@Override SortedSet<Integer> createUnfiltered(Iterable<Integer> contents) { final TreeSet<Integer> result = Sets.newTreeSet(contents); // we have to make the result not Navigable return new ForwardingSortedSet<Integer>() { @Override protected SortedSet<Integer> delegate() { return result; } }; }
@Generates private static <E extends Comparable<? super E>> TreeSet<E> generateTreeSet(E freshElement) { TreeSet<E> set = Sets.newTreeSet(); set.add(freshElement); return set; }
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
@Override public List<String> order(List<String> insertionOrder) { return Lists.newArrayList(Sets.newTreeSet(insertionOrder)); } })
public void testEquals_bothDefaultOrdering_StringVsInt() { SortedSet<String> set = of("a", "b", "c"); assertFalse(set.equals(Sets.newTreeSet(asList(4, 5, 6)))); assertNotEqualLenient(Sets.newTreeSet(asList(4, 5, 6)), set); }
public void testEquals_bothExplicitOrdering_StringVsInt() { SortedSet<String> set = of("in", "the", "a"); assertFalse(set.equals(Sets.newTreeSet(asList(4, 5, 6)))); assertNotEqualLenient(Sets.newTreeSet(asList(4, 5, 6)), set); }
public void testEquals_bothExplicitOrdering() { SortedSet<String> set = of("in", "the", "a"); assertEquals(Sets.newTreeSet(asList("in", "the", "a")), set); assertFalse(set.equals(Sets.newTreeSet(asList("in", "the", "house")))); assertFalse(Sets.newTreeSet(asList("in", "the", "house")).equals(set)); assertFalse(set.equals(Sets.newHashSet(4, 5, 6))); assertFalse(Sets.newHashSet(4, 5, 6).equals(set)); Set<String> complex = Sets.newTreeSet(STRING_LENGTH); Collections.addAll(complex, "in", "the", "a"); assertEquals(set, complex); }
public void testEquals_bothDefaultOrdering() { SortedSet<String> set = of("a", "b", "c"); assertEquals(set, Sets.newTreeSet(asList("a", "b", "c"))); assertEquals(Sets.newTreeSet(asList("a", "b", "c")), set); assertFalse(set.equals(Sets.newTreeSet(asList("a", "b", "d")))); assertFalse(Sets.newTreeSet(asList("a", "b", "d")).equals(set)); assertFalse(set.equals(Sets.newHashSet(4, 5, 6))); assertFalse(Sets.newHashSet(4, 5, 6).equals(set)); }
public void testContainsAll_sameComparator() { SortedSet<String> set = of("a", "b", "f"); assertTrue(set.containsAll(Sets.newTreeSet())); assertTrue(set.containsAll(Sets.newTreeSet(asList("b")))); assertTrue(set.containsAll(Sets.newTreeSet(asList("a", "f")))); assertTrue(set.containsAll(Sets.newTreeSet(asList("a", "b", "f")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("d")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("z")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("b", "d")))); assertFalse(set.containsAll(Sets.newTreeSet(asList("f", "d", "a")))); }
@SuppressWarnings("CollectionIncompatibleType") // testing incompatible types public void testContainsAll_sameComparator_StringVsInt() { SortedSet<String> set = of("a", "b", "f"); SortedSet<Integer> unexpected = Sets.newTreeSet(Ordering.natural()); unexpected.addAll(asList(1, 2, 3)); assertFalse(set.containsAll(unexpected)); }
public void testCopyOf_sortedSetIterable() { SortedSet<String> input = Sets.newTreeSet(STRING_LENGTH); Collections.addAll(input, "in", "the", "quick", "jumped", "over", "a"); SortedSet<String> set = copyOf(input); assertThat(set).containsExactly("a", "in", "jumped", "over", "quick", "the").inOrder(); }
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 testNewTreeSetEmptyNonGeneric() { TreeSet<LegacyComparable> set = Sets.newTreeSet(); assertTrue(set.isEmpty()); set.add(new LegacyComparable("foo")); set.add(new LegacyComparable("bar")); assertThat(set) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); }
public void testNewTreeSetEmptyDerived() { TreeSet<Derived> set = Sets.newTreeSet(); assertTrue(set.isEmpty()); set.add(new Derived("foo")); set.add(new Derived("bar")); assertThat(set).containsExactly(new Derived("bar"), new Derived("foo")).inOrder(); }
@GwtIncompatible // NavigableMap public void testAsMapNavigableWritesThrough() { NavigableSet<String> strings = Sets.newTreeSet(); Collections.addAll(strings, "one", "two", "three"); NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(3), map.remove("two")); assertThat(strings).containsExactly("one", "three").inOrder(); assertEquals(mapEntry("three", 5), map.subMap("one", false, "zzz", true).pollLastEntry()); assertThat(strings).contains("one"); }
public void testNewTreeSetFromIterableNonGeneric() { Iterable<LegacyComparable> iterable = Arrays.asList(new LegacyComparable("foo"), new LegacyComparable("bar")); TreeSet<LegacyComparable> set = Sets.newTreeSet(iterable); assertThat(set) .containsExactly(new LegacyComparable("bar"), new LegacyComparable("foo")) .inOrder(); }