@Override public void write(ArithmeticValueUpdate update) { putInt(null, update.getOperator().id); putDouble(null, update.getOperand().doubleValue()); }
@Override public void write(ArithmeticValueUpdate update) { putInt(null, update.getOperator().id); putDouble(null, update.getOperand().doubleValue()); }
@Override public void write(ArithmeticValueUpdate update) { final ArithmeticValueUpdate.Operator operator = update.getOperator(); final String operationKey; switch (operator) { case ADD: operationKey = "increment"; break; case DIV: operationKey = "divide"; break; case MUL: operationKey = "multiply"; break; case SUB: operationKey = "decrement"; break; default: throw new RuntimeException(String.format("Unrecognized arithmetic operator '%s'", operator.name)); } wrapIOException(() -> generator.writeFieldName(operationKey)); update.getValue().serialize(this); }
if (((ArithmeticValueUpdate)upd).getOperator() == ArithmeticValueUpdate.Operator.DIV && ((ArithmeticValueUpdate)upd).getOperand().doubleValue() == 0) { throw new IllegalArgumentException("Division by zero.");