/* InitialStringSearcher.java * * Copyright (c) 2001, Tuomas Lukka * * This file is part of Gzz. * * Gzz is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Gzz is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Gzz; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Tuomas Lukka */ package org.fenfire.util; import java.util.*; /** Searches for strings having the parameter string * as the initial substring. * Initial, not terribly efficient implementation. * Assumes that we will search for a few of the first characters. *

* Note that searching for a single character will return nothing. * Searching for more than 6 characters will return the same as searching * for the first 6 characters in that string. */ public class InitialStringSearcher implements StringSearcher { /* class Node { char ch; Node nextSibling; Node firstChild; String whole; Object value; } Node root = new Node(); void makeOrGet(Node n, int depth, char ch) { if(n.firstChild != null) { } Node prev = n.firstChild; n.firstChild = new Node(); n.firstChild.ch = ch; n.firstChild.nextSibling = prev; return n.firstChild; } public void addString(String s, Object value) { Node cur = root; for(int i=0; i= sets.length) s = s.substring(0, s.length()-1); while(sets[s.length()] == null) { if(s.length() == 0) return null; s = s.substring(0, s.length()-1); } return (Collection)sets[s.length()].get(s.toLowerCase()); } }