@Test public void testGetKeyValuePairsForKeysContainedIn() throws Exception { ConcurrentInvertedRadixTree<Integer> tree = new ConcurrentInvertedRadixTree<Integer>(getNodeFactory()); tree.put("see", 1); tree.put("think", 2); tree.put("never", 3); tree.put("tree", 4); tree.put("poem", 5); String document = "i think that i shall never see\n" + "a poem lovely as a tree"; assertEquals("[(think, 2), (never, 3), (see, 1), (poem, 5), (tree, 4)]", Iterables.toString(tree.getKeyValuePairsForKeysContainedIn(document))); }
@Override public Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document) { return new Iterable<KeyValuePair<O>>() { @Override public Iterator<KeyValuePair<O>> iterator() { return new LazyIterator<KeyValuePair<O>>() { Iterator<CharSequence> documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator<KeyValuePair<O>> matchesForCurrentSuffix = Collections.<KeyValuePair<O>>emptyList().iterator(); @Override protected KeyValuePair<O> computeNext() { while(!matchesForCurrentSuffix.hasNext()) { if (documentSuffixes.hasNext()) { CharSequence nextSuffix = documentSuffixes.next(); matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(nextSuffix).iterator(); } else { return endOfData(); } } return matchesForCurrentSuffix.next(); } }; } }; }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document) { return new Iterable<KeyValuePair<O>>() { @Override public Iterator<KeyValuePair<O>> iterator() { return new LazyIterator<KeyValuePair<O>>() { Iterator<CharSequence> documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator<KeyValuePair<O>> matchesForCurrentSuffix = Collections.<KeyValuePair<O>>emptyList().iterator(); @Override protected KeyValuePair<O> computeNext() { while(!matchesForCurrentSuffix.hasNext()) { if (documentSuffixes.hasNext()) { CharSequence nextSuffix = documentSuffixes.next(); matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(nextSuffix).iterator(); } else { return endOfData(); } } return matchesForCurrentSuffix.next(); } }; } }; } }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document) { return new Iterable<KeyValuePair<O>>() { @Override public Iterator<KeyValuePair<O>> iterator() { return new LazyIterator<KeyValuePair<O>>() { Iterator<CharSequence> documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator<KeyValuePair<O>> matchesForCurrentSuffix = Collections.<KeyValuePair<O>>emptyList().iterator(); @Override protected KeyValuePair<O> computeNext() { while(!matchesForCurrentSuffix.hasNext()) { if (documentSuffixes.hasNext()) { CharSequence nextSuffix = documentSuffixes.next(); matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(nextSuffix).iterator(); } else { return endOfData(); } } return matchesForCurrentSuffix.next(); } }; } }; } ConcurrentInvertedRadixTree(NodeFactory nodeFactory); }
ConcurrentInvertedRadixTree implements InvertedRadixTree<O>, PrettyPrintable, Serializable { @Override public Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document) { return new Iterable<KeyValuePair<O>>() { @Override public Iterator<KeyValuePair<O>> iterator() { return new LazyIterator<KeyValuePair<O>>() { Iterator<CharSequence> documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator<KeyValuePair<O>> matchesForCurrentSuffix = Collections.<KeyValuePair<O>>emptyList().iterator(); @Override protected KeyValuePair<O> computeNext() { while(!matchesForCurrentSuffix.hasNext()) { if (documentSuffixes.hasNext()) { CharSequence nextSuffix = documentSuffixes.next(); matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(nextSuffix).iterator(); } else { return endOfData(); } } return matchesForCurrentSuffix.next(); } }; } }; } 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<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(final CharSequence document) { return new Iterable<KeyValuePair<O>>() { @Override public Iterator<KeyValuePair<O>> iterator() { return new LazyIterator<KeyValuePair<O>>() { Iterator<CharSequence> documentSuffixes = CharSequences.generateSuffixes(document).iterator(); Iterator<KeyValuePair<O>> matchesForCurrentSuffix = Collections.<KeyValuePair<O>>emptyList().iterator(); @Override protected KeyValuePair<O> computeNext() { while(!matchesForCurrentSuffix.hasNext()) { if (documentSuffixes.hasNext()) { CharSequence nextSuffix = documentSuffixes.next(); matchesForCurrentSuffix = radixTree.scanForKeysAtStartOfInput(nextSuffix).iterator(); } else { return endOfData(); } } return matchesForCurrentSuffix.next(); } }; } }; } 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();  }