多个集合的交集<br>
针对一个集合中存在多个相同元素的情况，计算两个集合中此元素的个数，保留最少的个数<br>
例如：集合1：[a, b, c, c, c]，集合2：[a, b, c, c]<br>
结果：[a, b, c, c]，此结果中只保留了两个c

@param <T> 集合元素类型
@param coll1 集合1
@param coll2 集合2
@param otherColls 其它集合
@return 并集的集合，返回 {@link ArrayList}
552823
@SafeVarargs
	public static <T> Collection<T> intersection(Collection<T> coll1, Collection<T> coll2, Collection<T>... otherColls) {
		Collection<T> intersection = intersection(coll1, coll2);
		if (isEmpty(intersection)) {
			return intersection;
		}
		for (Collection<T> coll : otherColls) {
			intersection = intersection(intersection, coll);
			if (isEmpty(intersection)) {
				return intersection;
			}
		}
		return intersection;
	}
896290
public JcCollection<JcValue> addAll(Collection<?> coll) {
		JcCollection<JcValue> ret = new JcCollection<JcValue>(null, coll, this,
				OPERATOR.Collection.ADD_ALL);
		QueryRecorder.recordInvocationConditional(this, "addAll", ret, QueryRecorder.literal(coll));
		return ret;
	}
680016
public static <T> List<T> mergeLists(List<T> list1, List<T> list2) {
        List<T> merged = new LinkedList<T>();
        if (list1 != null) {
            merged.addAll(list1);
        }
        if (list2 != null) {
            merged.addAll(list2);
        }
        return merged;
    }
1114877
private List<IAtom> getUnion(List<IAtom> list1, List<IAtom> list2) {
        // FIXME: the JavaDoc does not describe what happens: that vec1 gets to be the union!
        // jm: pretty sure retainAll would do the trick here but don't want to change the
        //     functionality as item only present in list1 are not removed (i.e. not union)
        List<IAtom> is = new ArrayList<IAtom>(list1);
        for (int f = list2.size() - 1; f > -1; f--) {
            if (!list1.contains(list2.get(f))) is.add(list2.get(f));
        }
        return is;
    }
713253
public static float[] floatArrayCopyOf(CollectionNumber coll) {
        float[] data = new float[coll.size()];
        IteratorNumber iter = coll.iterator();
        int index = 0;
        while (iter.hasNext()) {
            data[index] = iter.nextFloat();
            index++;
        }
        return data;
    }
1123537
@Override
    protected double scoreImpl(List<Word> words1, List<Word> words2) {
        if(words1.isEmpty() && words2.isEmpty()){
            return 1.0;
        }
        //转变为不重复的集合
        Set<Word> words1Set = new HashSet<>(words1);
        Set<Word> words2Set = new HashSet<>(words2);
        // 两个集合的大小
        int set1Size = words1Set.size();
        int set2Size = words2Set.size();

        // 求交集（去重），计算交集的不重复词的个数
        words1Set.retainAll(words2Set);
        int intersectionSize = words1Set.size();

        //相似度分值
        double score = 2*intersectionSize / (double)(set1Size+set2Size);
        if(LOGGER.isDebugEnabled()) {
            LOGGER.debug("集合1：" + words1);
            LOGGER.debug("集合2：" + words2);
            LOGGER.debug("集合1的大小：" + set1Size);
            LOGGER.debug("集合2的大小：" + set2Size);
            LOGGER.debug("交集的大小：" + intersectionSize);
            LOGGER.debug("相似度分值=2*" + intersectionSize + "/(double)(" + set1Size + "+" + set2Size + ")=" + score);
        }
        return score;
    }
624185
public final Assignment union(Assignment other) {
    Preconditions.checkNotNull(other);
    if (other.size() == 0) {
      return this;
    } if (vars.length == 0) {
      return other;
    }

    // Merge varnums / values
    int[] otherNums = other.getVariableNumsArray();
    int[] myNums = getVariableNumsArray();
    Object[] otherVals = other.getValuesArray();
    Object[] myVals = getValuesArray();

    int[] mergedNums = new int[otherNums.length + myNums.length];
    Object[] mergedVals = new Object[otherNums.length + myNums.length];

    int i = 0;
    int j = 0;
    int numFilled = 0;
    while (i < otherNums.length && j < myNums.length) {
      if (otherNums[i] < myNums[j]) {
        mergedNums[numFilled] = otherNums[i];
        mergedVals[numFilled] = otherVals[i];
        i++;
        numFilled++;
      } else if (otherNums[i] > myNums[j]) {
        mergedNums[numFilled] = myNums[j];
        mergedVals[numFilled] = myVals[j];
        j++;
        numFilled++;
      } else {
        Preconditions.checkState(false, "Cannot combine non-disjoint assignments: %s with %s", this, other);
      }
    }
    // One list might still have elements in it.
    while (i < otherNums.length) {
      mergedNums[numFilled] = otherNums[i];
      mergedVals[numFilled] = otherVals[i];
      i++;
      numFilled++;
    }
    while (j < myNums.length) {
      mergedNums[numFilled] = myNums[j];
      mergedVals[numFilled] = myVals[j];
      j++;
      numFilled++;
    }
    Preconditions.checkState(numFilled == mergedNums.length);
    return Assignment.fromSortedArrays(mergedNums, mergedVals);
  }
