/** * Returns the comparator that orders the keys, which is {@link Ordering#natural()} when the * natural ordering of the keys is used. Note that its behavior is not consistent with {@link * TreeMap#comparator()}, which returns {@code null} to indicate natural ordering. */ @Override public Comparator<? super K> comparator() { return keySet().comparator(); }
@Override public final Comparator<? super E> comparator() { return elementSet().comparator(); }
@Override public Comparator<? super E> comparator() { return delegateCollection().comparator(); }
@Nullable Comparator<? super V> valueComparator() { return emptySet instanceof ImmutableSortedSet ? ((ImmutableSortedSet<V>) emptySet).comparator() : null; }
DescendingImmutableSortedSet(ImmutableSortedSet<E> forward) { super(Ordering.from(forward.comparator()).reverse()); this.forward = forward; }
@NullableDecl Comparator<? super V> valueComparator() { return emptySet instanceof ImmutableSortedSet ? ((ImmutableSortedSet<V>) emptySet).comparator() : null; }
DescendingImmutableSortedSet(ImmutableSortedSet<E> forward) { super(Ordering.from(forward.comparator()).reverse()); this.forward = forward; }
@Override public Comparator<? super E> comparator() { return delegateCollection().comparator(); }
/** * Returns the comparator that orders the keys, which is {@link Ordering#natural()} when the * natural ordering of the keys is used. Note that its behavior is not consistent with {@link * TreeMap#comparator()}, which returns {@code null} to indicate natural ordering. */ @Override public Comparator<? super K> comparator() { return keySet().comparator(); }
@NullableDecl Comparator<? super V> valueComparator() { return emptySet instanceof ImmutableSortedSet ? ((ImmutableSortedSet<V>) emptySet).comparator() : null; }
@Override public Comparator<? super E> comparator() { return delegateCollection().comparator(); }
DescendingImmutableSortedSet(ImmutableSortedSet<E> forward) { super(Ordering.from(forward.comparator()).reverse()); this.forward = forward; }
@Override public final Comparator<? super E> comparator() { return elementSet().comparator(); }
public void testToImmutableSortedSet_customComparator() { Collector<String, ?, ImmutableSortedSet<String>> collector = ImmutableSortedSet.toImmutableSortedSet(String.CASE_INSENSITIVE_ORDER); BiPredicate<ImmutableSortedSet<String>, ImmutableSortedSet<String>> equivalence = (set1, set2) -> set1.equals(set2) && set1.asList().equals(set2.asList()) && set1.comparator().equals(set2.comparator()); ImmutableSortedSet<String> expected = ImmutableSortedSet.orderedBy(String.CASE_INSENSITIVE_ORDER).add("a", "B", "c", "d").build(); CollectorTester.of(collector, equivalence) .expectCollects(expected, "a", "B", "a", "c", "b", "b", "d"); }
@GwtIncompatible // SerializableTester public void testSortedSerialization() { Multimap<String, Integer> multimap = new ImmutableSetMultimap.Builder<String, Integer>() .orderKeysBy(Ordering.natural().reverse()) .orderValuesBy(Ordering.usingToString()) .put("a", 2) .put("a", 10) .put("b", 1) .build(); multimap = SerializableTester.reserialize(multimap); assertThat(multimap.keySet()).containsExactly("b", "a").inOrder(); assertThat(multimap.get("a")).containsExactly(10, 2).inOrder(); assertEquals( Ordering.usingToString(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertEquals( Ordering.usingToString(), ((ImmutableSortedSet<Integer>) multimap.get("z")).comparator()); }
public void testBuilderOrderValuesBy() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("b", 3); builder.put("d", 2); builder.put("a", 5); builder.orderValuesBy(Collections.reverseOrder()); builder.put("c", 4); builder.put("a", 2); builder.put("b", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("b", "d", "a", "c").inOrder(); assertThat(multimap.values()).containsExactly(6, 3, 2, 5, 2, 4).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(6, 3).inOrder(); assertTrue(multimap.get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertTrue(multimap.get("x") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator()); assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator()); }
public void testBuilderOrderKeysAndValuesBy() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.put("b", 3); builder.put("d", 2); builder.put("a", 5); builder.orderKeysBy(Collections.reverseOrder()); builder.orderValuesBy(Collections.reverseOrder()); builder.put("c", 4); builder.put("a", 2); builder.put("b", 6); ImmutableSetMultimap<String, Integer> multimap = builder.build(); assertThat(multimap.keySet()).containsExactly("d", "c", "b", "a").inOrder(); assertThat(multimap.values()).containsExactly(2, 4, 6, 3, 5, 2).inOrder(); assertThat(multimap.get("a")).containsExactly(5, 2).inOrder(); assertThat(multimap.get("b")).containsExactly(6, 3).inOrder(); assertTrue(multimap.get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("a")).comparator()); assertTrue(multimap.get("x") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.get("x")).comparator()); assertTrue(multimap.asMap().get("a") instanceof ImmutableSortedSet); assertEquals( Collections.reverseOrder(), ((ImmutableSortedSet<Integer>) multimap.asMap().get("a")).comparator()); }
@Nullable Comparator<? super V> valueComparator() { return emptySet instanceof ImmutableSortedSet ? ((ImmutableSortedSet<V>) emptySet).comparator() : null; }
@Override public ImmutableList<E> subList(int fromIndex, int toIndex) { Preconditions.checkPositionIndexes(fromIndex, toIndex, size()); return (fromIndex == toIndex) ? ImmutableList.<E>of() : new RegularImmutableSortedSet<E>( backingList.subList(fromIndex, toIndex), backingSet.comparator()) .asList(); }
@Override public void write(Kryo kryo, Output output, ImmutableSortedSet<Object> object) { kryo.writeClassAndObject(output, object.comparator()); output.writeInt(object.size(), true); for (Object elm : object) { kryo.writeClassAndObject(output, elm); } }