aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java
Publish
Diffstat (limited to 'searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java
new file mode 100755
index 00000000000..e51519059ed
--- /dev/null
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/ConstantNode.java
@@ -0,0 +1,54 @@
+// Copyright 2016 Yahoo Inc. 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.evaluation.Context;
+import com.yahoo.searchlib.rankingexpression.evaluation.Value;
+
+import java.util.Deque;
+
+/**
+ * A node which holds a constant (frozen) value.
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public final class ConstantNode extends ExpressionNode {
+
+ private final String sourceImage;
+
+ 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;
+ this.sourceImage=sourceImage;
+ }
+
+ public Value getValue() { return value; }
+
+ @Override
+ public String toString(SerializationContext context, Deque<String> path, CompositeNode parent) {
+ return sourceString();
+ }
+
+ /** Returns the string which created this, or the value.toString() if not known */
+ public String sourceString() {
+ if (sourceImage != null) return sourceImage;
+ return value.toString();
+ }
+
+ @Override
+ public Value evaluate(Context context) {
+ return value;
+ }
+
+}