Class CodeExecution<I,​O>

  • All Implemented Interfaces:
    de.esoco.lib.property.Fluent<CoroutineStep<I,​O>>, org.obrel.core.FluentRelatable<CoroutineStep<I,​O>>, org.obrel.core.Relatable

    public class CodeExecution<I,​O>
    extends CoroutineStep<I,​O>
    An coroutine step that executes a code function.
    • Constructor Summary

      Constructors 
      Constructor Description
      CodeExecution​(java.util.function.BiFunction<I,​Continuation<?>,​O> code)
      Creates a new instance from a binary function that accepts the continuation of the execution and the input value.
      CodeExecution​(java.util.function.Function<I,​O> code)
      Creates a new instance from a simple function that processes the input into the output value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <I,​O>
      CodeExecution<I,​O>
      apply​(java.util.function.BiFunction<I,​Continuation<?>,​O> code)
      Applies a BiFunction to the step input and the continuation of the current execution and return the processed output.
      static <I,​O>
      CodeExecution<I,​O>
      apply​(java.util.function.Function<I,​O> code)
      Applies a Function to the step input and return the processed output.
      static <T> CodeExecution<T,​T> consume​(java.util.function.BiConsumer<T,​Continuation<?>> code)
      Consumes the input value with a Consumer and returns the input value.
      static <T> CodeExecution<T,​T> consume​(java.util.function.Consumer<T> code)
      Consumes the input value with a Consumer and returns the input value.
      protected O execute​(I input, Continuation<?> continuation)
      This method must be implemented by subclasses to provide the actual functionality of this step.
      static <I,​O>
      CodeExecution<I,​O>
      getParameter​(org.obrel.core.RelationType<O> rSource)
      Queries a parameter relation from the Continuation and returns it as the result of the execution.
      static <I,​O>
      CodeExecution<I,​O>
      getScopeParameter​(org.obrel.core.RelationType<O> rSource)
      Queries a parameter relation from the CoroutineScope and returns it as the result of the execution.
      static <I,​O>
      CodeExecution<I,​O>
      map​(java.util.function.Function<I,​O> mapper)
      A semantic alternative for apply(Function).
      static <T> CodeExecution<T,​java.lang.Void> run​(java.lang.Runnable code)
      Executes a Runnable, ignoring any input value and returning no result.
      static <T> CodeExecution<T,​T> run​(java.util.function.Consumer<Continuation<?>> code)
      Executes a Runnable and then returns the input value.
      static <T> CodeExecution<T,​T> setParameter​(org.obrel.core.RelationType<T> rTarget)
      Sets the input value into a parameter of the Continuation and then returns it.
      static <T> CodeExecution<T,​T> setScopeParameter​(org.obrel.core.RelationType<T> rTarget)
      Sets the input value into a parameter of the CoroutineScope and then returns it.
      static <I,​O>
      CodeExecution<I,​O>
      supply​(java.util.function.Function<Continuation<?>,​O> code)
      Provides a value from a Supplier as the result, ignoring any input value.
      static <I,​O>
      CodeExecution<I,​O>
      supply​(java.util.function.Supplier<O> code)
      Provides a value from a Supplier as the result, ignoring any input value.
      • Methods inherited from class org.obrel.core.RelatedObject

        deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface de.esoco.lib.property.Fluent

        _with
      • Methods inherited from interface org.obrel.core.FluentRelatable

        with, with, with
      • Methods inherited from interface org.obrel.core.Relatable

        deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
    • Constructor Detail

      • CodeExecution

        public CodeExecution​(java.util.function.BiFunction<I,​Continuation<?>,​O> code)
        Creates a new instance from a binary function that accepts the continuation of the execution and the input value.
        Parameters:
        code - A binary function containing the code to be executed
      • CodeExecution

        public CodeExecution​(java.util.function.Function<I,​O> code)
        Creates a new instance from a simple function that processes the input into the output value.
        Parameters:
        code - A function containing the code to be executed
    • Method Detail

      • apply

        public static <I,​O> CodeExecution<I,​O> apply​(java.util.function.Function<I,​O> code)
        Applies a Function to the step input and return the processed output.
        Parameters:
        code - The function to be executed
        Returns:
        A new instance of this class
      • apply

        public static <I,​O> CodeExecution<I,​O> apply​(java.util.function.BiFunction<I,​Continuation<?>,​O> code)
        Applies a BiFunction to the step input and the continuation of the current execution and return the processed output.
        Parameters:
        code - The binary function to be executed
        Returns:
        A new instance of this class
      • consume

        public static <T> CodeExecution<T,​T> consume​(java.util.function.Consumer<T> code)
        Consumes the input value with a Consumer and returns the input value.
        Parameters:
        code - The consumer to be executed
        Returns:
        A new instance of this class
      • consume

        public static <T> CodeExecution<T,​T> consume​(java.util.function.BiConsumer<T,​Continuation<?>> code)
        Consumes the input value with a Consumer and returns the input value.
        Parameters:
        code - The consumer to be executed
        Returns:
        A new instance of this class
      • getParameter

        public static <I,​O> CodeExecution<I,​O> getParameter​(org.obrel.core.RelationType<O> rSource)
        Queries a parameter relation from the Continuation and returns it as the result of the execution.
        Parameters:
        rSource - The relation type of the parameter
        Returns:
        A new instance of this class
      • getScopeParameter

        public static <I,​O> CodeExecution<I,​O> getScopeParameter​(org.obrel.core.RelationType<O> rSource)
        Queries a parameter relation from the CoroutineScope and returns it as the result of the execution.
        Parameters:
        rSource - The relation type of the parameter
        Returns:
        A new instance of this class
      • map

        public static <I,​O> CodeExecution<I,​O> map​(java.util.function.Function<I,​O> mapper)
        A semantic alternative for apply(Function).
        Parameters:
        mapper - The mapping function
        Returns:
        A new instance of this class
      • run

        public static <T> CodeExecution<T,​java.lang.Void> run​(java.lang.Runnable code)
        Executes a Runnable, ignoring any input value and returning no result.
        Parameters:
        code - The runnable to be executed
        Returns:
        A new instance of this class
      • run

        public static <T> CodeExecution<T,​T> run​(java.util.function.Consumer<Continuation<?>> code)
        Executes a Runnable and then returns the input value.
        Parameters:
        code - The runnable to be executed
        Returns:
        A new instance of this class
      • setParameter

        public static <T> CodeExecution<T,​T> setParameter​(org.obrel.core.RelationType<T> rTarget)
        Sets the input value into a parameter of the Continuation and then returns it.
        Parameters:
        rTarget - The type of the relation to set the parameter in
        Returns:
        A new instance of this class
      • setScopeParameter

        public static <T> CodeExecution<T,​T> setScopeParameter​(org.obrel.core.RelationType<T> rTarget)
        Sets the input value into a parameter of the CoroutineScope and then returns it.
        Parameters:
        rTarget - The type of the relation to set the parameter in
        Returns:
        A new instance of this class
      • supply

        public static <I,​O> CodeExecution<I,​O> supply​(java.util.function.Supplier<O> code)
        Provides a value from a Supplier as the result, ignoring any input value.
        Parameters:
        code - The supplier to be executed
        Returns:
        A new instance of this class
      • supply

        public static <I,​O> CodeExecution<I,​O> supply​(java.util.function.Function<Continuation<?>,​O> code)
        Provides a value from a Supplier as the result, ignoring any input value.
        Parameters:
        code - The supplier to be executed
        Returns:
        A new instance of this class
      • execute

        protected O execute​(I input,
                            Continuation<?> continuation)
        This method must be implemented by subclasses to provide the actual functionality of this step.
        Specified by:
        execute in class CoroutineStep<I,​O>
        Parameters:
        input - The input value
        continuation - The continuation of the execution
        Returns:
        The result of the execution