Hash2TokenStream.java revision 972
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * See LICENSE.txt included in this distribution for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at LICENSE.txt.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
928N/A * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/Apackage org.opensolaris.opengrok.analysis;
0N/A
392N/Aimport java.util.Iterator;
392N/Aimport java.util.Set;
0N/Aimport org.apache.lucene.analysis.TokenStream;
928N/Aimport org.apache.lucene.analysis.tokenattributes.TermAttribute;
0N/A
0N/Apublic final class Hash2TokenStream extends TokenStream {
0N/A int i=0;
0N/A String term;
0N/A String terms[];
0N/A Iterator<String> keys;
1185N/A private final TermAttribute termAtt= (TermAttribute) addAttribute(TermAttribute.class);
928N/A
349N/A public Hash2TokenStream(Set<String> symbols){
349N/A keys = symbols.iterator();
0N/A }
1190N/A
816N/A @Override
928N/A public boolean incrementToken() throws java.io.IOException {
972N/A while (true) {
972N/A if (i <= 0) {
972N/A if (keys.hasNext()) {
972N/A term = keys.next();
972N/A terms = term.split("[^a-zA-Z_0-9]+");
972N/A i = terms.length;
972N/A if (i > 0) {
928N/A termAtt.setTermBuffer(terms[--i]);
972N/A return true;
972N/A } else {
1185N/A // no tokens found in this key, try next
1185N/A continue;
972N/A }
1185N/A } else {
972N/A return false;
1185N/A }
1185N/A } else {
1185N/A //System.out.println("Returning " + term + h.get(term));
972N/A termAtt.setTermBuffer(terms[--i]);
0N/A return true;
972N/A }
456N/A }
0N/A }
457N/A
1190N/A @Override
0N/A public void close() {
// Nothing to close
}
}