aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/prelude/semantics/rule/NotCondition.java
blob: 117a17bb7eebd510579519b5f71400b6dffc1270 (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
38
39
40
41
42
43
44
45
46
47
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.semantics.rule;

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

/**
 * A condition which matches if its contained condition doesn't.
 * NotCondition inverts the term checking but not the label checking.
 * That is, it means "label:!term", it does not mean "!label:term".
 *
 * @author bratseth
 */
public class NotCondition extends Condition {

    private Condition condition;

    public NotCondition(Condition condition) {
        this.condition=condition;
    }

    public Condition getCondtiion() { return condition; }

    public void setCondition(Condition condition) { this.condition=condition; }

    protected boolean doesMatch(RuleEvaluation e) {
        e.setInNegation(!e.isInNegation());
        boolean matches=!condition.matches(e);
        e.setInNegation(!e.isInNegation());
        return matches;
    }

    public String toInnerString() {
        return "!" + condition;
    }

    public void makeReferences(RuleBase ruleBase) {
        condition.makeReferences(ruleBase);
    }

    protected boolean hasOpenChoicepoint(RuleEvaluation evaluation) {
        return condition.hasOpenChoicepoint(evaluation);
    }



}