@Test public void testMixedIntersection() { Set<Integer> a = Sets.newTreeSet(); Set<Integer> b = Sets.newHashSet(); populate(a); populate(b); Assert.assertEquals(TSets.intersection(a, b), Sets.intersection(a, b).copyInto(Sets.<Integer> newHashSet())); }
public static <T> Set<T> intersection(Set<T> a, Set<T> b) { if(a instanceof SortedSet && b instanceof SortedSet) { return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b); } else { Set<T> intersection = Sets.newLinkedHashSet(); Set<T> smaller = a.size() <= b.size() ? a : b; Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b); for (T element : smaller) { if(larger.contains(element)) { intersection.add(element); } } return intersection; } }
TSets { public static <T> Set<T> intersection(Set<T> a, Set<T> b) { if(a instanceof SortedSet && b instanceof SortedSet) { return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b); } else { Set<T> intersection = Sets.newLinkedHashSet(); Set<T> smaller = a.size() <= b.size() ? a : b; Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b); for (T element : smaller) { if(larger.contains(element)) { intersection.add(element); } } return intersection; } } }
TSets { public static <T> Set<T> intersection(Set<T> a, Set<T> b) { if(a instanceof SortedSet && b instanceof SortedSet) { return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b); } else { Set<T> intersection = Sets.newLinkedHashSet(); Set<T> smaller = a.size() <= b.size() ? a : b; Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b); for (T element : smaller) { if(larger.contains(element)) { intersection.add(element); } } return intersection; } }  }
TSets { public static <T> Set<T> intersection(Set<T> a, Set<T> b) { if(a instanceof SortedSet && b instanceof SortedSet) { return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b); } else { Set<T> intersection = Sets.newLinkedHashSet(); Set<T> smaller = a.size() <= b.size() ? a : b; Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b); for (T element : smaller) { if(larger.contains(element)) { intersection.add(element); } } return intersection; } }  static Set<T> intersection(Set<T> a, Set<T> b); static Set<Long> sequence(long from, long to); static Set<T> union(Set<T> a, Set<T> b); }
TSets { public static <T> Set<T> intersection(Set<T> a, Set<T> b) { if(a instanceof SortedSet && b instanceof SortedSet) { return sortedIntersection((SortedSet<T>) a, (SortedSet<T>) b); } else { Set<T> intersection = Sets.newLinkedHashSet(); Set<T> smaller = a.size() <= b.size() ? a : b; Set<T> larger = Sets.newHashSet(a.size() > b.size() ? a : b); for (T element : smaller) { if(larger.contains(element)) { intersection.add(element); } } return intersection; } }  static Set<T> intersection(Set<T> a, Set<T> b); static Set<Long> sequence(long from, long to); static Set<T> union(Set<T> a, Set<T> b);  }