com.limegroup.gnutella.util
Class TrieSet

java.lang.Object
  extended bycom.limegroup.gnutella.util.TrieSet
All Implemented Interfaces:
AutoCompleteDictionary

public class TrieSet
extends java.lang.Object
implements AutoCompleteDictionary

A TrieSet. 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


Constructor Summary
TrieSet(boolean caseSensitive)
          This constuctor sets up a dictionary where case IS significant but whose sort order is binary based.
 
Method Summary
 void addEntry(java.lang.String data)
          Adds a value to the set.
 boolean contains(java.lang.String data)
          Determines whether or not the Set contains this String.
 java.util.Iterator getPrefixedBy(java.lang.String data)
          Return all the Strings that can be prefixed by this String.
 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

TrieSet

public TrieSet(boolean caseSensitive)
This constuctor sets up a dictionary where case IS significant but whose sort order is binary based. All Strings are stored with the case of the last entry added.

Method Detail

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.Iterator 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.


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.