package org.trie4j;

import org.trie4j.Node;

public class Algorithms {
	public static boolean contains(Node root, String text){
		if(text.length() == 0){
			return root.getLetters().length == 0 && root.isTerminate();
		}
		int i = 0;
		Node node = root;
		while(node != null){
			char[] letters = node.getLetters();
			if(letters.length > 0){
				for(char c : letters){
					if(c != text.charAt(i++)) return false;
				}
				if(i == text.length()){
					return node.isTerminate();
				}
			}
			node = node.getChild(text.charAt(i));
		}
		return false;
	}
}

@@ -14,16 +14,68 @@
 rie4j;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import o
@@ -601,11 +601,662 @@
 alse;%0A%09%7D
+%0A%0A%09public Iterable%3CString%3E commonPrefixSearch(Node root, String query) %7B%0A%09%09List%3CString%3E ret = new ArrayList%3CString%3E();%0A%09%09char%5B%5D queryChars = query.toCharArray();%0A%09%09int cur = 0;%0A%09%09Node node = root;%0A%09%09while(node != null)%7B%0A%09%09%09char%5B%5D letters = node.getLetters();%0A%09%09%09if(letters.length %3E (queryChars.length - cur)) return ret;%0A%09%09%09for(int i = 0; i %3C letters.length; i++)%7B%0A%09%09%09%09if(letters%5Bi%5D != queryChars%5Bcur + i%5D) return ret;%0A%09%09%09%7D%0A%09%09%09if(node.isTerminate())%7B%0A%09%09%09%09ret.add(new String(queryChars, 0 , cur + letters.length));%0A%09%09%09%7D%0A%09%09%09cur += letters.length;%0A%09%09%09if(queryChars.length == cur) return ret;%0A%09%09%09node = node.getChild(queryChars%5Bcur%5D);%0A%09%09%7D%0A%09%09return ret;%0A%09%7D
 %0A%7D%0A

Add commonPrefixSearch logic.