public Comparator<? super Integer> comparator() { return core.comparator(); }
@Override public Comparator<? super K> comparator() { synchronized (mutex) { return delegate().comparator(); } }
@Override public Comparator<? super K> comparator() { return delegate().comparator(); }
@Override public Comparator<? super K> comparator() { return sortedMap().comparator(); }
@Override public Comparator<? super K> comparator() { return fromMap().comparator(); }
@Override public Comparator<? super K> comparator() { return map().comparator(); }
@Override public Comparator<? super K> comparator() { synchronized (mutex) { return delegate().comparator(); } }
@Override public Comparator<? super K> comparator() { return delegate().comparator(); }
@Override public Comparator<? super K> comparator() { return fromMap().comparator(); }
public void testTailMap() { List<Entry<K, V>> entries = Helpers.copyToList( getSubjectGenerator() .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator())); for (int i = 0; i < entries.size(); i++) { assertEqualInOrder( entries.subList(i, entries.size()), navigableMap.tailMap(entries.get(i).getKey()).entrySet()); } }
public void testSubMap() { List<Entry<K, V>> entries = Helpers.copyToList( getSubjectGenerator() .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator())); for (int i = 0; i < entries.size(); i++) { for (int j = i + 1; j < entries.size(); j++) { assertEqualInOrder( entries.subList(i, j), navigableMap.subMap(entries.get(i).getKey(), entries.get(j).getKey()).entrySet()); } } }
public void testHeadMap() { List<Entry<K, V>> entries = Helpers.copyToList( getSubjectGenerator() .getSampleElements(getSubjectGenerator().getCollectionSize().getNumElements())); Collections.sort(entries, Helpers.<K, V>entryComparator(navigableMap.comparator())); for (int i = 0; i < entries.size(); i++) { assertEqualInOrder( entries.subList(0, i), navigableMap.headMap(entries.get(i).getKey()).entrySet()); } }
public SortedMapSubmapTestMapGenerator( TestSortedMapGenerator<K, V> delegate, Bound to, Bound from) { super(delegate); this.to = to; this.from = from; SortedMap<K, V> emptyMap = delegate.create(); this.entryComparator = Helpers.entryComparator(emptyMap.comparator()); // derive values for inclusive filtering from the input samples SampleElements<Entry<K, V>> samples = delegate.samples(); @SuppressWarnings("unchecked") // no elements are inserted into the array List<Entry<K, V>> samplesList = Arrays.asList(samples.e0(), samples.e1(), samples.e2(), samples.e3(), samples.e4()); Collections.sort(samplesList, entryComparator); this.firstInclusive = samplesList.get(0).getKey(); this.lastInclusive = samplesList.get(samplesList.size() - 1).getKey(); }
private static <K, V> ImmutableSortedMap<K, V> copyOfInternal( Map<? extends K, ? extends V> map, Comparator<? super K> comparator) { boolean sameComparator = false; if (map instanceof SortedMap) { SortedMap<?, ?> sortedMap = (SortedMap<?, ?>) map; Comparator<?> comparator2 = sortedMap.comparator(); sameComparator = (comparator2 == null) ? comparator == NATURAL_ORDER : comparator.equals(comparator2); } if (sameComparator && (map instanceof ImmutableSortedMap)) { // TODO(kevinb): Prove that this cast is safe, even though // Collections.unmodifiableSortedMap requires the same key type. @SuppressWarnings("unchecked") ImmutableSortedMap<K, V> kvMap = (ImmutableSortedMap<K, V>) map; if (!kvMap.isPartialView()) { return kvMap; } } return fromEntries(comparator, sameComparator, map.entrySet()); }
@Override public void setUp() throws Exception { super.setUp(); navigableMap = (SortedMap<K, V>) getMap(); List<Entry<K, V>> 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) { c = entries.get(2); } } }
public void testTreeMapWithInitialMap() { SortedMap<Integer, Integer> map = Maps.newTreeMap(); map.put(5, 10); map.put(3, 20); map.put(1, 30); TreeMap<Integer, Integer> copy = Maps.newTreeMap(map); assertEquals(copy, map); assertSame(copy.comparator(), map.comparator()); }
public void testTreeMultimapAsMapSorted() { TreeMultimap<String, Integer> multimap = createPopulate(); SortedMap<String, Collection<Integer>> asMap = multimap.asMap(); assertEquals(Ordering.natural(), asMap.comparator()); assertEquals("foo", asMap.firstKey()); assertEquals("tree", asMap.lastKey()); Set<Integer> fooValues = ImmutableSet.of(1, 3, 7); Set<Integer> googleValues = ImmutableSet.of(2, 6); Set<Integer> treeValues = ImmutableSet.of(4, 0); assertEquals(ImmutableMap.of("google", googleValues, "tree", treeValues), asMap.tailMap("g")); assertEquals(ImmutableMap.of("google", googleValues, "foo", fooValues), asMap.headMap("h")); assertEquals(ImmutableMap.of("google", googleValues), asMap.subMap("g", "h")); }
public void testRowMapComparator() { sortedTable = TreeBasedTable.create(); assertSame(Ordering.natural(), sortedTable.rowMap().comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); assertSame(Collections.reverseOrder(), sortedTable.rowMap().comparator()); }
public void testColumnComparator() { sortedTable = TreeBasedTable.create(); sortedTable.put("", 42, 'x'); assertSame(Ordering.natural(), sortedTable.columnComparator()); assertSame( Ordering.natural(), ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next()) .comparator()); sortedTable = TreeBasedTable.create(Collections.reverseOrder(), Ordering.usingToString()); sortedTable.put("", 42, 'x'); assertSame(Ordering.usingToString(), sortedTable.columnComparator()); assertSame( Ordering.usingToString(), ((SortedMap<Integer, Character>) sortedTable.rowMap().values().iterator().next()) .comparator()); }
public void testAsMapSortedReadsThrough() { SortedSet<String> strings = new NonNavigableSortedSet(); Collections.addAll(strings, "one", "two", "three"); SortedMap<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")); strings.add("four"); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5, "four", 4), map); assertEquals(Integer.valueOf(4), map.get("four")); SortedMap<String, Integer> headMap = map.headMap("two"); assertEquals(ImmutableSortedMap.of("four", 4, "one", 3, "three", 5), headMap); strings.add("five"); strings.remove("one"); assertEquals(ImmutableSortedMap.of("five", 4, "four", 4, "three", 5), headMap); assertThat(map.entrySet()) .containsExactly( mapEntry("five", 4), mapEntry("four", 4), mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); }