Java Code Examples for java.util.concurrent.ConcurrentNavigableMap#tailMap()
The following examples show how to use
java.util.concurrent.ConcurrentNavigableMap#tailMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeltaStoreBasedWaveletState.java From swellrt with Apache License 2.0 | 6 votes |
private static void readDeltasCacheAscending( ConcurrentNavigableMap<HashedVersion, WaveletDeltaRecord> cachedDeltas, HashedVersion startVersion, HashedVersion endVersion, DeltaRecordTrackerReceiver receiver) { Preconditions.checkArgument(startVersion.getVersion() < endVersion.getVersion(), "Delta start version must be less than end version"); ConcurrentNavigableMap<HashedVersion, WaveletDeltaRecord> subCachedDeltas = cachedDeltas .tailMap(startVersion); Iterator<HashedVersion> viterator = subCachedDeltas.navigableKeySet().iterator(); while (viterator.hasNext()) { boolean stop = receiver.put(subCachedDeltas.get(viterator.next())); stop = stop || receiver.halted || receiver.lastDelta.getResultingVersion().getVersion() >= endVersion.getVersion(); if (stop) return; } }
Example 2
Source File: ConcurrentSkipListSubMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 3
Source File: ConcurrentSkipListSubMapTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(m2, k); k = (Integer)(i.next()); assertEquals(m3, k); k = (Integer)(i.next()); assertEquals(m4, k); k = (Integer)(i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 4
Source File: BTreeMapTest5.java From scava with Eclipse Public License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 5
Source File: BlockRangeIndexStorageTest.java From herddb with Apache License 2.0 | 4 votes |
@Test public void testReloadAfterBlockDeletion() throws Exception { PageReplacementPolicy policy = new RandomPageReplacementPolicy(10); IndexDataStorage<Sized<Integer>, Sized<Integer>> storage = new MemoryIndexDataStorage<>(); BlockRangeIndex<Sized<Integer>, Sized<Integer>> index = new BlockRangeIndex<>(400, policy, storage); index.boot(BlockRangeIndexMetadata.empty()); int i = 0; do { Sized<Integer> si = Sized.valueOf(i++); index.put(si, si); } while (index.getNumBlocks() < 4); /* First checkpoint after insertion */ index.checkpoint(); /* Now we empty middle blocks */ /* Map without first key */ ConcurrentNavigableMap<BlockStartKey<Sized<Integer>>, Block<Sized<Integer>, Sized<Integer>>> sub = index.getBlocks().tailMap(index.getBlocks().firstKey(), false); /* Second block */ Block<Sized<Integer>, Sized<Integer>> second = sub.firstEntry().getValue(); /* Map without second key */ sub = sub.tailMap(sub.firstKey(), false); /* Third block */ Block<Sized<Integer>, Sized<Integer>> third = sub.firstEntry().getValue(); /* Copy to avoid concurrent modification */ List<Entry<Sized<Integer>, Sized<Integer>>> toDelete = new ArrayList<>(); second.values.forEach((k, vl) -> vl.forEach(v -> toDelete.add(new SimpleEntry<>(k, v)))); third.values.forEach((k, vl) -> vl.forEach(v -> toDelete.add(new SimpleEntry<>(k, v)))); /* Delete blocks 2 and 3 */ toDelete.forEach(e -> index.delete(e.getKey(), e.getValue())); /* Checkpoint, should remove a block */ BlockRangeIndexMetadata<Sized<Integer>> metadata = index.checkpoint(); assertEquals(2, index.getNumBlocks()); assertEquals(index.getNumBlocks(), metadata.getBlocksMetadata().size()); /* Load a new index from data */ BlockRangeIndex<Sized<Integer>, Sized<Integer>> indexAfterBoot = new BlockRangeIndex<>(1024, new RandomPageReplacementPolicy(10), storage); indexAfterBoot.boot(metadata); /* Check data equality between new and old index */ index.getBlocks().forEach((f, b) -> b.values.forEach((k, vl) -> { List<Sized<Integer>> search = indexAfterBoot.search(k); Assert.assertEquals(vl, search); })); }
Example 6
Source File: ConcurrentSkipListSubMapJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 7
Source File: ConcurrentSkipListSubMapJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(m2, k); k = (Integer)(i.next()); assertEquals(m3, k); k = (Integer)(i.next()); assertEquals(m4, k); k = (Integer)(i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 8
Source File: ConcurrentSkipListSubMapJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 9
Source File: ConcurrentSkipListSubMapJUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(m2, k); k = (Integer)(i.next()); assertEquals(m3, k); k = (Integer)(i.next()); assertEquals(m4, k); k = (Integer)(i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 10
Source File: ConcurrentSkipListSubMapTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testTailMapContents() { ConcurrentNavigableMap map = map5(); SortedMap sm = map.tailMap(two); assertFalse(sm.containsKey(one)); assertTrue(sm.containsKey(two)); assertTrue(sm.containsKey(three)); assertTrue(sm.containsKey(four)); assertTrue(sm.containsKey(five)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); k = (Integer)(i.next()); assertEquals(four, k); k = (Integer)(i.next()); assertEquals(five, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(two, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(three, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(four, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(five, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(four); assertEquals(four, ssm.firstKey()); assertEquals(five, ssm.lastKey()); assertEquals("D", ssm.remove(four)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }
Example 11
Source File: ConcurrentSkipListSubMapTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * headMap returns map with keys in requested range */ public void testDescendingTailMapContents() { ConcurrentNavigableMap map = dmap5(); SortedMap sm = map.tailMap(m2); assertFalse(sm.containsKey(m1)); assertTrue(sm.containsKey(m2)); assertTrue(sm.containsKey(m3)); assertTrue(sm.containsKey(m4)); assertTrue(sm.containsKey(m5)); Iterator i = sm.keySet().iterator(); Object k; k = (Integer)(i.next()); assertEquals(m2, k); k = (Integer)(i.next()); assertEquals(m3, k); k = (Integer)(i.next()); assertEquals(m4, k); k = (Integer)(i.next()); assertEquals(m5, k); assertFalse(i.hasNext()); Iterator ei = sm.entrySet().iterator(); Map.Entry e; e = (Map.Entry)(ei.next()); assertEquals(m2, e.getKey()); assertEquals("B", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m3, e.getKey()); assertEquals("C", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m4, e.getKey()); assertEquals("D", e.getValue()); e = (Map.Entry)(ei.next()); assertEquals(m5, e.getKey()); assertEquals("E", e.getValue()); assertFalse(i.hasNext()); SortedMap ssm = sm.tailMap(m4); assertEquals(m4, ssm.firstKey()); assertEquals(m5, ssm.lastKey()); assertEquals("D", ssm.remove(m4)); assertEquals(1, ssm.size()); assertEquals(3, sm.size()); assertEquals(4, map.size()); }