@SuppressWarnings("unchecked") // if sortedSet.comparator() is null, the set must be naturally ordered public static <E> Comparator<? super E> comparator(SortedSet<E> sortedSet) { Comparator<? super E> result = sortedSet.comparator(); if (result == null) { result = (Comparator<? super E>) Ordering.natural(); } return result; } }
@Override public Comparator<? super E> comparator() { synchronized (mutex) { return delegate().comparator(); } }
/** * Returns the comparator that orders the rows. With natural ordering, {@link Ordering#natural()} * is returned. * * @deprecated Use {@code table.rowKeySet().comparator()} instead. */ @Deprecated public Comparator<? super R> rowComparator() { return rowKeySet().comparator(); }
public void testCopyOfExplicit_comparator() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asList("in", "the", "quick", "jumped", "over", "a")); assertSame(STRING_LENGTH, set.comparator()); }
public void testAsMapValuesImplementSortedSet() { for (Collection<V> valueCollection : multimap().asMap().values()) { SortedSet<V> valueSet = (SortedSet<V>) valueCollection; assertEquals(multimap().valueComparator(), valueSet.comparator()); } }
public void testCopyOfSorted_natural_comparator() { SortedSet<String> input = Sets.newTreeSet(asList("in", "the", "quick", "jumped", "over", "a")); SortedSet<String> set = ImmutableSortedSet.copyOfSorted(input); assertSame(Ordering.natural(), set.comparator()); }
@GwtIncompatible // SerializableTester public void testSeveral_serialization() { SortedSet<String> set = new SafeTreeSet<>(); set.add("a"); set.add("b"); set.add("c"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); } }
public void testCopyOfExplicit_iterator_comparator() { SortedSet<String> set = ImmutableSortedSet.copyOf( STRING_LENGTH, asIterator("in", "the", "quick", "jumped", "over", "a")); assertSame(STRING_LENGTH, set.comparator()); }
@GwtIncompatible // SerializableTester public void testSingle_serialization() { SortedSet<String> set = new SafeTreeSet<>(); set.add("e"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); }
@GwtIncompatible // SerializableTester public void testEmpty_serialization() { SortedSet<String> set = new SafeTreeSet<>(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); }
@GwtIncompatible // SerializableTester public void testSingle_serialization() { SortedSet<String> set = of("e"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); }
public void testAsMapGetImplementsSortedSet() { for (K key : multimap().keySet()) { SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().get(key); assertEquals(multimap().valueComparator(), valueSet.comparator()); } }
@MapFeature.Require(SUPPORTS_REMOVE) public void testAsMapRemoveImplementsSortedSet() { List<K> keys = new ArrayList<K>(multimap().keySet()); for (K key : keys) { resetCollection(); SortedSet<V> valueSet = (SortedSet<V>) multimap().asMap().remove(key); assertEquals(multimap().valueComparator(), valueSet.comparator()); } } }
public void testCopyOfSorted_explicit_ordering() { SortedSet<String> input = Sets.newTreeSet(STRING_LENGTH); Collections.addAll(input, "in", "the", "quick", "jumped", "over", "a"); SortedSet<String> set = ImmutableSortedSet.copyOfSorted(input); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); assertSame(STRING_LENGTH, set.comparator()); }
public void testRowKeySetComparator() { sortedTable = TreeBasedTable.create(); assertSame(Ordering.natural(), sortedTable.rowKeySet().comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); assertSame(Collections.reverseOrder(), sortedTable.rowKeySet().comparator()); }
/** * Utility method to verify that the given SortedSet is equal to and hashes identically to a set * constructed with the elements in the given iterable. Also verifies that the comparator is the * same as the given comparator. */ private static <E> void verifySortedSetContents( SortedSet<E> set, Iterable<E> iterable, @Nullable Comparator<E> comparator) { assertSame(comparator, set.comparator()); verifySetContents(set, iterable); }
@GwtIncompatible // SerializableTester public void testOf_serialization() { SortedSet<String> set = of("e", "f", "b", "d", "c"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertEquals(set.comparator(), copy.comparator()); }
public void testExplicit_comparator() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertSame(STRING_LENGTH, set.comparator()); }
@GwtIncompatible // SerializableTester public void testExplicit_serialization() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertSame(set.comparator(), copy.comparator()); }
public void testReverseOrder() { SortedSet<String> set = ImmutableSortedSet.<String>reverseOrder().add("a", "b", "c").build(); assertThat(set).containsExactly("c", "b", "a").inOrder(); assertTrue(Comparators.isInOrder(Arrays.asList("c", "b", "a"), set.comparator())); }