Class Operation<T>

  • Type Parameters:
    T - the type of a dataset item involved in an operation

    public abstract class Operation<T>
    extends Object
    An insert, delete or update operation.
    • Method Detail

      • type

        public abstract Operation.Type type()
        Returns the type of this operation.
        Returns:
        the type of this operation
      • oldItem

        public Optional<T> oldItem()
        Returns the previous value of the item affected by this operation. Not populated for inserts.
        Returns:
        the previous value of the item affected by in this operation
      • newItem

        public Optional<T> newItem()
        Returns the current value of the item affected by this operation. Not populated for deletes.
        Returns:
        the current value of the item affected by this operation
      • combine

        public Optional<Operation<T>> combine​(Operation<T> other)
        Combines this operation with another operation, using a default item equivalence function.
        Parameters:
        other - the other operation with which to combine
        Returns:
        an Optional containing the combined operation, or an empty Optional if the combination results in a no-op
        Throws:
        InvalidCombination - if:
        • An insert is combined with another insert
        • An update is combined with an insert
        • A delete is combined with an update
        • A delete is combined with a delete
        NullPointerException - if other is null
      • combine

        public abstract Optional<Operation<T>> combine​(Operation<T> other,
                                                       Equivalence<T> equivalence)
        Combines this operation with another operation.
        Parameters:
        other - the other operation with which to combine
        equivalence - a function to determine whether two dataset items are equivalent
        Returns:
        an Optional containing the combined operation, or an empty Optional if the combination results in a no-op
        Throws:
        InvalidCombination - if:
        • An insert is combined with another insert
        • An update is combined with an insert
        • A delete is combined with an update
        • A delete is combined with a delete
        NullPointerException - if other is null or equivalence is null
      • insert

        public static <T> Operation<T> insert​(T item)
        Creates an insert operation for a given item.
        Type Parameters:
        T - the type of the inserted item
        Parameters:
        item - the inserted item
        Returns:
        a new insert operation containing the given item
        Throws:
        NullPointerException - if item is null
      • update

        public static <T> Operation<T> update​(T before,
                                              T after)
        Creates an update operation for a given item in its before and after states.
        Type Parameters:
        T - the type of the updated item
        Parameters:
        before - the item before it was updated
        after - the item after it was updated
        Returns:
        a new update operation containing the given item in its before and after states
        Throws:
        NullPointerException - if before is null or after is null
      • delete

        public static <T> Operation<T> delete​(T item)
        Creates a delete operation for a given item.
        Type Parameters:
        T - the type of the deleted item
        Parameters:
        item - the deleted item
        Returns:
        a new delete operation containing the given item
        Throws:
        NullPointerException - if item is null