Package com.yahoo.document.update
Class ValueUpdate<T extends FieldValue>
- java.lang.Object
-
- com.yahoo.document.update.ValueUpdate<T>
-
- Direct Known Subclasses:
AddValueUpdate
,ArithmeticValueUpdate
,AssignValueUpdate
,ClearValueUpdate
,MapValueUpdate
,RemoveValueUpdate
,TensorAddUpdate
,TensorModifyUpdate
,TensorRemoveUpdate
public abstract class ValueUpdate<T extends FieldValue> extends Object
A value update represents some action to perform to a value.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ValueUpdate.ValueUpdateClassID
-
Field Summary
Fields Modifier and Type Field Description protected ValueUpdate.ValueUpdateClassID
valueUpdateClassID
-
Constructor Summary
Constructors Modifier Constructor Description protected
ValueUpdate(ValueUpdate.ValueUpdateClassID valueUpdateClassID)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract FieldValue
applyTo(FieldValue oldValue)
protected abstract void
checkCompatibility(DataType fieldType)
static ValueUpdate
createAdd(FieldValue value)
Creates a new value update specifying an addition of a value to an array or a key to a weighted set (with default weight 1).static ValueUpdate
createAdd(FieldValue key, Integer weight)
Creates a new value update specifying an addition of a key (with a specified weight) to a weighted set.static List<ValueUpdate>
createAddAll(WeightedSet<? extends FieldValue> set)
Creates a new value update specifying an addition of all key/weight pairs in a weighted set to a weighted set.static List<ValueUpdate>
createAddAll(List<? extends FieldValue> values)
Creates a new value update specifying an addition of all values in a given list to an array.static ValueUpdate
createAssign(FieldValue newValue)
Creates a new value update that assigns a new value, completely overwriting the previous value.static ValueUpdate
createClear()
Creates a new value update that clears the field fromthe document.static ValueUpdate
createDecrement(FieldValue key, Number decrement)
Creates a new value update that decrements a weight in a weighted set.static ValueUpdate
createDecrement(Number decrement)
Creates a new value update that decrements a value.static ValueUpdate
createDivide(FieldValue key, Number divisor)
Creates a new value update that divides a weight in a weighted set.static ValueUpdate
createDivide(Number divisor)
Creates a new value update that divides a value.static ValueUpdate
createIncrement(FieldValue key, Number increment)
Creates a new value update that increments a weight in a weighted set.static ValueUpdate
createIncrement(Number increment)
Creates a new value update that increments a value.static ValueUpdate
createMap(FieldValue value, ValueUpdate update)
Creates a map value update, which is able to map an update to a value to a subvalue in an array or a weighted set.static ValueUpdate
createMultiply(FieldValue key, Number factor)
Creates a new value update that multiplies a weight in a weighted set.static ValueUpdate
createMultiply(Number factor)
Creates a new value update that multiplies a value.static ValueUpdate
createRemove(FieldValue value)
Creates a new value update specifying the removal of a value from an array or a key/weight from a weighted set.static List<ValueUpdate>
createRemoveAll(WeightedSet<? extends FieldValue> values)
Creates a new value update specifying the removal of all values in a given list from an array or weighted set.static List<ValueUpdate>
createRemoveAll(List<? extends FieldValue> values)
Creates a new value update specifying the removal of all values in a given list from an array or weighted set.boolean
equals(Object o)
abstract T
getValue()
Returns the primary "value" of this update, or null if this kind of update has no valueValueUpdate.ValueUpdateClassID
getValueUpdateClassID()
Returns the valueUpdateClassID of this value update.int
hashCode()
abstract void
serialize(DocumentUpdateWriter data, DataType superType)
abstract void
setValue(T value)
Sets the value of this.String
toString()
-
-
-
Field Detail
-
valueUpdateClassID
protected ValueUpdate.ValueUpdateClassID valueUpdateClassID
-
-
Constructor Detail
-
ValueUpdate
protected ValueUpdate(ValueUpdate.ValueUpdateClassID valueUpdateClassID)
-
-
Method Detail
-
getValueUpdateClassID
public ValueUpdate.ValueUpdateClassID getValueUpdateClassID()
Returns the valueUpdateClassID of this value update.- Returns:
- the valueUpdateClassID of this ValueUpdate
-
checkCompatibility
protected abstract void checkCompatibility(DataType fieldType)
-
serialize
public abstract void serialize(DocumentUpdateWriter data, DataType superType)
-
applyTo
public abstract FieldValue applyTo(FieldValue oldValue)
-
createAdd
public static ValueUpdate createAdd(FieldValue value)
Creates a new value update specifying an addition of a value to an array or a key to a weighted set (with default weight 1).- Parameters:
value
- the value to add to the array, or key to add to the weighted set- Returns:
- a ValueUpdate specifying the addition
- Throws:
IllegalArgumentException
- if the runtime type of newValue does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set
-
createAdd
public static ValueUpdate createAdd(FieldValue key, Integer weight)
Creates a new 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.- Parameters:
key
- the key to addweight
- the weight to associate with the given key- Returns:
- a ValueUpdate specifying the addition
- Throws:
IllegalArgumentException
- if the runtime type of key does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set
-
createAddAll
public static List<ValueUpdate> createAddAll(List<? extends FieldValue> values)
Creates a new value update 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. Note that this method is just a convenience method, it simply iterates through the list and creates value updates by calling createAdd() for each element.- Parameters:
values
- a List containing the values to add- Returns:
- a List of ValueUpdates specifying the addition
- Throws:
IllegalArgumentException
- if the runtime type of values does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set- See Also:
createAdd(FieldValue)
-
createAddAll
public static List<ValueUpdate> createAddAll(WeightedSet<? extends FieldValue> set)
Creates a new value update 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. Note that this method is just a convenience method, it simply iterates through the set and creates value updates by calling createAdd() for each element.- Parameters:
set
- a WeightedSet containing the key/weight pairs to add- Returns:
- a ValueUpdate specifying the addition
- Throws:
IllegalArgumentException
- if the runtime type of values does not match the type requiredUnsupportedOperationException
- if the field type is not weighted set or array- See Also:
createAdd(FieldValue, Integer)
-
createIncrement
public static ValueUpdate createIncrement(Number increment)
Creates a new value update that increments a value. Note that the data type must be a numeric type.- Parameters:
increment
- the number to increment by- Returns:
- a ValueUpdate specifying the increment
- Throws:
UnsupportedOperationException
- if the data type is non-numeric
-
createIncrement
public static ValueUpdate createIncrement(FieldValue key, Number increment)
Creates a new value update that increments a weight in a weighted set. Note that this method is just a convenience method, it simply creates an increment value update by calling createIncrement() and then creates a map value update by calling createMap() with the key and the increment value update as parameters.- Parameters:
key
- the key whose weight in the weighted set to incrementincrement
- the number to increment by- Returns:
- a ValueUpdate specifying the increment
- See Also:
createIncrement(Number)
,createMap(FieldValue, ValueUpdate)
-
createDecrement
public static ValueUpdate createDecrement(Number decrement)
Creates a new value update that decrements a value. Note that the data type must be a numeric type.- Parameters:
decrement
- the number to decrement by- Returns:
- a ValueUpdate specifying the decrement
- Throws:
UnsupportedOperationException
- if the data type is non-numeric
-
createDecrement
public static ValueUpdate createDecrement(FieldValue key, Number 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.- Parameters:
key
- the key whose weight in the weighted set to decrementdecrement
- the number to decrement by- Returns:
- a ValueUpdate specifying the decrement
- See Also:
createDecrement(Number)
,createMap(FieldValue, ValueUpdate)
-
createMultiply
public static ValueUpdate createMultiply(Number factor)
Creates a new value update that multiplies a value. Note that the data type must be a numeric type.- Parameters:
factor
- the number to multiply by- Returns:
- a ValueUpdate specifying the multiplication
- Throws:
UnsupportedOperationException
- if the data type is non-numeric
-
createMultiply
public static ValueUpdate createMultiply(FieldValue key, Number 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.- Parameters:
key
- the key whose weight in the weighted set to multiplyfactor
- the number to multiply by- Returns:
- a ValueUpdate specifying the multiplication
- See Also:
createMultiply(Number)
,createMap(FieldValue, ValueUpdate)
-
createDivide
public static ValueUpdate createDivide(Number divisor)
Creates a new value update that divides a value. Note that the data type must be a numeric type.- Parameters:
divisor
- the number to divide by- Returns:
- a ValueUpdate specifying the division
- Throws:
UnsupportedOperationException
- if the data type is non-numeric
-
createDivide
public static ValueUpdate createDivide(FieldValue key, Number 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.- Parameters:
key
- the key whose weight in the weighted set to dividedivisor
- the number to divide by- Returns:
- a ValueUpdate specifying the division
- See Also:
createDivide(Number)
,createMap(FieldValue, ValueUpdate)
-
createAssign
public static ValueUpdate createAssign(FieldValue newValue)
Creates a new value update that assigns a new value, completely overwriting the previous value.- Parameters:
newValue
- the value to assign- Returns:
- a ValueUpdate specifying the assignment
- Throws:
IllegalArgumentException
- if the runtime type of newValue does not match the type required
-
createClear
public static ValueUpdate createClear()
Creates a new value update that clears the field fromthe document.- Returns:
- a ValueUpdate specifying the removal
-
createMap
public static ValueUpdate createMap(FieldValue value, ValueUpdate update)
Creates a map value update, which is able to map an update to a value to a subvalue in an array or a weighted set. If this update is to be applied to an array, the value parameter must be an integer specifying the index in the array that the update parameter is to be applied to, and the update parameter must be compatible with the sub-datatype of the array. If this update is to be applied on a weighted set, the value parameter must be the key in the set that the update parameter is to be applied to, and the update parameter must be compatible with the INT data type.- Parameters:
value
- the index in case of array, or key in case of weighted setupdate
- the update to apply to the target sub-value- Returns:
- a ValueUpdate specifying the sub-update
- Throws:
IllegalArgumentException
- in case data type is an array type and value is not an Integer; in case data type is a weighted set type and value is not equal to the nested type of the weighted set; or the encapsulated update throws such an exceptionUnsupportedOperationException
- if superType is a single-value type, or anything else than array or weighted set; or the encapsulated update throws such an exception
-
createRemove
public static ValueUpdate createRemove(FieldValue value)
Creates a new value update specifying the removal of a value from an array or a key/weight from a weighted set.- Parameters:
value
- the value to remove from the array, or key to remove from the weighted set- Returns:
- a ValueUpdate specifying the removal
- Throws:
IllegalArgumentException
- if the runtime type of newValue does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set
-
createRemoveAll
public static List<ValueUpdate> createRemoveAll(List<? extends FieldValue> values)
Creates a new value update 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.- Parameters:
values
- a List containing the values to remove- Returns:
- a List of ValueUpdates specifying the removal
- Throws:
IllegalArgumentException
- if the runtime type of values does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set- See Also:
createRemove(FieldValue)
-
createRemoveAll
public static List<ValueUpdate> createRemoveAll(WeightedSet<? extends FieldValue> values)
Creates a new value update 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.- Parameters:
values
- a List containing the values to remove- Returns:
- a List of ValueUpdates specifying the removal
- Throws:
IllegalArgumentException
- if the runtime type of values does not match the type requiredUnsupportedOperationException
- if the field type is not array or weighted set- See Also:
createRemove(FieldValue)
-
getValue
public abstract T getValue()
Returns the primary "value" of this update, or null if this kind of update has no value
-
setValue
public abstract void setValue(T value)
Sets the value of this. Ignored by update who have no value
-
-