0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
407N/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/*
1344N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A */
0N/Apackage org.opensolaris.opengrok.analysis;
0N/A
1267N/Aimport java.util.Iterator;
457N/Aimport java.util.List;
0N/Aimport org.apache.lucene.analysis.TokenStream;
1318N/Aimport org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
0N/A
0N/Apublic final class List2TokenStream extends TokenStream {
481N/A
1267N/A private Iterator<String> it;
0N/A private String[] subTokens;
0N/A private int si;
1318N/A private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
481N/A
481N/A public List2TokenStream(List<String> l) {
1267N/A it = l.iterator();
0N/A }
481N/A
816N/A @Override
1344N/A public final boolean incrementToken() {
1267N/A if (!it.hasNext()) {
931N/A // reached end of stream
928N/A return false;
481N/A }
481N/A
481N/A if (subTokens == null || subTokens.length == si) {
1267N/A String tok = it.next();
481N/A if (tok == null) {
928N/A return false;
1185N/A }
1185N/A if (tok.indexOf('.') > 0) {
1185N/A subTokens = tok.split("[^a-z0-9A-Z_]+");
481N/A } else {
1185N/A subTokens = null;
1318N/A termAtt.setEmpty();
1318N/A termAtt.append(tok);
1185N/A return true;
0N/A }
1185N/A si = 0;
0N/A }
395N/A if (si < subTokens.length) {
1318N/A termAtt.setEmpty();
1318N/A termAtt.append(subTokens[si++]);
928N/A return true;
395N/A }
1185N/A return false;
0N/A }
481N/A
481N/A @Override
0N/A public void close() {
1267N/A it = null;
0N/A }
0N/A}