src/spelling/AutoCompleteDictionaryTrie.java
/** 
	 *  * Returns up to the n "best" predictions, including the word itself,
     * in terms of length
     * If this string is not in the trie, it returns null.
     * @param text The text to use at the word stem
     * @param n The maximum number of predictions desired.
     * @return A list containing the up to n best predictions
     */
Returns up to the n "best" predictions, including the word itself,
in terms of length
If this string is not in the trie, it returns null.
@param text The text to use at the word stem
@param n The maximum number of predictions desired.
@return A list containing the up to n best predictions
Returns up to the n " best " predictions including the word itself in terms of length If this string is not in the trie it returns null . @param text The text to use at the word stem @param n The maximum number of predictions desired . @return A list containing the up to n best predictions
@Override
     public List<String> predictCompletions(String prefix, int numCompletions) 
     {
    	 List<String> completionList = new ArrayList<String>();	    	 
    	 LinkedList<TrieNode> queue = new LinkedList<TrieNode>();
    	 TrieNode currentNode=null;
    	 TrieNode next=null;
    	 currentNode=root;
    	 char [] prefixChar=null;
    	 prefix=prefix.toLowerCase();
    	 prefixChar=prefix.toCharArray();
    	 char ch='\0';
    	 for(int i=0;i<prefix.length();i++){
					ch=prefixChar[i];
					next = currentNode.getChild(ch);
					if (null != next) {
						currentNode = next;						
						if(i==prefix.length()-1){
							System.out.println(" @#@ prefix.equalsIgnoreCase(currentNode.getText()) ="+prefix.equalsIgnoreCase(currentNode.getText()));
							System.out.println(" !@#@@ stem currentNode="+currentNode.toString());
							queue.add(currentNode);
						}				
					} else { 
						return completionList;
					}
			}
	    	 int count=0;
	    	 TrieNode wordNode=null;
	    	 System.out.println(" @#$#@ First part of algo is over ....");
	    	 System.out.println(" @#$@#$#@ queue size ="+queue.size());
	    	 while(!queue.isEmpty()&&count<numCompletions){	    	 
	    		 System.out.println(" count ="+count);
	    		 wordNode=queue.remove();
	    		 for (Character c : wordNode.getValidNextCharacters()) {	  
						System.out.println(" c ="+c + "  @#$ wordNode.getChild(c) ="+wordNode.getChild(c));	
						queue.add(wordNode.getChild(c));
					}
	    		 System.out.println(" wordNode removed from the queue ="+wordNode.getText() );
				if (wordNode.endsWord()) {
					completionList.add(wordNode.getText());
					count++;
					System.out.println(" @#$#@ wordNode.getValidNextCharacters() ="+wordNode.getValidNextCharacters());
					System.out.println(" added words to queue and queue size ="+queue.size());
				}
	    	 }
	    	 System.out.println(" Final completion list ="+completionList.toString());
         return completionList;
     }
@ Override public List < String > predictCompletions ( String prefix , int numCompletions ) { List < String > completionList = new ArrayList < String > ( ) ; LinkedList < TrieNode > queue = new LinkedList < TrieNode > ( ) ; TrieNode currentNode = null ; TrieNode next = null ; currentNode = root ; char [ ] prefixChar = null ; prefix = prefix . toLowerCase ( ) ; prefixChar = prefix . toCharArray ( ) ; char ch = '\0' ; for ( int i = 0 ; i < prefix . length ( ) ; i ++ ) { ch = prefixChar [ i ] ; next = currentNode . getChild ( ch ) ; if ( null != next ) { currentNode = next ; if ( i == prefix . length ( ) - 1 ) { System . out . println ( " @#@ prefix.equalsIgnoreCase(currentNode.getText()) =" + prefix . equalsIgnoreCase ( currentNode . getText ( ) ) ) ; System . out . println ( " !@#@@ stem currentNode=" + currentNode . toString ( ) ) ; queue . add ( currentNode ) ; } } else { return completionList ; } } int count = 0 ; TrieNode wordNode = null ; System . out . println ( " @#$#@ First part of algo is over ...." ) ; System . out . println ( " @#$@#$#@ queue size =" + queue . size ( ) ) ; while ( ! queue . isEmpty ( ) && count < numCompletions ) { System . out . println ( " count =" + count ) ; wordNode = queue . remove ( ) ; for ( Character c : wordNode . getValidNextCharacters ( ) ) { System . out . println ( " c =" + c + "  @#$ wordNode.getChild(c) =" + wordNode . getChild ( c ) ) ; queue . add ( wordNode . getChild ( c ) ) ; } System . out . println ( " wordNode removed from the queue =" + wordNode . getText ( ) ) ; if ( wordNode . endsWord ( ) ) { completionList . add ( wordNode . getText ( ) ) ; count ++ ; System . out . println ( " @#$#@ wordNode.getValidNextCharacters() =" + wordNode . getValidNextCharacters ( ) ) ; System . out . println ( " added words to queue and queue size =" + queue . size ( ) ) ; } } System . out . println ( " Final completion list =" + completionList . toString ( ) ) ; return completionList ; }
* Returns up to the n "best" predictions, including the word itself,
 in terms of length
 If this string is not in the trie, it returns null.
* Returns up to the n " best " predictions including the word itself in terms of length If this string is not in the trie it returns null .
//    Create a list of completions to return (initially empty) //Once the stem is found, perform a breadth first search to generate completions  using the following algorithm: //Create a queue (LinkedList) and add the node that completes the stem to the back of the queue // Find the stem in the trie.  If the stem does not appear in the trie, return an empty list						 //    While the queue is not empty and you don't have enough completions: //  Add all of its child nodes to the back of the queue // If it is a word, add it to the completions list