/** * Calls the smallest subMap overload that filters out the extreme values. This method is * overridden in NavigableMapTestSuiteBuilder. */ SortedMap<K, V> createSubMap(SortedMap<K, V> map, K firstExclusive, K lastExclusive) { if (from == Bound.NO_BOUND && to == Bound.EXCLUSIVE) { return map.headMap(lastExclusive); } else if (from == Bound.INCLUSIVE && to == Bound.NO_BOUND) { return map.tailMap(firstInclusive); } else if (from == Bound.INCLUSIVE && to == Bound.EXCLUSIVE) { return map.subMap(firstInclusive, lastExclusive); } else { throw new IllegalArgumentException(); } }
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) { return delegate().subMap(fromKey, toKey); }
/** * Creates a sub map by using the given range (both ends inclusive). */ public static <V> SortedMap<Integer,V> filter(SortedMap<Integer,V> map, String from, String to) { if(from==null && to==null) return map; if(to==null) return map.headMap(Integer.parseInt(from)-1); if(from==null) return map.tailMap(Integer.parseInt(to)); return map.subMap(Integer.parseInt(to),Integer.parseInt(from)-1); }
/** * Creates a sub map by using the given range (upper end inclusive). */ @Restricted(NoExternalUse.class) public static <V> SortedMap<Integer,V> filterExcludingFrom(SortedMap<Integer,V> map, String from, String to) { if(from==null && to==null) return map; if(to==null) return map.headMap(Integer.parseInt(from)); if(from==null) return map.tailMap(Integer.parseInt(to)); return map.subMap(Integer.parseInt(to),Integer.parseInt(from)); }
@CollectionSize.Require(SEVERAL) public void testSubMapIllegal() { try { navigableMap.subMap(c.getKey(), a.getKey()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
public SortedMap<Integer, R> subMap(Integer fromKey, Integer toKey) { return new BuildReferenceMapAdapter<R>(loader,core.subMap(fromKey, toKey)); }
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) { synchronized (mutex) { return sortedMap(delegate().subMap(fromKey, toKey), mutex); } }
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) { return new FilteredEntrySortedMap<>(sortedMap().subMap(fromKey, toKey), predicate); }
@Override public SortedSet<K> subSet(K fromElement, K toElement) { return new SortedKeySet<>(map().subMap(fromElement, toElement)); }
@Override public SortedMap<K, V2> subMap(K fromKey, K toKey) { return transformEntries(fromMap().subMap(fromKey, toKey), transformer); }
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()); } } }
@Override public SortedMap<K, V> subMap(K fromKey, K toKey) { synchronized (mutex) { return sortedMap(delegate().subMap(fromKey, toKey), mutex); } }
@Override public SortedMap<K, V2> subMap(K fromKey, K toKey) { return transformEntries(fromMap().subMap(fromKey, toKey), transformer); }
public void testHeadSubTailMap_FilteredMap() { SortedMap<String, Integer> unfiltered = createUnfiltered(); unfiltered.put("apple", 2); unfiltered.put("banana", 6); unfiltered.put("cat", 4); unfiltered.put("dog", 3); SortedMap<String, Integer> filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); assertEquals(ImmutableMap.of("banana", 6), filtered.headMap("dog")); assertEquals(ImmutableMap.of(), filtered.headMap("banana")); assertEquals(ImmutableMap.of("banana", 6, "dog", 3), filtered.headMap("emu")); assertEquals(ImmutableMap.of("banana", 6), filtered.subMap("banana", "dog")); assertEquals(ImmutableMap.of("dog", 3), filtered.subMap("cat", "emu")); assertEquals(ImmutableMap.of("dog", 3), filtered.tailMap("cat")); assertEquals(ImmutableMap.of("banana", 6, "dog", 3), filtered.tailMap("banana")); } }
@Override protected Map<String, Map<Integer, Character>> makeEmptyMap() { return makeTable().rowMap().subMap("b", "x"); }
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 testRowKeyMapSubMap() { sortedTable = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c', "dog", 2, 'd'); Map<String, Map<Integer, Character>> map = sortedTable.rowMap().subMap("cat", "egg"); assertEquals(ImmutableMap.of(2, 'd'), map.get("dog")); map.clear(); assertTrue(map.isEmpty()); assertEquals(ImmutableSet.of("bar", "foo"), sortedTable.rowKeySet()); }
@Override protected Map<String, Map<Integer, Character>> makePopulatedMap() { TreeBasedTable<String, Integer, Character> table = makeTable(); populateTable(table); return table.rowMap().subMap("b", "x"); }
public void testClearSubMapOfRowMap() { TreeBasedTable<String, String, String> table = TreeBasedTable.create(); table.put("a", "b", "c"); table.put("c", "b", "a"); table.put("b", "b", "x"); table.put("b", "c", "y"); table.put("b", "x", "n"); table.put("a", "a", "d"); table.row("b").subMap("c", "x").clear(); assertEquals(table.row("b"), ImmutableMap.of("b", "x", "x", "n")); table.row("b").subMap("b", "y").clear(); assertEquals(table.row("b"), ImmutableMap.of()); assertFalse(table.backingMap.containsKey("b")); } }
public void testAsMapSorted() { SortedSet<String> strings = new NonNavigableSortedSet(); Collections.addAll(strings, "one", "two", "three"); SortedMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(5), map.get("three")); assertNull(map.get("five")); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); assertThat(map.tailMap("onea").entrySet()) .containsExactly(mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); assertThat(map.subMap("one", "two").entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("three", 5)) .inOrder(); }