T
- The type of state to be transformed in a chain@FunctionalInterface
@API(status=EXPERIMENTAL,
since="1.7.0")
public interface Transformer<T>
extends java.util.function.Function<T,T>
T
into another value of this type.
Transformation can create a new object, or change the inner state of an object and return it.
In addition to performing a state transformation the mutator function can also check or assert conditions and invariants that should hold when doing the transformation. This is especially useful when a transformer is used as part of an action.
Chain
,
Transformation
,
Action
Modifier and Type | Field and Description |
---|---|
static Transformer<?> |
END_OF_CHAIN
The singleton object used for all calls to endOfChain().
|
static Transformer<?> |
NOOP
The singleton object used for all calls to noop().
|
Modifier and Type | Method and Description |
---|---|
static <T> Transformer<T> |
endOfChain()
Use this transformer to stop further enhancement of a chain.
|
default boolean |
isEndOfChain() |
static <S> Transformer<S> |
mutate(java.lang.String description,
java.util.function.Consumer<S> mutate)
Convenience method to create a transformer with a description.
|
static <T> Transformer<T> |
noop()
Use this transformer to signal a noop transformation.
|
static <S> Transformer<S> |
transform(java.lang.String description,
java.util.function.Function<S,S> transform)
Create a transformer with a description
|
default java.lang.String |
transformation()
Describe the transformation this Transformer is doing in a human understandable way.
|
static final Transformer<?> END_OF_CHAIN
static final Transformer<?> NOOP
static <T> Transformer<T> endOfChain()
Whenever a endOfChain() is chosen by a chain, the chain ends with the current state being provided (e.g. in the chain's iterator) for a last time.
T
- The transformer's state value typestatic <T> Transformer<T> noop()
Noop transformers are ignored and not added to the chain of transformers.
T
- The transformer's state value typestatic <S> Transformer<S> transform(java.lang.String description, java.util.function.Function<S,S> transform)
S
- The type of the state to transformdescription
- A text to describe what the transform is doingtransform
- The actual transforming functionstatic <S> Transformer<S> mutate(java.lang.String description, java.util.function.Consumer<S> mutate)
S
- The type of the state to mutatedescription
- A text to describe what the transform is doingmutate
- The actual mutating operationdefault java.lang.String transformation()
default boolean isEndOfChain()