<K, V> void testNavigationAgainstExpected( NavigableMap<K, V> expected, NavigableMap<K, V> navigableMap, Iterable<K> keysToTest) { for (K key : keysToTest) { assertEquals(expected.lowerEntry(key), navigableMap.lowerEntry(key)); assertEquals(expected.floorEntry(key), navigableMap.floorEntry(key)); assertEquals(expected.ceilingEntry(key), navigableMap.ceilingEntry(key)); assertEquals(expected.higherEntry(key), navigableMap.higherEntry(key)); for (boolean inclusive : new boolean[] {false, true}) { ASSERT .that(navigableMap.headMap(key, inclusive).entrySet()) .has() .allFrom(expected.headMap(key, inclusive).entrySet()) .inOrder(); ASSERT .that(navigableMap.tailMap(key, inclusive).entrySet()) .has() .allFrom(expected.tailMap(key, inclusive).entrySet()) .inOrder(); ASSERT .that(navigableMap.headMap(key, inclusive).descendingMap().entrySet()) .has() .allFrom(expected.headMap(key, inclusive).descendingMap().entrySet()) .inOrder(); ASSERT .that(navigableMap.tailMap(key, inclusive).descendingMap().entrySet()) .has() .allFrom(expected.tailMap(key, inclusive).descendingMap().entrySet()) .inOrder(); } } }
@CollectionSize.Require(SEVERAL) public void testLower() { resetWithHole(); assertEquals(null, navigableMap.lowerEntry(a.getKey())); assertEquals(null, navigableMap.lowerKey(a.getKey())); assertEquals(a, navigableMap.lowerEntry(b.getKey())); assertEquals(a.getKey(), navigableMap.lowerKey(b.getKey())); assertEquals(a, navigableMap.lowerEntry(c.getKey())); assertEquals(a.getKey(), navigableMap.lowerKey(c.getKey())); }
@CollectionSize.Require(ZERO) public void testEmptyMapNearby() { assertNull(navigableMap.lowerEntry(samples.e0.getKey())); assertNull(navigableMap.lowerKey(samples.e0.getKey())); assertNull(navigableMap.floorEntry(samples.e0.getKey())); assertNull(navigableMap.floorKey(samples.e0.getKey())); assertNull(navigableMap.ceilingEntry(samples.e0.getKey())); assertNull(navigableMap.ceilingKey(samples.e0.getKey())); assertNull(navigableMap.higherEntry(samples.e0.getKey())); assertNull(navigableMap.higherKey(samples.e0.getKey())); }
@CollectionSize.Require(ONE) public void testSingletonMapNearby() { assertNull(navigableMap.lowerEntry(samples.e0.getKey())); assertNull(navigableMap.lowerKey(samples.e0.getKey())); assertEquals(a, navigableMap.floorEntry(samples.e0.getKey())); assertEquals(a.getKey(), navigableMap.floorKey(samples.e0.getKey())); assertEquals(a, navigableMap.ceilingEntry(samples.e0.getKey())); assertEquals(a.getKey(), navigableMap.ceilingKey(samples.e0.getKey())); assertNull(navigableMap.higherEntry(samples.e0.getKey())); assertNull(navigableMap.higherKey(samples.e0.getKey())); }
private RequestMetaData doGet(final String path) { RequestMetaData requestMetaData = metaDataMap.get(path); if (requestMetaData == null) { final Map.Entry<String, RequestMetaData> entry = treeMap.lowerEntry(path); if (entry == null) { return null; } if (path.startsWith(entry.getKey())) { return entry.getValue(); } else { return null; } } else { return requestMetaData; } }
void checkCanAddRange(Range range) throws CannotAddException { Map.Entry<TextPoint, RangeGroup> previousEntry = rangeMap.lowerEntry(range.end); if (previousEntry != null) { TextPoint previousRangeStart = previousEntry.getKey(); RangeGroup previousRangeGroup = previousEntry.getValue(); TextPoint previousRangeEnd; if (previousRangeGroup.nonEmptyRangeMapping == null) { previousRangeEnd = previousRangeStart; } else { previousRangeEnd = previousRangeGroup.nonEmptyRangeMapping.sourceRange.end; } if (previousRangeEnd.compareTo(range.start) > 0) { throw new CannotAddException( "Ranges overlaps: " + range + " with " + new Range(previousRangeStart, previousRangeEnd)); } } }