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