FileDocCategorySizeDatePackage
PrefixTrie.javaAPI DocExample2114Mon Jul 23 13:26:56 BST 2007org.apache.struts2.util

PrefixTrie

public class PrefixTrie extends Object
Quickly matches a prefix to an object.

Fields Summary
private static final int
SIZE
Node
root
Constructors Summary
Methods Summary
public java.lang.Objectget(java.lang.String key)

        Node current = root;
        for (int i = 0; i < key.length(); i++) {
            char c = key.charAt(i);
            if (c > SIZE)
                return null;
            current = current.next[c];
            if (current == null)
                return null;
            if (current.value != null)
                return current.value;
        }
        return null;
    
public voidput(java.lang.String prefix, java.lang.Object value)


          
        Node current = root;
        for (int i = 0; i < prefix.length(); i++) {
            char c = prefix.charAt(i);
            if (c > SIZE)
                throw new IllegalArgumentException("'" + c + "' is too big.");
            if (current.next[c] == null)
                current.next[c] = new Node();
            current = current.next[c];
        }
        current.value = value;