@SuppressWarnings("unchecked") @Override public Comparator<? super K> comparator() { Comparator<? super K> comparator = delegate.comparator(); if (comparator == null) { comparator = (Comparator<? super K>) NATURAL_ORDER; } return comparator; }
@Override public Comparator<? super K> comparator() { return unfiltered.comparator(); }
@Override public Comparator<? super K> comparator() { return unfiltered.comparator(); }
@Override public Comparator<? super K> comparator() { return unfiltered.comparator(); }
@Override public Comparator<? super K> comparator() { return unfiltered.comparator(); }
/** * Returns the comparator used to compare elements in this {@code TreeSet}. * * @return a Comparator or null if the natural ordering is used */ public Comparator<? super E> comparator() { return backingMap.comparator(); }
@SuppressWarnings("unchecked") @Override public Comparator<? super K> comparator() { Comparator<? super K> result = comparator; if (result == null) { Comparator<? super K> forwardCmp = forward().comparator(); if (forwardCmp == null) { forwardCmp = (Comparator) Ordering.natural(); } result = comparator = reverse(forwardCmp); } return result; }
@SuppressWarnings("unchecked") @Override public Comparator<? super K> comparator() { Comparator<? super K> result = comparator; if (result == null) { Comparator<? super K> forwardCmp = forward().comparator(); if (forwardCmp == null) { forwardCmp = (Comparator) Ordering.natural(); } result = comparator = reverse(forwardCmp); } return result; }
private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeObject(backingMap.comparator()); int size = backingMap.size(); stream.writeInt(size); if (size > 0) { Iterator<E> it = backingMap.keySet().iterator(); while (it.hasNext()) { stream.writeObject(it.next()); } } }
@Override public Comparator<? super K> comparator() { assertTrue(Thread.holdsLock(mutex)); return delegate().comparator(); }
/** * {@inheritDoc} * * @see java.util.NavigableSet#headSet(Object, boolean) * @since 1.6 */ @SuppressWarnings("unchecked") public NavigableSet<E> headSet(E end, boolean endInclusive) { // Check for errors Comparator<? super E> c = backingMap.comparator(); if (c == null) { ((Comparable<E>) end).compareTo(end); } else { c.compare(end, end); } return new TreeSet<E>(backingMap.headMap(end, endInclusive)); }
/** * {@inheritDoc} * * @see java.util.NavigableSet#subSet(Object, boolean, Object, boolean) * @since 1.6 */ @SuppressWarnings("unchecked") public NavigableSet<E> subSet(E start, boolean startInclusive, E end, boolean endInclusive) { Comparator<? super E> c = backingMap.comparator(); int compare = (c == null) ? ((Comparable<E>) start).compareTo(end) : c .compare(start, end); if (compare <= 0) { return new TreeSet<E>(backingMap.subMap(start, startInclusive, end, endInclusive)); } throw new IllegalArgumentException(); }
/** * {@inheritDoc} * * @see java.util.NavigableSet#tailSet(Object, boolean) * @since 1.6 */ @SuppressWarnings("unchecked") public NavigableSet<E> tailSet(E start, boolean startInclusive) { // Check for errors Comparator<? super E> c = backingMap.comparator(); if (c == null) { ((Comparable<E>) start).compareTo(start); } else { c.compare(start, start); } return new TreeSet<E>(backingMap.tailMap(start, startInclusive)); }
public void testComparator() { create().comparator(); }
@SuppressWarnings("unchecked") @Override public Comparator<? super K> comparator() { Comparator<? super K> result = comparator; if (result == null) { Comparator<? super K> forwardCmp = forward().comparator(); if (forwardCmp == null) { forwardCmp = (Comparator) Ordering.natural(); } result = comparator = reverse(forwardCmp); } return result; }
@Override public void setUp() throws Exception { super.setUp(); navigableMap = (NavigableMap<K, V>) getMap(); entries = Helpers.copyToList( getSubjectGenerator() .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator())); // some tests assume SEVERAL == 3 if (entries.size() >= 1) { a = entries.get(0); if (entries.size() >= 3) { b = entries.get(1); c = entries.get(2); } } }
@SuppressWarnings("unchecked") @Override public Comparator<? super K> comparator() { Comparator<? super K> result = comparator; if (result == null) { Comparator<? super K> forwardCmp = forward().comparator(); if (forwardCmp == null) { forwardCmp = (Comparator) Ordering.natural(); } result = comparator = reverse(forwardCmp); } return result; }
if (map.comparator() != null && map.comparator() != Ordering.natural() && range.hasLowerBound() && range.hasUpperBound()) { checkArgument( map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0, "map is using a custom comparator which is inconsistent with the natural ordering.");
if (map.comparator() != null && map.comparator() != Ordering.natural() && range.hasLowerBound() && range.hasUpperBound()) { checkArgument( map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0, "map is using a custom comparator which is inconsistent with the natural ordering.");
Collections.addAll(strings, "one", "two", "three"); NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertNull(map.comparator()); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5), map); assertNull(map.get("four"));