aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-01-29 14:51:23 +0100
committerJon Bratseth <bratseth@oath.com>2018-01-29 14:51:23 +0100
commit1b4fde01d98bf724a54b6c1cfe3ffa4b29aec90e (patch)
tree20a127542b004eceb94e4d1344b3446df8092bd2 /searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
parent28e3545728977a0be82159b8f278be8e772cb59b (diff)
Propagate type information
Diffstat (limited to 'searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java')
-rw-r--r--searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java28
1 files changed, 16 insertions, 12 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
index 23dd841b0ef..a4d3c111356 100644
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/evaluation/ArrayContext.java
@@ -48,12 +48,11 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable {
*
* @throws IllegalArgumentException if the name is not present in the ranking expression this was created with, and
* ignoredUnknownValues is false
- * @since 5.1.5
*/
@Override
public final void put(String name, Value value) {
Integer index = nameToIndex().get(name);
- if (index==null) {
+ if (index == null) {
if (ignoreUnknownValues())
return;
else
@@ -70,24 +69,29 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable {
/**
* Puts a value by index.
* The value will be frozen if it isn't already.
- *
- * @since 5.1.5
*/
public final void put(int index, Value value) {
- values[index]=value.freeze();
+ values[index] = value.freeze();
try {
- doubleValues()[index]=value.asDouble();
+ doubleValues()[index] = value.asDouble();
}
catch (UnsupportedOperationException e) {
- doubleValues()[index]=Double.NaN; // see getDouble below
+ doubleValues()[index] = Double.NaN; // see getDouble below
}
}
+ @Override
+ public ValueType getType(String name) {
+ Integer index = nameToIndex().get(name);
+ if (index == null) return null;
+ return values[index].type();
+ }
+
/** Perform a slow lookup by name */
@Override
public Value get(String name) {
- Integer index=nameToIndex().get(name);
- if (index==null) return DoubleValue.zero;
+ Integer index = nameToIndex().get(name);
+ if (index == null) return DoubleValue.zero;
return values[index];
}
@@ -100,8 +104,8 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable {
/** Perform a fast lookup directly of the value as a double. This is faster than get(index).asDouble() */
@Override
public final double getDouble(int index) {
- double value=doubleValues()[index];
- if (value==Double.NaN)
+ double value = doubleValues()[index];
+ if (value == Double.NaN)
throw new UnsupportedOperationException("Value at " + index + " has no double representation");
return value;
}
@@ -111,7 +115,7 @@ public class ArrayContext extends AbstractArrayContext implements Cloneable {
* in a different thread (i.e, name name to index map, different value set.
*/
public ArrayContext clone() {
- ArrayContext clone=(ArrayContext)super.clone();
+ ArrayContext clone = (ArrayContext)super.clone();
clone.values = new Value[nameToIndex().size()];
Arrays.fill(values,constantZero);
return clone;