Class Stages


  • public final class Stages
    extends java.lang.Object
    A stage-related collection of utility methods.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Stages()
      Prevents instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <DATA,​RESULT>
      Stage<DATA>
      asStage​(Inflector<DATA,​RESULT> inflector)
      Creates a terminal Stage that implements Inflecting interface and returns the provided Inflector instance when the Inflecting.inflector() method is called.
      static <DATA> Stage.Builder<DATA> chain​(java.util.function.Function<DATA,​DATA> transformation)
      Start building a stage chain.
      static <DATA> Stage.Builder<DATA> chain​(ChainableStage<DATA> rootStage)
      Start building a stage chain.
      static <DATA,​RESULT,​T extends Inflector<DATA,​RESULT>>
      T
      extractInflector​(java.lang.Object stage)
      (Optionally) extracts an inflector from a processing stage, provided the stage implements Inflecting interface.
      static <DATA> ChainableStage<DATA> identity()
      Get a chainable "identity" stage.
      static <DATA> DATA process​(DATA data, Stage<DATA> rootStage)
      Run the data through a chain of stages identified by the root stage.
      static <DATA,​RESULT,​T extends Inflector<DATA,​RESULT>>
      DATA
      process​(DATA data, Stage<DATA> rootStage, Ref<T> inflectorRef)
      Run the data through a chain of stages identified by the root stage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Stages

        private Stages()
        Prevents instantiation.
    • Method Detail

      • identity

        public static <DATA> ChainableStage<DATA> identity()
        Get a chainable "identity" stage. This stage, when applied returns the unmodified input data object as part of it's continuation.
        Type Parameters:
        DATA - data type transformable by the stage.
        Returns:
        identity stage.
      • asStage

        public static <DATA,​RESULT> Stage<DATA> asStage​(Inflector<DATA,​RESULT> inflector)
        Creates a terminal Stage that implements Inflecting interface and returns the provided Inflector instance when the Inflecting.inflector() method is called.
        Type Parameters:
        DATA - data type transformable by the stage and returned inflector.
        RESULT - type of result produced by a successful inflector data transformation.
        Parameters:
        inflector - a request to response transformation to be wrapped in a stage.
        Returns:
        a stage that wraps the supplied Inflector.
      • extractInflector

        public static <DATA,​RESULT,​T extends Inflector<DATA,​RESULT>> T extractInflector​(java.lang.Object stage)
        (Optionally) extracts an inflector from a processing stage, provided the stage implements Inflecting interface. Otherwise method returns null.
        Type Parameters:
        DATA - data type transformable by the stage and returned inflector.
        RESULT - type of result produced by a successful inflector data transformation.
        Parameters:
        stage - a stage to extract the inflector from.
        Returns:
        extracted inflector if present, null otherwise.
      • chain

        public static <DATA> Stage.Builder<DATA> chain​(java.util.function.Function<DATA,​DATA> transformation)
        Start building a stage chain.
        Parameters:
        transformation - root transformation function.
        Returns:
        linear accepting chain builder.
      • process

        public static <DATA> DATA process​(DATA data,
                                          Stage<DATA> rootStage)
        Run the data through a chain of stages identified by the root stage.
        Type Parameters:
        DATA - processed data type.
        Parameters:
        data - data to be processed.
        rootStage - root stage of the stage chain.
        Returns:
        processing result.
      • process

        public static <DATA,​RESULT,​T extends Inflector<DATA,​RESULT>> DATA process​(DATA data,
                                                                                                    Stage<DATA> rootStage,
                                                                                                    Ref<T> inflectorRef)
        Run the data through a chain of stages identified by the root stage. If an inflector is found in the leaf stage, it's reference is set into the inflectorRef parameter.
        Type Parameters:
        DATA - processed data type.
        Parameters:
        data - data to be processed.
        rootStage - root stage of the stage chain.
        inflectorRef - a mutable reference to an inflector.
        Returns:
        processing result.