Search in sources :

Example 1 with Operator

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);
    }
}
Also used : Operator(com.yahoo.document.update.ArithmeticValueUpdate.Operator) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) HashMap(java.util.HashMap) AddValueUpdate(com.yahoo.document.update.AddValueUpdate) MapValueUpdate(com.yahoo.document.update.MapValueUpdate) ValueUpdate(com.yahoo.document.update.ValueUpdate) AssignValueUpdate(com.yahoo.document.update.AssignValueUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) ClearValueUpdate(com.yahoo.document.update.ClearValueUpdate) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Tuple2(com.yahoo.collections.Tuple2) FieldUpdate(com.yahoo.document.update.FieldUpdate) ArithmeticValueUpdate(com.yahoo.document.update.ArithmeticValueUpdate) Test(org.junit.Test)

Aggregations

Tuple2 (com.yahoo.collections.Tuple2)1 DocumentUpdate (com.yahoo.document.DocumentUpdate)1 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)1 AddValueUpdate (com.yahoo.document.update.AddValueUpdate)1 ArithmeticValueUpdate (com.yahoo.document.update.ArithmeticValueUpdate)1 Operator (com.yahoo.document.update.ArithmeticValueUpdate.Operator)1 AssignValueUpdate (com.yahoo.document.update.AssignValueUpdate)1 ClearValueUpdate (com.yahoo.document.update.ClearValueUpdate)1 FieldUpdate (com.yahoo.document.update.FieldUpdate)1 MapValueUpdate (com.yahoo.document.update.MapValueUpdate)1 ValueUpdate (com.yahoo.document.update.ValueUpdate)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1