/** * Creates a new field update, with one encapsulated value update that divides a value. * Note that the data type must be a numeric type. * * @param field the field to divide the value of * @param divisor the number to divide by * @return a FieldUpdate specifying the division * @throws UnsupportedOperationException if the data type is non-numeric * @see ValueUpdate#createDivide(Number) */ public static FieldUpdate createDivide(Field field, Number divisor) { return new FieldUpdate(field, ValueUpdate.createDivide(divisor)); }
/** * Creates a new value update that divides a weight in a weighted set. Note that this method is just a convenience * method, it simply creates a divide value update by calling createDivide() and then creates a map value * update by calling createMap() with the key and the divide value update as parameters. * * @param key the key whose weight in the weighted set to divide * @param divisor the number to divide by * @return a ValueUpdate specifying the division * @see ValueUpdate#createDivide(Number) * @see ValueUpdate#createMap(FieldValue, ValueUpdate) */ public static ValueUpdate createDivide(FieldValue key, Number divisor) { return createMap(key, createDivide(divisor)); }
/** * Creates a new field update, with one encapsulated value update that divides a weight in a weighted set. * * @param field the field to divide one of the weights of * @param key the key whose weight in the weighted set to divide * @param divisor the number to divide by * @return a FieldUpdate specifying the division * @throws IllegalArgumentException if key is not equal to the nested type of the weighted set * @see ValueUpdate#createDivide(Number) * @see ValueUpdate#createMap(FieldValue, ValueUpdate) */ public static FieldUpdate createDivide(Field field, FieldValue key, Number divisor) { return new FieldUpdate(field, ValueUpdate.createDivide(key, divisor)); }
if ("decrement".equals(type)) { fu.addValueUpdate(ValueUpdate.createDecrement(key, by)); } if ("multiply".equals(type)) { fu.addValueUpdate(ValueUpdate.createMultiply(key, by)); } if ("divide".equals(type)) { fu.addValueUpdate(ValueUpdate.createDivide(key, by)); } } else { if ("increment".equals(type)) { fu.addValueUpdate(ValueUpdate.createIncrement(by)); } if ("decrement".equals(type)) { fu.addValueUpdate(ValueUpdate.createDecrement(by)); } if ("multiply".equals(type)) { fu.addValueUpdate(ValueUpdate.createMultiply(by)); } if ("divide".equals(type)) { fu.addValueUpdate(ValueUpdate.createDivide(by)); }
@SuppressWarnings("rawtypes") public static ValueUpdate readSingleUpdate(TokenBuffer buffer, DataType expectedType, String action) { ValueUpdate update; switch (action) { case UPDATE_ASSIGN: update = (buffer.currentToken() == JsonToken.VALUE_NULL) ? ValueUpdate.createClear() : ValueUpdate.createAssign(readSingleValue(buffer, expectedType)); break; // double is silly, but it's what is used internally anyway case UPDATE_INCREMENT: update = ValueUpdate.createIncrement(Double.valueOf(buffer.currentText())); break; case UPDATE_DECREMENT: update = ValueUpdate.createDecrement(Double.valueOf(buffer.currentText())); break; case UPDATE_MULTIPLY: update = ValueUpdate.createMultiply(Double.valueOf(buffer.currentText())); break; case UPDATE_DIVIDE: update = ValueUpdate.createDivide(Double.valueOf(buffer.currentText())); break; default: throw new IllegalArgumentException("Operation \"" + buffer.currentName() + "\" not implemented."); } return update; }