/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( E e1, E e2, E e3, E e4, E e5) { return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3, e4, e5)); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any of {@code elements} is null */ public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> copyOf(E[] elements) { return copyOf(Ordering.natural(), Arrays.asList(elements)); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2, E e3) { return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3)); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of( E e1, E e2, E e3, E e4) { return copyOf(Ordering.natural(), Arrays.asList(e1, e2, e3, e4)); }
/** * Returns an immutable sorted multiset containing the given elements sorted by their natural * ordering. * * @throws NullPointerException if any element is null */ @SuppressWarnings("unchecked") public static <E extends Comparable<? super E>> ImmutableSortedMultiset<E> of(E e1, E e2) { return copyOf(Ordering.natural(), Arrays.asList(e1, e2)); }
@Override public <E extends Comparable<E>> SortedMultiset<E> create(Collection<E> contents) { return ImmutableSortedMultiset.copyOf(contents); } };
public void testCreation_arrayOfOneElement() { String[] array = new String[] {"a"}; Multiset<String> multiset = ImmutableSortedMultiset.copyOf(array); assertEquals(HashMultiset.create(asList("a")), multiset); }
public void testCopyOf_multisetContainingNull() { Multiset<String> c = HashMultiset.create(asList("a", null, "b")); try { ImmutableSortedMultiset.copyOf(c); fail(); } catch (NullPointerException expected) { } }
public void testCopyOf_iterator_general() { Iterator<String> iterator = asList("a", "b", "a").iterator(); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(iterator); assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset); }
public void testCopyOf_iteratorContainingNull() { Iterator<String> iterator = asList("a", null, "b").iterator(); try { ImmutableSortedMultiset.copyOf(iterator); fail(); } catch (NullPointerException expected) { } }
public void testCopyOf_multiset_oneElement() { Multiset<String> c = HashMultiset.create(asList("a")); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertEquals(HashMultiset.create(asList("a")), multiset); }
public void testCopyOf_multiset_general() { Multiset<String> c = HashMultiset.create(asList("a", "b", "a")); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset); }
public void testCopyOf_collection_oneElement() { Collection<String> c = MinimalCollection.of("a"); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertEquals(HashMultiset.create(asList("a")), multiset); }
public void testCopyOf_collection_general() { Collection<String> c = MinimalCollection.of("a", "b", "a"); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertEquals(HashMultiset.create(asList("a", "b", "a")), multiset); }
public void testCopyOf_multiset_empty() { Multiset<String> c = HashMultiset.create(); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertTrue(multiset.isEmpty()); }
public void testCopyOf_collectionContainingNull() { Collection<String> c = MinimalCollection.of("a", null, "b"); try { ImmutableSortedMultiset.copyOf(c); fail(); } catch (NullPointerException expected) { } }
public void testCreation_emptyArray() { String[] array = new String[0]; Multiset<String> multiset = ImmutableSortedMultiset.copyOf(array); assertTrue(multiset.isEmpty()); }
public void testCopyOf_collection_empty() { // "<String>" is required to work around a javac 1.5 bug. Collection<String> c = MinimalCollection.<String>of(); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(c); assertTrue(multiset.isEmpty()); }
public void testCopyOf_iterator_empty() { Iterator<String> iterator = Iterators.emptyIterator(); Multiset<String> multiset = ImmutableSortedMultiset.copyOf(iterator); assertTrue(multiset.isEmpty()); }
public void testCopyOfDuplicateInconsistentWithEquals() { IntegerDiv10 three = new IntegerDiv10(3); IntegerDiv10 eleven = new IntegerDiv10(11); IntegerDiv10 twelve = new IntegerDiv10(12); IntegerDiv10 twenty = new IntegerDiv10(20); List<IntegerDiv10> original = ImmutableList.of(three, eleven, twelve, twenty); Multiset<IntegerDiv10> copy = ImmutableSortedMultiset.copyOf(original); assertTrue(copy.contains(eleven)); assertTrue(copy.contains(twelve)); } }