@Test public void testSearch() { for (int index = 0; index < 100; index++) { store.put("key" + index, "value" + index); } KeyValueIterable<String, String> entries = store.search("key50"); for (Entry<String, String> entry : entries) { puts(entry.key(), entry.value()); } entries.close(); }
@Override public KeyValueIterable<String, String> search(String startKey) { final Set<Map.Entry<String, String>> entries = map.tailMap(startKey).entrySet(); final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); return new KeyValueIterable<String, String>() { @Override public void close() { } @Override public Iterator<Entry<String, String>> iterator() { return new Iterator<Entry<String, String>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<String, String> next() { Map.Entry<String, String> next = iterator.next(); return new Entry<>(next.getKey(), next.getValue()); } @Override public void remove() { iterator.remove(); } }; } }; }
InMemoryStringKeyValueStore implements StringKeyValueStore { @Override public KeyValueIterable<String, String> search(String startKey) { final Set<Map.Entry<String, String>> entries = map.tailMap(startKey).entrySet(); final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); return new KeyValueIterable<String, String>() { @Override public void close() { } @Override public Iterator<Entry<String, String>> iterator() { return new Iterator<Entry<String, String>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<String, String> next() { Map.Entry<String, String> next = iterator.next(); return new Entry<>(next.getKey(), next.getValue()); } @Override public void remove() { iterator.remove(); } }; } }; } }
InMemoryStringKeyValueStore implements StringKeyValueStore { @Override public KeyValueIterable<String, String> search(String startKey) { final Set<Map.Entry<String, String>> entries = map.tailMap(startKey).entrySet(); final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); return new KeyValueIterable<String, String>() { @Override public void close() { } @Override public Iterator<Entry<String, String>> iterator() { return new Iterator<Entry<String, String>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<String, String> next() { Map.Entry<String, String> next = iterator.next(); return new Entry<>(next.getKey(), next.getValue()); } @Override public void remove() { iterator.remove(); } }; } }; }  }
InMemoryStringKeyValueStore implements StringKeyValueStore { @Override public KeyValueIterable<String, String> search(String startKey) { final Set<Map.Entry<String, String>> entries = map.tailMap(startKey).entrySet(); final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); return new KeyValueIterable<String, String>() { @Override public void close() { } @Override public Iterator<Entry<String, String>> iterator() { return new Iterator<Entry<String, String>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<String, String> next() { Map.Entry<String, String> next = iterator.next(); return new Entry<>(next.getKey(), next.getValue()); } @Override public void remove() { iterator.remove(); } }; } }; }  @Override void put(String key, String value); @Override void putAll(Map<String, String> values); @Override void removeAll(Iterable<String> keys); void remove(String key); @Override KeyValueIterable<String, String> search(String startKey); @Override KeyValueIterable<String, String> loadAll(); @Override Collection<String> loadAllKeys(); @Override String load(String key); @Override Map<String, String> loadAllByKeys(Collection<String> key); @Override void close(); @Override boolean isOpen(); @Override boolean isClosed(); }
InMemoryStringKeyValueStore implements StringKeyValueStore { @Override public KeyValueIterable<String, String> search(String startKey) { final Set<Map.Entry<String, String>> entries = map.tailMap(startKey).entrySet(); final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); return new KeyValueIterable<String, String>() { @Override public void close() { } @Override public Iterator<Entry<String, String>> iterator() { return new Iterator<Entry<String, String>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Entry<String, String> next() { Map.Entry<String, String> next = iterator.next(); return new Entry<>(next.getKey(), next.getValue()); } @Override public void remove() { iterator.remove(); } }; } }; }  @Override void put(String key, String value); @Override void putAll(Map<String, String> values); @Override void removeAll(Iterable<String> keys); void remove(String key); @Override KeyValueIterable<String, String> search(String startKey); @Override KeyValueIterable<String, String> loadAll(); @Override Collection<String> loadAllKeys(); @Override String load(String key); @Override Map<String, String> loadAllByKeys(Collection<String> key); @Override void close(); @Override boolean isOpen(); @Override boolean isClosed();  }