use of com.yahoo.document.update.ArithmeticValueUpdate.Operator in project vespa by vespa-engine.
the class JsonReaderTestCase method testArithmeticOperators.
@SuppressWarnings({ "cast", "unchecked", "rawtypes" })
@Test
public final void testArithmeticOperators() throws IOException {
Tuple2[] operations = new Tuple2[] { new Tuple2<String, Operator>(UPDATE_DECREMENT, ArithmeticValueUpdate.Operator.SUB), new Tuple2<String, Operator>(UPDATE_DIVIDE, ArithmeticValueUpdate.Operator.DIV), new Tuple2<String, Operator>(UPDATE_INCREMENT, ArithmeticValueUpdate.Operator.ADD), new Tuple2<String, Operator>(UPDATE_MULTIPLY, ArithmeticValueUpdate.Operator.MUL) };
for (Tuple2<String, Operator> operator : operations) {
DocumentUpdate doc = parseUpdate("{\"update\": \"id:unittest:testset::whee\"," + " \"fields\": { " + "\"actualset\": {" + " \"match\": {" + " \"element\": \"person\"," + " \"" + (String) operator.first + "\": 13}}}}");
Map<String, Tuple2<Number, Operator>> matches = new HashMap<>();
FieldUpdate x = doc.getFieldUpdate("actualset");
for (ValueUpdate v : x.getValueUpdates()) {
MapValueUpdate adder = (MapValueUpdate) v;
final String key = ((StringFieldValue) adder.getValue()).getString();
Operator op = ((ArithmeticValueUpdate) adder.getUpdate()).getOperator();
Number n = ((ArithmeticValueUpdate) adder.getUpdate()).getOperand();
matches.put(key, new Tuple2<>(n, op));
}
assertEquals(1, matches.size());
final String o = "person";
assertSame(operator.second, matches.get(o).second);
assertEquals(Double.valueOf(13), matches.get(o).first);
}
}
Aggregations