public void testTailMapWriteThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } if (map.size() < 2 || !supportsPut) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); Entry<K, V> firstEntry = iterator.next(); Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); V value = getValueNotInPopulatedMap(); subMap.put(key, value); assertEquals(secondEntry.getValue(), value); assertEquals(map.get(key), value); try { subMap.put(firstEntry.getKey(), value); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
@Override public Iterable<Relationship> getRelationships() { return relationships.values(); }
public Set<Integer> keySet() { return core.keySet(); }
/** * Gets the latest build #m that satisfies {@code m<=n}. * * This is useful when you'd like to fetch a build but the exact build might * be already gone (deleted, rotated, etc.) * @see LazyBuildMixIn#getNearestOldBuild */ public RunT getNearestOldBuild(int n) { SortedMap<Integer, ? extends RunT> m = _getRuns().tailMap(n); if (m.isEmpty()) return null; return m.get(m.firstKey()); }
@Override protected Map<Integer, TypeDefinition> resolveInitializationTypes(ArgumentHandler argumentHandler) { SortedMap<Integer, TypeDefinition> namedTypes = new TreeMap<Integer, TypeDefinition>(); for (Map.Entry<String, TypeDefinition> entry : this.namedTypes.entrySet()) { namedTypes.put(argumentHandler.named(entry.getKey()), entry.getValue()); } return namedTypes; }
public void testFactory_Decorate() { SortedMap base = new TreeMap(); base.put("A", "1"); base.put("B", "2"); base.put("C", "3"); SortedMap trans = TransformedSortedMap.decorate(base, null, TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER); assertEquals(3, trans.size()); assertEquals("1", trans.get("A")); assertEquals("2", trans.get("B")); assertEquals("3", trans.get("C")); trans.put("D", "4"); assertEquals(new Integer(4), trans.get("D")); }
private void addRegion(SortedMap<Long, Collection<HRegion>> sortedRegions, HRegion region, long size) { if (!sortedRegions.containsKey(size)) { sortedRegions.put(size, new ArrayList<>()); } sortedRegions.get(size).add(region); } /**
public void testTailMapRemoveThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } int oldSize = map.size(); if (map.size() < 2 || !supportsRemove) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); Entry<K, V> firstEntry = iterator.next(); Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); subMap.remove(key); assertNull(subMap.remove(firstEntry.getKey())); assertEquals(map.size(), oldSize - 1); assertFalse(map.containsKey(key)); assertEquals(subMap.size(), oldSize - 2); }
public void testTailMapClearThrough() { final SortedMap<K, V> map; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } int oldSize = map.size(); if (map.size() < 2 || !supportsClear) { return; } Iterator<Entry<K, V>> iterator = map.entrySet().iterator(); iterator.next(); // advance Entry<K, V> secondEntry = iterator.next(); K key = secondEntry.getKey(); SortedMap<K, V> subMap = map.tailMap(key); int subMapSize = subMap.size(); subMap.clear(); assertEquals(map.size(), oldSize - subMapSize); assertTrue(subMap.isEmpty()); } }
/** * Gets the youngest build #m that satisfies {@code n<=m}. * * This is useful when you'd like to fetch a build but the exact build might * be already gone (deleted, rotated, etc.) * @see LazyBuildMixIn#getNearestBuild */ public RunT getNearestBuild(int n) { SortedMap<Integer, ? extends RunT> m = _getRuns().headMap(n - 1); // the map should // include n, so n-1 if (m.isEmpty()) return null; return m.get(m.lastKey()); }
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(); }
public Object getPreviousState(long txid) { final SortedMap<Long, Object> prevMap = _curr.headMap(txid); Object state; if (prevMap.isEmpty()) { state = null; } else { state = prevMap.get(prevMap.lastKey()); } LOG.debug("Getting previous [state = {}], [txid = {}]", state, txid); LOG.trace("[{}]", this); return state; }
/** * Get the object descriptor for the given address * * @param address address * @return object descriptor */ public GraphPathRecord record(long address) { return addresses.get(address); }
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(); }
public void testFirstAndLastKeyFilteredMap() { SortedMap<String, Integer> unfiltered = createUnfiltered(); unfiltered.put("apple", 2); unfiltered.put("banana", 6); unfiltered.put("cat", 3); unfiltered.put("dog", 5); SortedMap<String, Integer> filtered = Maps.filterEntries(unfiltered, CORRECT_LENGTH); assertEquals("banana", filtered.firstKey()); assertEquals("cat", filtered.lastKey()); }
@Test public void testBlock() { for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlock, entry.getKey(), entry.getValue(), expectedObjectValues.get(entry.getKey())); } for (Entry<Integer, Object> entry : expectedStackValues.entrySet()) { assertPositionEquals(testBlockWithNulls, entry.getKey() * 2, entry.getValue(), expectedObjectValues.get(entry.getKey())); assertPositionEquals(testBlockWithNulls, (entry.getKey() * 2) + 1, null, null); } }