aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/SequenceCondition.java
blob: 8b3b0ff48742fb9b7de824f318e39d9fd6c75367 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.rule;

import java.util.Iterator;

import com.yahoo.prelude.semantics.engine.Choicepoint;
import com.yahoo.prelude.semantics.engine.RuleEvaluation;

/**
 * A set of conditions which much match the query in sequence
 *
 * @author bratseth
 */
public class SequenceCondition extends CompositeCondition {

    public SequenceCondition() {
    }

    public boolean doesMatch(RuleEvaluation e) {
        Choicepoint choicepoint = e.getChoicepoint(this, true);
        choicepoint.updateState();
        boolean matches = allSubConditionsMatches(e);
        if (!matches)
            choicepoint.backtrack();
        return matches;
    }

    protected boolean useParentheses() {
        return (getParent() != null
                && ! (getParent() instanceof ChoiceCondition));
    }

    public String toInnerString() {
        return toInnerString(" ");
    }

}