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
A value update represents some action to perform to a value.
- Author:
- Einar M R Rosenvinge
- See Also:
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ValueUpdate
(ValueUpdate.ValueUpdateClassID valueUpdateClassID) -
Method Summary
Modifier and TypeMethodDescriptionabstract 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
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
abstract T
getValue()
Returns the primary "value" of this update, or null if this kind of update has no valueReturns the valueUpdateClassID of this value update.int
hashCode()
abstract void
serialize
(DocumentUpdateWriter data, DataType superType) abstract void
Sets the value of this.toString()
-
Field Details
-
valueUpdateClassID
-
-
Constructor Details
-
ValueUpdate
-
-
Method Details
-
getValueUpdateClassID
Returns the valueUpdateClassID of this value update. -
checkCompatibility
-
serialize
-
equals
-
hashCode
public int hashCode() -
toString
-
applyTo
-
createAdd
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
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
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:
-
createAddAll
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:
-
createIncrement
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
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:
-
createDecrement
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
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:
-
createMultiply
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
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:
-
createDivide
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
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:
-
createAssign
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
Creates a new value update that clears the field fromthe document.- Returns:
- a ValueUpdate specifying the removal
-
createMap
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
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
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:
-
createRemoveAll
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:
-
getValue
Returns the primary "value" of this update, or null if this kind of update has no value -
setValue
Sets the value of this. Ignored by update who have no value
-