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/*
1138N/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A */
1138N/A
0N/Apackage org.opensolaris.opengrok.search.context;
0N/A
0N/A/**
0N/A * Matches a term against a set of tokens
0N/A *
0N/A */
408N/Aclass PhraseMatcher extends LineMatcher {
408N/A private final String[] phraseTerms;
0N/A private int cur;
1190N/A
1138N/A PhraseMatcher(String[] phraseTerms, boolean caseInsensitive) {
1138N/A super(caseInsensitive);
1185N/A this.phraseTerms = phraseTerms.clone();
0N/A cur = 0;
0N/A }
1190N/A
0N/A public int match(String token) {
1138N/A if (equal(token, phraseTerms[cur])) {
0N/A //System.out.println(" PhraseMatcher matched " + token);
0N/A if ( cur < phraseTerms.length-1) {
0N/A cur ++;
0N/A return WAIT; //matching.
0N/A }
1185N/A //System.out.println(" PhraseMatcher match complete with " + token);
1185N/A cur = 0;
1185N/A return MATCHED; //matched!
0N/A } else if (cur > 0) {
0N/A cur = 0;
1138N/A if (equal(token, phraseTerms[cur])) {
0N/A cur ++;
0N/A return WAIT; //matching.
0N/A }
0N/A }
0N/A return NOT_MATCHED;
0N/A }
0N/A}