[代码] [Java]代码 import java.util.HashMap; import java.util.Map; import com.baijob.commonTools.LangUtil; /** * 单词树 * @author Luxiaolei * */ public class Words extends HashMaphttp://www.fpzhangsha.com/linked/20130227.do; ords>{ private static final long serialVersionUID = -4646423269465809276L; /** 关键词类型,可否最终一个字符 */ public Map types = new HashMap(); public Words() { } /** * * @param type 类型 */ public Words(int type) { types.put(type, false); } /** * 添加单词 * @param word 单词 * @param type 类型 */ public void addWord(String word, int type){ //已是单词的结尾 if(LangUtil.isEmpty(word)){ this.types.put(type, true); this.clear(); return; } //已是关键词的结尾,则完毕(即只保存最短字符串) Boolean isEnd = this.types.get(type); if(isEnd != null