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.
Author:
Einar M R Rosenvinge
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getValueUpdateClassID

      public ValueUpdate.ValueUpdateClassID getValueUpdateClassID()
      Returns the valueUpdateClassID of this value update.
    • checkCompatibility

      protected abstract void checkCompatibility(DataType fieldType)
    • serialize

      public abstract void serialize(DocumentUpdateWriter data, DataType superType)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 required
      UnsupportedOperationException - 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 add
      weight - 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 required
      UnsupportedOperationException - 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 required
      UnsupportedOperationException - if the field type is not array or weighted set
      See Also:
    • 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 required
      UnsupportedOperationException - if the field type is not weighted set or array
      See Also:
    • 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 increment
      increment - the number to increment by
      Returns:
      a ValueUpdate specifying the increment
      See Also:
    • 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 decrement
      decrement - the number to decrement by
      Returns:
      a ValueUpdate specifying the decrement
      See Also:
    • 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 multiply
      factor - the number to multiply by
      Returns:
      a ValueUpdate specifying the multiplication
      See Also:
    • 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 divide
      divisor - the number to divide by
      Returns:
      a ValueUpdate specifying the division
      See Also:
    • 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 set
      update - 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 exception
      UnsupportedOperationException - 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 required
      UnsupportedOperationException - 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 required
      UnsupportedOperationException - if the field type is not array or weighted set
      See Also:
    • 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 required
      UnsupportedOperationException - if the field type is not array or weighted set
      See Also:
    • 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