Hash2TokenStream.java revision 392
94N/A/*
94N/A * CDDL HEADER START
94N/A *
94N/A * The contents of this file are subject to the terms of the
94N/A * Common Development and Distribution License (the "License").
94N/A * You may not use this file except in compliance with the License.
94N/A *
94N/A * See LICENSE.txt included in this distribution for the specific
94N/A * language governing permissions and limitations under the License.
94N/A *
94N/A * When distributing Covered Code, include this CDDL HEADER in each
94N/A * file and include the License file at LICENSE.txt.
94N/A * If applicable, add the following below this CDDL HEADER, with the
94N/A * fields enclosed by brackets "[]" replaced with your own identifying
94N/A * information: Portions Copyright [yyyy] [name of copyright owner]
94N/A *
94N/A * CDDL HEADER END
94N/A */
94N/A
94N/A/*
94N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
94N/A * Use is subject to license terms.
844N/A */
94N/Apackage org.opensolaris.opengrok.analysis;
94N/A
94N/Aimport java.util.Iterator;
94N/Aimport java.util.Set;
94N/Aimport org.apache.lucene.analysis.Token;
94N/Aimport org.apache.lucene.analysis.TokenStream;
618N/A
94N/Apublic final class Hash2TokenStream extends TokenStream {
94N/A int i=0;
844N/A String term;
844N/A String terms[];
94N/A Iterator<String> keys;
94N/A public Hash2TokenStream(Set<String> symbols){
94N/A keys = symbols.iterator();
94N/A }
94N/A
94N/A public Token next() {
94N/A while(true) {
94N/A if (i <= 0) {
94N/A if (keys.hasNext()) {
94N/A term = keys.next();
94N/A terms = term.split("[^a-zA-Z_0-9]+");
94N/A i = terms.length;
94N/A if (i > 0) {
94N/A //repeat = h.get(term).size();
94N/A //System.out.println("Returning " + term + h.get(term));
99N/A return new Token(terms[--i], 0, 0);
94N/A } else {
94N/A //System.err.println(" ERRROR term " + term);
94N/A //return null;
94N/A }
94N/A } else {
94N/A return null;
94N/A }
94N/A } else {
94N/A //System.out.println("Returning " + term + h.get(term));
181N/A return new Token(terms[--i], 0, 0);
94N/A }
94N/A }
94N/A }
181N/A
94N/A public void close() {
94N/A }
}