/** * Creates a new field update, with one encapsulated value update that multiplies a weight in a weighted set. * * @param field the field to multiply one of the weights of * @param key the key whose weight in the weighted set to multiply * @param factor the number to multiply by * @return a FieldUpdate specifying the multiplication * @throws IllegalArgumentException if key is not equal to the nested type of the weighted set * @see ValueUpdate#createMultiply(Number) * @see ValueUpdate#createMap(FieldValue, ValueUpdate) */ public static FieldUpdate createMultiply(Field field, FieldValue key, Number factor) { return new FieldUpdate(field, ValueUpdate.createMultiply(key, factor)); }
/** * Creates a new field update, with one encapsulated value update that multiplies a value. * Note that the data type must be a numeric type. * * @param field the field to multiply the value of * @param factor the number to multiply by * @return a FieldUpdate specifying the multiplication * @throws UnsupportedOperationException if the data type is non-numeric * @see ValueUpdate#createMultiply(Number) */ public static FieldUpdate createMultiply(Field field, Number factor) { return new FieldUpdate(field, ValueUpdate.createMultiply(factor)); }
/** * Creates a new value update that multiplies a weight in a weighted set. Note that this method is just a convenience * method, it simply creates a multiply value update by calling createMultiply() and then creates a map value * update by calling createMap() with the key and the multiply value update as parameters. * * @param key the key whose weight in the weighted set to multiply * @param factor the number to multiply by * @return a ValueUpdate specifying the multiplication * @see ValueUpdate#createMultiply(Number) * @see ValueUpdate#createMap(FieldValue, ValueUpdate) */ public static ValueUpdate createMultiply(FieldValue key, Number factor) { return createMap(key, createMultiply(factor)); }
if ("increment".equals(type)) { fu.addValueUpdate(ValueUpdate.createIncrement(key, by)); } 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; }