private static SelectResults sizeSortedIntersection(SelectResults small,SelectResults large,ExecutionContext contextOrNull){
  boolean smallModifiable=small.isModifiable() && (isBag(small) || !isBag(large));
  boolean largeModifiable=large.isModifiable() && (isBag(large) || !isBag(small));
  if (smallModifiable) {
    try {
      for (Iterator itr=small.iterator(); itr.hasNext(); ) {
        Object element=itr.next();
        int count=large.occurrences(element);
        if (small.occurrences(element) > count) {
          itr.remove();
        }
      }
      return small;
    }
 catch (    UnsupportedOperationException e1) {
    }
  }
  if (largeModifiable) {
    try {
      for (Iterator itr=large.iterator(); itr.hasNext(); ) {
        Object element=itr.next();
        int count=small.occurrences(element);
        if (large.occurrences(element) > count) {
          itr.remove();
        }
      }
      return large;
    }
 catch (    UnsupportedOperationException e2) {
    }
  }
  SelectResults rs;
  if (contextOrNull != null) {
    rs=contextOrNull.isDistinct() ? new ResultsSet(small) : new ResultsBag(small,contextOrNull.getCachePerfStats());
  }
 else {
    rs=new ResultsBag(small,null);
  }
  for (Iterator itr=rs.iterator(); itr.hasNext(); ) {
    Object element=itr.next();
    int count=large.occurrences(element);
    if (rs.occurrences(element) > count) {
      itr.remove();
    }
  }
  return rs;
}

private static SelectResults sizeSortedIntersection ( SelectResults small , SelectResults large , ExecutionContext contextOrNull ) { boolean smallModifiable = small . isModifiable ( ) && ( isBag ( small ) || ! isBag ( large ) ) ; boolean largeModifiable = large . isModifiable ( ) && ( isBag ( large ) || ! isBag ( small ) ) ; if ( smallModifiable ) { try { for ( Iterator itr = small . iterator ( ) ; itr . hasNext ( ) ; ) { Object element = itr . next ( ) ; int count = large . occurrences ( element ) ; if ( small . occurrences ( element ) > count ) { itr . remove ( ) ; } } return small ; } catch ( UnsupportedOperationException e1 ) { } } if ( largeModifiable ) { try { for ( Iterator itr = large . iterator ( ) ; itr . hasNext ( ) ; ) { Object element = itr . next ( ) ; int count = small . occurrences ( element ) ; if ( large . occurrences ( element ) > count ) { itr . remove ( ) ; } } return large ; } catch ( UnsupportedOperationException e2 ) { } } SelectResults rs ; if ( contextOrNull != null ) { rs = contextOrNull . isDistinct ( ) ? new ResultsSet ( small ) : new ResultsBag ( small , contextOrNull . getCachePerfStats ( ) ) ; } else { rs = new ResultsBag ( small , null ) ; } for ( Iterator itr = rs . iterator ( ) ; itr . hasNext ( ) ; ) { Object element = itr . next ( ) ; int count = large . occurrences ( element ) ; if ( rs . occurrences ( element ) > count ) { itr . remove ( ) ; } } return rs ; }
collections are passed in from smallest to largest
