LimeWire collection component api

org.limewire.collection
Class StringTrieSet

java.lang.Object
  extended by org.limewire.collection.StringTrieSet
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>, AutoCompleteDictionary

public class StringTrieSet
extends java.lang.Object
implements AutoCompleteDictionary, java.lang.Iterable<java.lang.String>

Provides a set-like interface designed specifically for Strings. Uses a Trie as the backing map and provides an implementation specific to Strings. Has the same retrieval/insertion times as the backing Trie. Stores the value as the string, for easier retrieval. The goal is to efficiently find Strings that can branch off a prefix.

Primarily designed as an AutoCompleteDictionary.

See Trie for more information.


Constructor Summary
StringTrieSet(boolean ignoreCase)
           
 
Method Summary
 void addEntry(java.lang.String data)
          Adds a value to the set.
 void clear()
          Clears all items in the dictionary.
 boolean contains(java.lang.String data)
          Determines whether or not the Set contains this String.
 java.util.Collection<java.lang.String> getPrefixedBy(java.lang.String data)
          Return all the Strings that can be prefixed by this String.
 boolean isImmediate()
          Returns true if the dictionary can immediately return results.
 java.util.Iterator<java.lang.String> iterator()
          Returns all values (entire TrieSet).
 java.lang.String lookup(java.lang.String data)
          Return the last String in the set that can be prefixed by this String (Trie's are stored in alphabetical order).
 boolean removeEntry(java.lang.String data)
          Removes a value from the Set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTrieSet

public StringTrieSet(boolean ignoreCase)
Method Detail

isImmediate

public boolean isImmediate()
Description copied from interface: AutoCompleteDictionary
Returns true if the dictionary can immediately return results. False if it will block for any reason.

Specified by:
isImmediate in interface AutoCompleteDictionary

addEntry

public void addEntry(java.lang.String data)
Adds a value to the set. Different letter case of values is always kept and significant. If the TrieSet is made case-insensitive, it will not store two Strings with different case but will update the stored values with the case of the last entry.

Specified by:
addEntry in interface AutoCompleteDictionary
Parameters:
data - The string to add to the dictionary.

contains

public boolean contains(java.lang.String data)
Determines whether or not the Set contains this String.


removeEntry

public boolean removeEntry(java.lang.String data)
Removes a value from the Set.

Specified by:
removeEntry in interface AutoCompleteDictionary
Parameters:
data - The string to remove to the dictionary.
Returns:
true if a value was actually removed.

getPrefixedBy

public java.util.Collection<java.lang.String> getPrefixedBy(java.lang.String data)
Return all the Strings that can be prefixed by this String. All values returned by the iterator have their case preserved.

Specified by:
getPrefixedBy in interface AutoCompleteDictionary

lookup

public java.lang.String lookup(java.lang.String data)
Return the last String in the set that can be prefixed by this String (Trie's are stored in alphabetical order). Return null if no such String exist in the current set.

Specified by:
lookup in interface AutoCompleteDictionary
Parameters:
data - The string to use as the base for the lookup. How this routine is implemented determines the behaviour of the component. Typically, the closest matching string that completely contains the given string is returned.

iterator

public java.util.Iterator<java.lang.String> iterator()
Returns all values (entire TrieSet).

Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

clear

public void clear()
Clears all items in the dictionary.

Specified by:
clear in interface AutoCompleteDictionary

LimeWire collection component api

Copyright © 2009 Lime Wire LLC. All Rights Reserved.