blob: 68134cc85b48e9a13db0f08795197a8895e1151a (
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
48
49
50
51
52
53
54
55
56
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.searchlib.rankingexpression.rule;
import com.yahoo.searchlib.rankingexpression.Reference;
import com.yahoo.searchlib.rankingexpression.evaluation.Context;
import com.yahoo.searchlib.rankingexpression.evaluation.Value;
import com.yahoo.tensor.TensorType;
import com.yahoo.tensor.evaluation.TypeContext;
import java.util.Deque;
/**
* A node which holds a constant (frozen) value.
*
* @author Simon Thoresen Hult
*/
public final class ConstantNode extends ExpressionNode {
private final Value value;
public ConstantNode(Value value) {
this(value,null);
}
/**
* Creates a constant value
*
* @param value the value. Ownership of this value is transferred to this.
* @param sourceImage the source string image producing this value
*/
public ConstantNode(Value value, String sourceImage) {
value.freeze();
this.value = value;
}
public Value getValue() { return value; }
@Override
public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) {
return string.append(sourceString());
}
/** Returns the string which created this, or the value.toString() if not known */
public String sourceString() {
return value.toString();
}
@Override
public TensorType type(TypeContext<Reference> context) { return value.type(); }
@Override
public Value evaluate(Context context) {
return value;
}
}
|