/*
 * Copyright 2012 Takao Nakaguchi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.trie4j;

import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;

public abstract class AbstractTrie implements Trie{
	@Override
	public int findWord(CharSequence chars, int start, int end, StringBuilder word){
		for(int i = start; i < end; i++){
			Iterator<String> it = commonPrefixSearch(chars.subSequence(i, end).toString()).iterator();
			if(it.hasNext()){
				if(word != null) word.append(it.next());
				return i;
			}
		}
		return -1;
	}

	@Override
	public void dump(Writer writer) throws IOException{
		writer.write("-- dump " + getClass().getName() + " --\n");
		Algorithms.dump(getRoot(), writer);
	}

	@Override
	public void trimToSize() {
	}

	@Override
	public void freeze() {
	}

	@Override
	public void insert(String word) {
		throw new UnsupportedOperationException();
	}
}

@@ -963,16 +963,20 @@
 ator();%0A
+//*%0A
 %09%09%09if(it
@@ -1052,16 +1052,264 @@
 i;%0A%09%09%09%7D%0A
+/*/%0A%09%09%09int len = Integer.MIN_VALUE;%0A%09%09%09String ret = null;%0A%09%09%09while(it.hasNext())%7B%0A%09%09%09%09String w = it.next();%0A%09%09%09%09if(w.length() %3E len)%7B%0A%09%09%09%09%09ret = w;%0A%09%09%09%09%09len = w.length();%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09if(ret != null)%7B%0A%09%09%09%09word.append(ret);%0A%09%09%09%09return i;%0A%09%09%09%7D%0A//*/%0A
 %09%09%7D%0A%09%09re

test implementation to find longest word.