Interface Transformer<T>

  • Type Parameters:
    T - The type of state to be transformed in a chain
    All Superinterfaces:
    java.util.function.Function<@NotNull T,​@NotNull T>
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    @API(status=EXPERIMENTAL,
         since="1.7.0")
    public interface Transformer<T>
    extends java.util.function.Function<@NotNull T,​@NotNull T>
    A transformer is used to transform a state of type 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.

    See Also:
    Chain, Transformation, Action
    • Method Summary

      All Methods Static Methods Instance Methods Default Methods 
      Modifier and Type Method 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.
      • Methods inherited from interface java.util.function.Function

        andThen, apply, compose
    • Field Detail

      • NOOP

        static final Transformer<?> NOOP
        The singleton object used for all calls to noop().
    • Method Detail

      • endOfChain

        static <T> Transformer<T> endOfChain()
        Use this transformer to stop further enhancement of a chain.

        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.

        Type Parameters:
        T - The transformer's state value type
        Returns:
        a transformer instance
      • noop

        static <T> Transformer<T> noop()
        Use this transformer to signal a noop transformation. This can be useful when a Transformation wants to provide a transformer that does nothing in some circumstances.

        Noop transformers are ignored and not added to the chain of transformers.

        Type Parameters:
        T - The transformer's state value type
        Returns:
        a transformer instance
      • transform

        static <S> Transformer<S> transform​(java.lang.String description,
                                            java.util.function.Function<S,​S> transform)
        Create a transformer with a description
        Type Parameters:
        S - The type of the state to transform
        Parameters:
        description - A text to describe what the transform is doing
        transform - The actual transforming function
        Returns:
        a new instance of a transformer
      • mutate

        static <S> Transformer<S> mutate​(java.lang.String description,
                                         java.util.function.Consumer<S> mutate)
        Convenience method to create a transformer with a description. A mutator works on a mutable, stateful object which will always be returned.
        Type Parameters:
        S - The type of the state to mutate
        Parameters:
        description - A text to describe what the transform is doing
        mutate - The actual mutating operation
        Returns:
        a new instance of a transformer
      • transformation

        default java.lang.String transformation()
        Describe the transformation this Transformer is doing in a human understandable way.
        Returns:
        non-empty String
      • isEndOfChain

        default boolean isEndOfChain()