aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/treenet/rule/ComparisonCondition.java
blob: 6c40406977b207535ead5beb3a7afbda784ccda2 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.treenet.rule;

import com.yahoo.java7compat.Util;

/**
 * Represents a condition which comparing two values
 *
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
 */
public class ComparisonCondition extends Condition {

    private final double rhs;

    /**
     * Constructs a new instance of this class.
     *
     * @param lhs The name of the feature to compare to a constant.
     * @param rhs The constant to compare the feature with.
     * @param ift The label to jump to if left &lt; right.
     * @param iff The label to jump to if left &gt;= right;
     */
    public ComparisonCondition(String lhs, double rhs, String ift, String iff) {
        super(lhs, ift, iff);
        this.rhs = rhs;
    }

    /**
     * Returns the constant to compare the feature with.
     *
     * @return The constant.
     */
    public double getConstant() { return rhs; }

    @Override
    public String conditionToRankingExpression() {
        return "< " + Util.toJava7String(rhs);
    }
}