Package uk.megaslice.delta
Class Operation<T>
- java.lang.Object
-
- uk.megaslice.delta.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOperation.TypeThe type of an operation: insert, update or delete.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Optional<Operation<T>>combine(Operation<T> other)Combines this operation with another operation, using a default item equivalence function.abstract Optional<Operation<T>>combine(Operation<T> other, Equivalence<T> equivalence)Combines this operation with another operation.static <T> Operation<T>delete(T item)Creates a delete operation for a given item.static <T> Operation<T>insert(T item)Creates an insert operation for a given item.Optional<T>newItem()Returns the current value of the item affected by this operation.Optional<T>oldItem()Returns the previous value of the item affected by this operation.abstract Operation.Typetype()Returns the type of this operation.static <T> Operation<T>update(T before, T after)Creates an update operation for a given item in its before and after states.
-
-
-
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
Optionalcontaining the combined operation, or an emptyOptionalif 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- ifotheris 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 combineequivalence- a function to determine whether two dataset items are equivalent- Returns:
- an
Optionalcontaining the combined operation, or an emptyOptionalif 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- ifotheris null orequivalenceis 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- ifitemis 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 updatedafter- the item after it was updated- Returns:
- a new update operation containing the given item in its before and after states
- Throws:
NullPointerException- ifbeforeis null orafteris 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- ifitemis null
-
-