668502
public Tags merge(Tags other) {
    // Dereference "other" first as a null pointer check so we cannot risk returning null later.
    if (other.isEmpty()) {
      return this;
    }
    if (this.isEmpty()) {
      return other;
    }
    SortedMap<String, SortedSet<Object>> merged = new TreeMap<String, SortedSet<Object>>();
    for (Map.Entry<String, SortedSet<Object>> e : map.entrySet()) {
      SortedSet<Object> otherValues = other.map.get(e.getKey());
      if (otherValues == null || e.getValue().containsAll(otherValues)) {
        // Our values are a superset of the values in the other map, so just use them.
        merged.put(e.getKey(), e.getValue());
      } else if (otherValues.containsAll(e.getValue())) {
        // The other map's values are a superset of ours, so just use them.
        merged.put(e.getKey(), otherValues);
      } else {
        // Values exist in both maps and neither is a superset, so we really must merge.
        SortedSet<Object> mergedValues = new TreeSet<Object>(e.getValue());
        mergedValues.addAll(otherValues);
        merged.put(e.getKey(), Collections.unmodifiableSortedSet(mergedValues));
      }
    }
    for (Map.Entry<String, SortedSet<Object>> e : other.map.entrySet()) {
      // Finally add those values that were only in the other map.
      if (!map.containsKey(e.getKey())) {
        merged.put(e.getKey(), e.getValue());
      }
    }
    return new Tags(Collections.unmodifiableSortedMap(merged));
  }
230947
@SuppressWarnings("unchecked")
	public static <T> List<T> aggregateToList(Object v1, T v2) {
		List<Object> aggregatedValues = toList(v1);
		aggregatedValues.add(v2);
		return (List<T>) aggregatedValues;
	}
1030529
public static <T> Collection<T> union(Collection<T> coll1, Collection<T> coll2) {
		final ArrayList<T> list = new ArrayList<>();
		if (isEmpty(coll1)) {
			list.addAll(coll2);
		} else if (isEmpty(coll2)) {
			list.addAll(coll1);
		} else {
			final Map<T, Integer> map1 = countMap(coll1);
			final Map<T, Integer> map2 = countMap(coll2);
			final Set<T> elts = newHashSet(coll2);
			elts.addAll(coll1);
			int m;
			for (T t : elts) {
				m = Math.max(Convert.toInt(map1.get(t), 0), Convert.toInt(map2.get(t), 0));
				for (int i = 0; i < m; i++) {
					list.add(t);
				}
			}
		}
		return list;
	}
212302
public static <E1,E2> Collection<E2> mapColl(Iterable<E1> coll, Function<E1,E2> func, Collection<E2> newColl) {
	for(E1 elem : coll) {
	    newColl.add(func.f(elem));
	}
	return newColl;
    }
266046
public Set<T> newColl(Collection<T> coll) {
	Set<T> newSet = this.create();
	newSet.addAll(coll);
	return newSet;
    }
134806
public static <E> List<E> intersection(final List<E> list1, final List<E> list2) {
        final List<E> result = newArrayList();
        for (final E item : list1) {
            if (list2.contains(item)) {
                result.add(item);
            }
        }
        return result;
    }
1067480
public IntervalCollection<T> intersect(IntervalCollection<T> other) {

        if (this.isEmpty() || other.isEmpty()) {
            List<ChronoInterval<T>> zero = Collections.emptyList();
            return this.create(zero);
        }

        List<ChronoInterval<T>> list = new ArrayList<>();

        for (ChronoInterval<T> a : this.intervals) {
            for (ChronoInterval<T> b : other.intervals) {
                List<ChronoInterval<T>> candidates = new ArrayList<>(2);
                candidates.add(a);
                candidates.add(b);
                candidates.sort(this.getComparator());
                candidates = this.intersect(candidates);
                if (!candidates.isEmpty()) {
                    list.addAll(candidates);
                }
            }
        }

        list.sort(this.getComparator());
        return this.create(list).withBlocks();

    }
1323177
public static <E> List<E> buildMergedList(
            Collection<E> collection1, Collection<E> collection2) {
        List<E> mergedList = new ArrayList<>(collection1);
        mergedList.addAll(collection2);
        return mergedList;
    }
26588
@SuppressWarnings("unchecked")
  public <E> boolean isEqualsCollections(Collection<E> coll1, Collection<E> coll2, boolean isOrdered,
      ISrvIsEquals<E> srvIsEquals) {
    if((coll1 == null && coll2 != null) ||
        (coll1 != null && coll2 == null)) {
      return false;
    }
    if(coll1 != null && coll2 != null) {
      if(coll1.size() != coll2.size()) {
        return false;
      }
      if(isOrdered) {
        Object[] arr1 = coll1.toArray();
        Object[] arr2 = coll2.toArray();
        for(int i=0; i < coll1.size(); i++) {
          if(!srvIsEquals.getIsEquals((E)arr1[i], (E)arr2[i])) {
            return false;
          }
        }
      }
      else {
        outer:
        for(E e1 : coll1) {
          for(E e2 : coll2) {
            if(srvIsEquals.getIsEquals(e1, e2)) {
              continue outer;
            }
          }
          return false;
        }
      }
    }
    return true;  
  }
1258951
public static <E> List<E> union(final List<? extends E> list1, final List<? extends E> list2) {
		final List<E> result = new ArrayList<E>(list1.size() + list2.size());
		result.addAll(list1);
		result.addAll(list2);
		return result;
	}