@Test public void shouldReturnTheMultisetUnionOfAllIterablesInTheSuppliedIterable() throws Exception { Iterable<String> firstIterable = listWith("a", "b", "a", "a", "c"); Iterable<String> secondIterable = setWith("c", "d", "e"); Iterable<String> thirdIterable = multisetWith("a", "a", "c", "c", "b"); Iterable<Iterable<String>> iterables = iterableWith(firstIterable, secondIterable, thirdIterable); Multiset<String> expectedUnionMultiset = multisetWith("a", "a", "a", "b", "c", "c", "d", "e"); Multiset<String> actualUnionMultiset = Multisets.union(iterables); assertThat(actualUnionMultiset, is(expectedUnionMultiset)); }
public static <T> Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables) { Multiset<T> unionMultiset = HashMultiset.create(first(iterables).get()); for (Iterable<? extends T> iterable : rest(iterables)) { Multiset<T> currentMultiset = HashMultiset.create(iterable); for (T element : currentMultiset.elementSet()) { int numberInUnionMultiset = unionMultiset.count(element); int numberInCurrentMultiset = currentMultiset.count(element); if (numberInUnionMultiset < numberInCurrentMultiset) { unionMultiset.setCount(element, numberInCurrentMultiset); } } } return unionMultiset; }
Multisets { public static <T> Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables) { Multiset<T> unionMultiset = HashMultiset.create(first(iterables).get()); for (Iterable<? extends T> iterable : rest(iterables)) { Multiset<T> currentMultiset = HashMultiset.create(iterable); for (T element : currentMultiset.elementSet()) { int numberInUnionMultiset = unionMultiset.count(element); int numberInCurrentMultiset = currentMultiset.count(element); if (numberInUnionMultiset < numberInCurrentMultiset) { unionMultiset.setCount(element, numberInCurrentMultiset); } } } return unionMultiset; } }
Multisets { public static <T> Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables) { Multiset<T> unionMultiset = HashMultiset.create(first(iterables).get()); for (Iterable<? extends T> iterable : rest(iterables)) { Multiset<T> currentMultiset = HashMultiset.create(iterable); for (T element : currentMultiset.elementSet()) { int numberInUnionMultiset = unionMultiset.count(element); int numberInCurrentMultiset = currentMultiset.count(element); if (numberInUnionMultiset < numberInCurrentMultiset) { unionMultiset.setCount(element, numberInCurrentMultiset); } } } return unionMultiset; } private  Multisets(); }
Multisets { public static <T> Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables) { Multiset<T> unionMultiset = HashMultiset.create(first(iterables).get()); for (Iterable<? extends T> iterable : rest(iterables)) { Multiset<T> currentMultiset = HashMultiset.create(iterable); for (T element : currentMultiset.elementSet()) { int numberInUnionMultiset = unionMultiset.count(element); int numberInCurrentMultiset = currentMultiset.count(element); if (numberInUnionMultiset < numberInCurrentMultiset) { unionMultiset.setCount(element, numberInCurrentMultiset); } } } return unionMultiset; } private  Multisets(); static Multiset<T> concatenate(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> intersection(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> difference(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); }
Multisets { public static <T> Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables) { Multiset<T> unionMultiset = HashMultiset.create(first(iterables).get()); for (Iterable<? extends T> iterable : rest(iterables)) { Multiset<T> currentMultiset = HashMultiset.create(iterable); for (T element : currentMultiset.elementSet()) { int numberInUnionMultiset = unionMultiset.count(element); int numberInCurrentMultiset = currentMultiset.count(element); if (numberInUnionMultiset < numberInCurrentMultiset) { unionMultiset.setCount(element, numberInCurrentMultiset); } } } return unionMultiset; } private  Multisets(); static Multiset<T> concatenate(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> union(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> intersection(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> difference(Iterable<? extends Iterable<? extends T>> iterables); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> concatenate(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> union(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> intersection(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10); static Multiset<T> difference(
            Iterable<? extends T> i1, Iterable<? extends T> i2, Iterable<? extends T> i3, Iterable<? extends T> i4,
            Iterable<? extends T> i5, Iterable<? extends T> i6, Iterable<? extends T> i7, Iterable<? extends T> i8,
            Iterable<? extends T> i9, Iterable<? extends T> i10, Iterable<? extends T>... i11on);  }