Class PrefixTree

java.lang.Object
java.util.AbstractCollection<String>
com.google.gwt.user.client.ui.PrefixTree
All Implemented Interfaces:
Iterable<String>, Collection<String>

class PrefixTree extends AbstractCollection<String>
A prefix tree (aka trie).
  • Field Details

    • prefixLength

      protected final int prefixLength
      Stores the requested prefix length.
    • suffixes

      protected JavaScriptObject suffixes
      Field to store terminal nodes in.
    • subtrees

      protected JavaScriptObject subtrees
      Field to store subtrees in.
    • size

      protected int size
      Store the number of elements contained by this PrefixTree and its sub-trees.
  • Constructor Details

    • PrefixTree

      public PrefixTree()
      Constructor.
    • PrefixTree

      public PrefixTree(Collection<String> source)
      Constructor.
      Parameters:
      source - Initialize from another collection
    • PrefixTree

      public PrefixTree(int prefixLength)
      Constructor.
      Parameters:
      prefixLength - Smaller prefix length equals faster, more direct searches, at a cost of setup time.
    • PrefixTree

      public PrefixTree(int prefixLength, Collection<String> source)
      Constructor.
      Parameters:
      prefixLength - Smaller prefix length equals faster, more direct searches, at a cost of setup time.
      source - Initialize from another collection
  • Method Details

    • createPrefixTree

      protected static PrefixTree createPrefixTree(int prefixLength)
      Used by native methods to create an appropriately blessed PrefixTree.
      Parameters:
      prefixLength - Smaller prefix length equals faster, more direct searches, at a cost of setup time
      Returns:
      a newly constructed prefix tree
    • add

      public boolean add(String s)
      Add a String to the PrefixTree.
      Specified by:
      add in interface Collection<String>
      Overrides:
      add in class AbstractCollection<String>
      Parameters:
      s - The data to add
      Returns:
      true if the string was added, false otherwise
    • clear

      public void clear()
      Initialize native state.
      Specified by:
      clear in interface Collection<String>
      Overrides:
      clear in class AbstractCollection<String>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<String>
      Overrides:
      contains in class AbstractCollection<String>
    • contains

      public boolean contains(String s)
    • getSuggestions

      public List<String> getSuggestions(String search, int limit)
      Retrieve suggestions from the PrefixTree. The number of items returned from getSuggestions may slightly exceed limit so that all suffixes and partial stems will be returned. This prevents the search space from changing size if the PrefixTree is used in an interactive manner.
      The returned List is guaranteed to be safe; changing its contents will not affect the PrefixTree.
      Parameters:
      search - The prefix to search for
      limit - The desired number of results to retrieve
      Returns:
      A List of suggestions
    • iterator

      public Iterator<String> iterator()
      Specified by:
      iterator in interface Collection<String>
      Specified by:
      iterator in interface Iterable<String>
      Specified by:
      iterator in class AbstractCollection<String>
    • size

      public int size()
      Get the number of all elements contained within the PrefixTree.
      Specified by:
      size in interface Collection<String>
      Specified by:
      size in class AbstractCollection<String>
      Returns:
      the size of the prefix tree
    • suggestImpl

      protected void suggestImpl(String search, String prefix, Collection<String> output, int limit)