@Override public Comparator<? super E> comparator() { return multiset().comparator(); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
@Override public Comparator<? super E> comparator() { Comparator<? super E> result = comparator; if (result == null) { return comparator = Ordering.from(forwardMultiset().comparator()).<E>reverse(); } return result; }
@Override public Comparator<? super E> comparator() { return multiset().comparator(); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
/** * Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by * the same {@code Comparator}. That behavior differs from {@link #copyOf(Iterable)}, which always * uses the natural ordering of the elements. * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. * * <p>This method is safe to use even when {@code sortedMultiset} is a synchronized or concurrent * collection that is currently being modified by another thread. * * @throws NullPointerException if {@code sortedMultiset} or any of its elements is null */ public static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset) { return copyOfSortedEntries( sortedMultiset.comparator(), Lists.newArrayList(sortedMultiset.entrySet())); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
@Override public Comparator<? super E> comparator() { return multiset().comparator(); }
@Override public Comparator<? super E> comparator() { return delegate().comparator(); }
@Override public Comparator<? super E> comparator() { Comparator<? super E> result = comparator; if (result == null) { return comparator = Ordering.from(forwardMultiset().comparator()).<E>reverse(); } return result; }
@SuppressWarnings("unchecked") SerializedForm(SortedMultiset<E> multiset) { this.comparator = multiset.comparator(); int n = multiset.entrySet().size(); elements = (E[]) new Object[n]; counts = new int[n]; int i = 0; for (Entry<E> entry : multiset.entrySet()) { elements[i] = entry.getElement(); counts[i] = entry.getCount(); i++; } }
@SuppressWarnings("unchecked") SerializedForm(SortedMultiset<E> multiset) { this.comparator = multiset.comparator(); int n = multiset.entrySet().size(); elements = (E[]) new Object[n]; counts = new int[n]; int i = 0; for (Entry<E> entry : multiset.entrySet()) { elements[i] = entry.getElement(); counts[i] = entry.getCount(); i++; } }
@Override public Comparator<? super E> comparator() { Comparator<? super E> result = comparator; if (result == null) { return comparator = Ordering.from(forwardMultiset().comparator()).<E>reverse(); } return result; }
/** * Returns an immutable sorted multiset containing the elements of a sorted multiset, sorted by * the same {@code Comparator}. That behavior differs from {@link #copyOf(Iterable)}, which always * uses the natural ordering of the elements. * * <p>Despite the method name, this method attempts to avoid actually copying the data when it is * safe to do so. The exact circumstances under which a copy will or will not be performed are * undocumented and subject to change. * * <p>This method is safe to use even when {@code sortedMultiset} is a synchronized or concurrent * collection that is currently being modified by another thread. * * @throws NullPointerException if {@code sortedMultiset} or any of its elements is null */ public static <E> ImmutableSortedMultiset<E> copyOfSorted(SortedMultiset<E> sortedMultiset) { return copyOfSortedEntries( sortedMultiset.comparator(), Lists.newArrayList(sortedMultiset.entrySet())); }
@Override public void setUp() throws Exception { super.setUp(); sortedMultiset = cast(getMultiset()); entries = copyToList( getSubjectGenerator() .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); Collections.sort(entries, sortedMultiset.comparator()); // some tests assume SEVERAL == 3 if (entries.size() >= 1) { a = Multisets.immutableEntry(entries.get(0), sortedMultiset.count(entries.get(0))); if (entries.size() >= 3) { b = Multisets.immutableEntry(entries.get(1), sortedMultiset.count(entries.get(1))); c = Multisets.immutableEntry(entries.get(2), sortedMultiset.count(entries.get(2))); } } }
@SuppressWarnings("unchecked") SerializedForm(SortedMultiset<E> multiset) { this.comparator = multiset.comparator(); int n = multiset.entrySet().size(); elements = (E[]) new Object[n]; counts = new int[n]; int i = 0; for (Entry<E> entry : multiset.entrySet()) { elements[i] = entry.getElement(); counts[i] = entry.getCount(); i++; } }
@SuppressWarnings("unchecked") public void testCopyOfSortedDefensiveCopy() { // Depending on JDK version, either toArray() or toArray(T[]) may be called... use this class // rather than mocking to ensure that one of those methods is called. class TestHashSet<E> extends HashSet<E> { boolean toArrayCalled = false; @Override public Object[] toArray() { toArrayCalled = true; return super.toArray(); } @Override public <T> T[] toArray(T[] a) { toArrayCalled = true; return super.toArray(a); } } // Test that toArray() is used to make a defensive copy in copyOf(), so concurrently modified // synchronized collections can be safely copied. SortedMultiset<String> toCopy = mock(SortedMultiset.class); TestHashSet<Entry<String>> entrySet = new TestHashSet<>(); when((Comparator<Comparable<String>>) toCopy.comparator()) .thenReturn(Ordering.<Comparable<String>>natural()); when(toCopy.entrySet()).thenReturn(entrySet); ImmutableSortedMultiset<String> unused = ImmutableSortedMultiset.copyOfSorted(toCopy); assertTrue(entrySet.toArrayCalled); }
final Comparator<? super E> comparator = emptyMultiset.comparator(); SampleElements<E> samples = delegate.samples(); @SuppressWarnings("unchecked")