@Override protected SortedSet<String> create(String[] elements) { return ImmutableSortedSet.orderedBy(STRING_REVERSED).add(elements).build(); }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements).reverse(); return ImmutableSortedSet.orderedBy(comparator) .add(elements) .build() .descendingSet() .asList(); } }
@SuppressWarnings("CollectionIncompatibleType") // testing incompatible types public void testExplicit_containsMismatchedTypes() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertFalse(set.contains(3.7)); }
public void testExplicit_comparator() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertSame(STRING_LENGTH, set.comparator()); }
public void testExplicit_first() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertEquals("a", set.first()); }
public void testExplicit_last() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertEquals("jumped", set.last()); }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator); builder.add(BEFORE_FIRST); builder.add(elements); builder.add(AFTER_LAST); return builder.build().subSet(BEFORE_FIRST_2, AFTER_LAST).asList(); } }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator); builder.add(BEFORE_FIRST); builder.add(elements); builder.add(AFTER_LAST); return builder.build().asList().subList(1, elements.length + 1); } }
@GwtIncompatible // SerializableTester public void testExplicitEmpty_serialization() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH).build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(set.isEmpty()); assertTrue(copy.isEmpty()); assertSame(set.comparator(), copy.comparator()); }
public void testExplicit_tailSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.tailSet("california") instanceof ImmutableSortedSet); assertTrue(set.tailSet("fish") instanceof ImmutableSortedSet); assertThat(set.tailSet("fish")).containsExactly("over", "quick", "jumped").inOrder(); assertThat(set.tailSet("a")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.tailSet("california").isEmpty()); }
public void testExplicit_contains() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.contains("quick")); assertTrue(set.contains("google")); assertFalse(set.contains("")); assertFalse(set.contains("california")); assertFalse(set.contains(null)); }
public void testExplicit_headSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.headSet("a") instanceof ImmutableSortedSet); assertTrue(set.headSet("fish") instanceof ImmutableSortedSet); assertThat(set.headSet("fish")).containsExactly("a", "in", "the").inOrder(); assertThat(set.headSet("california")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.headSet("a").isEmpty()); assertTrue(set.headSet("").isEmpty()); }
public Set<Plugin> loadPlugins() { return ImmutableSortedSet.orderedBy(new PluginComparator()) .addAll(Iterables.transform(loadJarPlugins(), new PluginAdapterFunction())) .addAll(Iterables.transform(loadClassPathPlugins(), new PluginAdapterFunction())) .build(); }
public void testExplicit_ordering_dupes() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "brown", "fox", "jumped", "over", "a", "lazy", "dog") .build(); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
public void testExplicit_ordering() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertThat(set).containsExactly("a", "in", "the", "over", "quick", "jumped").inOrder(); }
@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()); }
@Override protected List<String> create(String[] elements) { Comparator<String> comparator = createExplicitComparator(elements); ImmutableSortedSet.Builder<String> builder = ImmutableSortedSet.orderedBy(comparator); builder.add(BEFORE_FIRST); builder.add(BEFORE_FIRST_2); builder.add(elements); builder.add(AFTER_LAST); builder.add(AFTER_LAST_2); return builder .build() .subSet(BEFORE_FIRST_2, AFTER_LAST_2) .asList() .subList(1, elements.length + 1); } }
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"); }
public void testExplicit_subSet() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); assertTrue(set.subSet("the", "quick") instanceof ImmutableSortedSet); assertTrue(set.subSet("", "b") instanceof ImmutableSortedSet); assertThat(set.subSet("the", "quick")).containsExactly("the", "over").inOrder(); assertThat(set.subSet("a", "california")) .containsExactly("a", "in", "the", "over", "quick", "jumped") .inOrder(); assertTrue(set.subSet("", "b").isEmpty()); assertTrue(set.subSet("vermont", "california").isEmpty()); assertTrue(set.subSet("aaa", "zzz").isEmpty()); try { set.subSet("quick", "the"); fail(); } catch (IllegalArgumentException expected) { } }
public void testAsListInconsistentComprator() { ImmutableSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); ImmutableList<String> list = set.asList(); assertTrue(list.contains("the")); assertEquals(2, list.indexOf("the")); assertEquals(2, list.lastIndexOf("the")); assertFalse(list.contains("dog")); assertEquals(-1, list.indexOf("dog")); assertEquals(-1, list.lastIndexOf("dog")); assertFalse(list.contains("chicken")); assertEquals(-1, list.indexOf("chicken")); assertEquals(-1, list.lastIndexOf("chicken")); }