@Test public void testGetValuesForKeysPrefixing() throws Exception { ConcurrentInvertedRadixTree<Integer> tree = new ConcurrentInvertedRadixTree<Integer>(getNodeFactory()); tree.put("1234567", 1); tree.put("1234568", 2); tree.put("123", 3); assertEquals("[3, 1]", Iterables.toString(tree.getValuesForKeysPrefixing("1234567"))); assertEquals("[3, 1]", Iterables.toString(tree.getValuesForKeysPrefixing("12345670"))); assertEquals("[3, 2]", Iterables.toString(tree.getValuesForKeysPrefixing("1234568"))); assertEquals("[3, 2]", Iterables.toString(tree.getValuesForKeysPrefixing("12345680"))); assertEquals("[3]", Iterables.toString(tree.getValuesForKeysPrefixing("1234569"))); assertEquals("[3]", Iterables.toString(tree.getValuesForKeysPrefixing("123456"))); assertEquals("[3]", Iterables.toString(tree.getValuesForKeysPrefixing("123"))); assertEquals("[]", Iterables.toString(tree.getValuesForKeysPrefixing("12"))); assertEquals("[]", Iterables.toString(tree.getValuesForKeysPrefixing(""))); }
@Override public Iterable<O> getValuesForKeysPrefixing(final CharSequence document) { return new Iterable<O>() { @Override public Iterator<O> iterator() { return new LazyIterator<O>() { Iterator<KeyValuePair<O>> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { if (matchesForCurrentSuffix.hasNext()) { return matchesForCurrentSuffix.next().getValue(); } else { return endOfData(); } } }; } }; }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<O> getValuesForKeysPrefixing(final CharSequence document) { return new Iterable<O>() { @Override public Iterator<O> iterator() { return new LazyIterator<O>() { Iterator<KeyValuePair<O>> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { if (matchesForCurrentSuffix.hasNext()) { return matchesForCurrentSuffix.next().getValue(); } else { return endOfData(); } } }; } }; } }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<O> getValuesForKeysPrefixing(final CharSequence document) { return new Iterable<O>() { @Override public Iterator<O> iterator() { return new LazyIterator<O>() { Iterator<KeyValuePair<O>> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { if (matchesForCurrentSuffix.hasNext()) { return matchesForCurrentSuffix.next().getValue(); } else { return endOfData(); } } }; } }; } ConcurrentInvertedRadixTree(NodeFactory nodeFactory); }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<O> getValuesForKeysPrefixing(final CharSequence document) { return new Iterable<O>() { @Override public Iterator<O> iterator() { return new LazyIterator<O>() { Iterator<KeyValuePair<O>> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { if (matchesForCurrentSuffix.hasNext()) { return matchesForCurrentSuffix.next().getValue(); } else { return endOfData(); } } }; } }; } ConcurrentInvertedRadixTree(NodeFactory nodeFactory); @Override O put(CharSequence key, O value); @Override O putIfAbsent(CharSequence key, O value); @Override boolean remove(CharSequence key); @Override O getValueForExactKey(CharSequence key); @Override Iterable<CharSequence> getKeysStartingWith(CharSequence prefix); @Override Iterable<O> getValuesForKeysStartingWith(CharSequence prefix); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysStartingWith(CharSequence prefix); @Override Iterable<CharSequence> getClosestKeys(CharSequence candidate); @Override Iterable<O> getValuesForClosestKeys(CharSequence candidate); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForClosestKeys(CharSequence candidate); @Override Iterable<CharSequence> getKeysPrefixing(final CharSequence document); @Override Iterable<O> getValuesForKeysPrefixing(final CharSequence document); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysPrefixing(final CharSequence document); @Override CharSequence getLongestKeyPrefixing(CharSequence document); @Override O getValueForLongestKeyPrefixing(CharSequence document); @Override KeyValuePair<O> getKeyValuePairForLongestKeyPrefixing(CharSequence document); @Override Iterable<CharSequence> getKeysContainedIn(final CharSequence document); @Override Iterable<O> getValuesForKeysContainedIn(final CharSequence document); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document); @Override int size(); @Override Node getNode(); }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<O> getValuesForKeysPrefixing(final CharSequence document) { return new Iterable<O>() { @Override public Iterator<O> iterator() { return new LazyIterator<O>() { Iterator<KeyValuePair<O>> matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(document).iterator(); @Override protected O computeNext() { if (matchesForCurrentSuffix.hasNext()) { return matchesForCurrentSuffix.next().getValue(); } else { return endOfData(); } } }; } }; } ConcurrentInvertedRadixTree(NodeFactory nodeFactory); @Override O put(CharSequence key, O value); @Override O putIfAbsent(CharSequence key, O value); @Override boolean remove(CharSequence key); @Override O getValueForExactKey(CharSequence key); @Override Iterable<CharSequence> getKeysStartingWith(CharSequence prefix); @Override Iterable<O> getValuesForKeysStartingWith(CharSequence prefix); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysStartingWith(CharSequence prefix); @Override Iterable<CharSequence> getClosestKeys(CharSequence candidate); @Override Iterable<O> getValuesForClosestKeys(CharSequence candidate); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForClosestKeys(CharSequence candidate); @Override Iterable<CharSequence> getKeysPrefixing(final CharSequence document); @Override Iterable<O> getValuesForKeysPrefixing(final CharSequence document); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysPrefixing(final CharSequence document); @Override CharSequence getLongestKeyPrefixing(CharSequence document); @Override O getValueForLongestKeyPrefixing(CharSequence document); @Override KeyValuePair<O> getKeyValuePairForLongestKeyPrefixing(CharSequence document); @Override Iterable<CharSequence> getKeysContainedIn(final CharSequence document); @Override Iterable<O> getValuesForKeysContainedIn(final CharSequence document); @Override Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document); @Override int size(); @Override Node getNode();  }