/** * Creates a new, empty field update with no encapsulated value updates. Use this method to add an arbitrary * set of value updates using the FieldUpdate.addValueUpdate() method. * * @param field the Field to alter * @return a new, empty FieldUpdate * @see com.yahoo.document.update.ValueUpdate * @see FieldUpdate#addValueUpdate(ValueUpdate) */ public static FieldUpdate create(Field field) { return new FieldUpdate(field); }
/** * 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 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 field update, with one encapsulated value update that increments a weight in a weighted set. * * @param field the field to increment one of the weights of * @param key the key whose weight in the weighted set to increment * @param increment the number to increment by * @return a FieldUpdate specifying the increment * @throws IllegalArgumentException if key is not equal to the nested type of the weighted set * @see ValueUpdate#createIncrement(Number) * @see ValueUpdate#createMap(FieldValue, ValueUpdate) */ public static FieldUpdate createIncrement(Field field, FieldValue key, Number increment) { return new FieldUpdate(field, ValueUpdate.createIncrement(key, increment)); }
/** * 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)); }
/** * Creates a new field update that clears the field. This operation removes the value/field completely. * * @param field the Field to clear * @return a FieldUpdate specifying the clearing * @see com.yahoo.document.update.FieldUpdate#createClear(Field) */ public static FieldUpdate createClearField(Field field) { return new FieldUpdate(field, ValueUpdate.createClear()); }
/** * Creates a new field update, with one encapsulated value update that increments a value. * Note that the data type must be a numeric type. * * @param field the field to increment the value of * @param increment the number to increment by * @return a FieldUpdate specifying the increment * @throws UnsupportedOperationException if the data type is non-numeric * @see ValueUpdate#createIncrement(Number) */ public static FieldUpdate createIncrement(Field field, Number increment) { return new FieldUpdate(field, ValueUpdate.createIncrement(increment)); }
/** * Creates a new field update, with one encapsulated value update * specifying an addition of a value to an array or a key to a weighted set (with default weight 1). * * @param field the Field to add a value to * @param value the value to add to the array, or key to add to the weighted set * @return a FieldUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of newValue does not match the type required by field * @throws UnsupportedOperationException if the field type is not array or weighted set * @see com.yahoo.document.update.ValueUpdate#createAdd(FieldValue) */ public static FieldUpdate createAdd(Field field, FieldValue value) { return new FieldUpdate(field, ValueUpdate.createAdd(value)); }
/** * 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 assigns a new value, completely overwriting the previous value. Note that it is possible to pass * newValue=null to this method to remove the value completely. * * @param field the Field to assign a new value to * @param newValue the value to assign * @return a FieldUpdate specifying the assignment * @throws IllegalArgumentException if the runtime type of newValue does not match the type required by field * @see com.yahoo.document.update.ValueUpdate#createAssign(FieldValue) */ public static FieldUpdate createAssign(Field field, FieldValue newValue) { return new FieldUpdate(field, ValueUpdate.createAssign(newValue)); }
/** * 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 field update, with encapsulated value updates, * specifying an addition of all values in a given list to an array. If this method is used on a weighted set data * type, the default weights will be 1. * * @param field the Field to add an array of values to * @param values a List containing the values to add * @return a FieldUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of values does not match the type required by field * @throws UnsupportedOperationException if the field type is not array or weighted set * @see com.yahoo.document.update.ValueUpdate#createAddAll(java.util.List) * @see ValueUpdate#createAdd(FieldValue) */ public static FieldUpdate createAddAll(Field field, List<? extends FieldValue> values) { return new FieldUpdate(field, ValueUpdate.createAddAll(values)); }
/** * 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)); }
/** * Creates a new field update, with one encapsulated value update, * specifying the removal of a value from an array or a key/weight from a weighted set. * * @param field the field to remove a value from * @param value the value to remove from the array, or key to remove from the weighted set * @return a FieldUpdate specifying the removal * @throws IllegalArgumentException if the runtime type of newValue does not match the type required * @throws UnsupportedOperationException if the field type is not array or weighted set * @see ValueUpdate#createRemove(FieldValue) */ public static FieldUpdate createRemove(Field field, FieldValue value) { return new FieldUpdate(field, ValueUpdate.createRemove(value)); }
/** * Creates a new field update, with encapsulated value updates, * specifying the removal of all values in a given list from an array or weighted set. Note that this method * is just a convenience method, it simply iterates * through the list and creates value updates by calling createRemove() for each element. * * @param field the field to remove values from * @param values a List containing the values to remove * @return a FieldUpdate specifying the removal * @throws IllegalArgumentException if the runtime type of values does not match the type required by field * @throws UnsupportedOperationException if the field type is not array or weighted set * @see ValueUpdate#createRemoveAll(java.util.List) */ public static FieldUpdate createRemoveAll(Field field, WeightedSet<? extends FieldValue> values) { return new FieldUpdate(field, ValueUpdate.createRemoveAll(values)); } }
/** * Creates a new field update, with encapsulated value updates, * specifying an addition of all key/weight pairs in a weighted set to a weighted set. If this method * is used on an array data type, the weights will be omitted. * * @param field the Field to add the key/weight pairs in a weighted set to * @param set a WeightedSet containing the key/weight pairs to add * @return a FieldUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of values does not match the type required by field * @throws UnsupportedOperationException if the field type is not weighted set or array * @see ValueUpdate#createAdd(FieldValue, Integer) * @see com.yahoo.document.update.ValueUpdate#createAddAll(com.yahoo.document.datatypes.WeightedSet) */ public static FieldUpdate createAddAll(Field field, WeightedSet<? extends FieldValue> set) { return new FieldUpdate(field, ValueUpdate.createAddAll(set)); }
/** * Creates a new field update, with one encapsulated value update, * that clears the value; see documentation for ClearValueUpdate to see behavior * for the individual data types. Note that clearing the value is not the same * clearing the field; this method leaves an empty value, whereas clearing the * field will completely remove the value. * * @param field the field to clear the value of * @return a FieldUpdate specifying the clearing * @see com.yahoo.document.update.ClearValueUpdate * @see ValueUpdate#createClear() * @see FieldUpdate#createClearField(com.yahoo.document.Field) */ public static FieldUpdate createClear(Field field) { return new FieldUpdate(field, ValueUpdate.createClear()); }
/** * Creates a new field update, with one encapsulated value update * specifying an addition of a key (with a specified weight) to a weighted set. If this * method is used on an array data type, the weight will be omitted. * * @param field the Field to a add a key to * @param key the key to add * @param weight the weight to associate with the given key * @return a FieldUpdate specifying the addition * @throws IllegalArgumentException if the runtime type of key does not match the type required by field * @throws UnsupportedOperationException if the field type is not array or weighted set * @see com.yahoo.document.update.ValueUpdate#createAdd(FieldValue,Integer) */ public static FieldUpdate createAdd(Field field, FieldValue key, Integer weight) { return new FieldUpdate(field, ValueUpdate.createAdd(key, weight)); }
public void read(DocumentUpdate update) { short serializationVersion = getShort(null); update.setId(new DocumentId(this)); byte contents = getByte(null); if ((contents & 0x1) == 0) { throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype"); } update.setDocumentType(readDocumentType()); int size = getInt(null); for (int i = 0; i < size; i++) { update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); } }
public void read(DocumentUpdate update) { update.setId(new DocumentId(this)); update.setDocumentType(readDocumentType()); int size = getInt(null); for (int i = 0; i < size; i++) { update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), 8)); } int sizeAndFlags = getInt(null); update.setCreateIfNonExistent(DocumentUpdateFlags.extractFlags(sizeAndFlags).getCreateIfNonExistent()); size = DocumentUpdateFlags.extractValue(sizeAndFlags); for (int i = 0; i < size; i++) { int type = getByte(null); update.addFieldPathUpdate(FieldPathUpdate.create(FieldPathUpdate.Type.valueOf(type), update.getDocumentType(), this)); } }