Interface Coupler

All Superinterfaces:
org.refcodes.mixin.ValidAccessor
All Known Implementing Classes:
Scope

public interface Coupler extends org.refcodes.mixin.ValidAccessor
A Coupler connects (logically) chained elements (linked lists or tree alike structures) together as of conditions being implemented by implementations of this class and determines whether a given element in the chain is valid or not as of the conditions implemented by the Coupler.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Definition of a method with single argument of type Coupler.

    Nested classes/interfaces inherited from interface org.refcodes.mixin.ValidAccessor

    org.refcodes.mixin.ValidAccessor.ValidBuilder<B extends org.refcodes.mixin.ValidAccessor.ValidBuilder<B>>, org.refcodes.mixin.ValidAccessor.ValidMutator, org.refcodes.mixin.ValidAccessor.ValidProperty
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Determines whether this Coupler has a succeeding Coupler.
    default <RET> RET
    invokeNext(Function<Coupler,RET> aOperation)
    Invokes a given operation with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or null in case there is no succeeding Coupler.
    default <SUBJECT, RET>
    RET
    invokeNext(SUBJECT aSuccessor, Coupler.Operation<SUBJECT,Coupler,RET> aOperation)
    Invokes a given operation on the given successor with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or null in case there is no succeeding Coupler or the successor is null.
    default <RET> RET
    invokeNextOr(Function<Coupler,RET> aSuccessor, RET aDefaultValue)
    Invokes a given operation with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or the default value in case there is no succeeding Coupler.
    default <SUBJECT, RET>
    RET
    invokeNextOr(SUBJECT aSuccessor, Coupler.Operation<SUBJECT,Coupler,RET> aOperation, RET aDefaultValue)
    Invokes a given operation on the given successor with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or the default value in case there is no succeeding Coupler or the successor is null.
    boolean
    To be used by an element's method being invoked with a Coupler instance as argument belonging to a chain of elements.
    Retrieves the succeeding Coupler.
  • Method Details

    • hasNext

      boolean hasNext()
      Determines whether this Coupler has a succeeding Coupler. In case we have no following Coupler, we reached the end of the chain.
      Returns:
      True in case there is a succeeding Coupler, false in case we reached the end of the chain.
    • next

      Coupler next()
      Retrieves the succeeding Coupler. In case there is no succeeding Coupler, then an exception is thrown.
      Returns:
      The succeeding Coupler.
      Throws:
      IllegalStateException - thrown in case this is the last Coupler in the chain and there is no succeeding coupler.
    • invokeNext

      default <RET> RET invokeNext(Function<Coupler,RET> aOperation)
      Invokes a given operation with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or null in case there is no succeeding Coupler. The operation to be invoked must have a single argument being of type Coupler.
      Type Parameters:
      RET - The return type of the operation to be invoked.
      Parameters:
      aOperation - The succeeding operation (having a single argument of type Coupler) to be invoked.
      Returns:
      The according result of the invoked operation or null in case there is no succeeding Coupler.
    • invokeNextOr

      default <RET> RET invokeNextOr(Function<Coupler,RET> aSuccessor, RET aDefaultValue)
      Invokes a given operation with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or the default value in case there is no succeeding Coupler. The operation to be invoked must have a single argument being of type Coupler.
      Type Parameters:
      RET - The return type of the operation to be invoked.
      Parameters:
      aSuccessor - The succeeding operation (having a single argument of type Coupler) to be invoked.
      aDefaultValue - The default value to be returned in case there is no succeeding Coupler.
      Returns:
      The according result of the invoked operation or the given default value in case there is no succeeding Coupler.
    • invokeNext

      default <SUBJECT, RET> RET invokeNext(SUBJECT aSuccessor, Coupler.Operation<SUBJECT,Coupler,RET> aOperation)
      Invokes a given operation on the given successor with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or null in case there is no succeeding Coupler or the successor is null. The operation to be invoked must have a single argument being of type Coupler.
      Type Parameters:
      SUBJECT - The instance which is subject of operation.
      RET - The return type of the operation to be invoked.
      Parameters:
      aSuccessor - The instance on which to invoke the successor operation.
      aOperation - The successor operation (having a single argument of type Coupler) to be invoked.
      Returns:
      The according result of the invoked operation or the given default value in case there is no successor or succeeding Coupler.
    • invokeNextOr

      default <SUBJECT, RET> RET invokeNextOr(SUBJECT aSuccessor, Coupler.Operation<SUBJECT,Coupler,RET> aOperation, RET aDefaultValue)
      Invokes a given operation on the given successor with the succeeding Coupler (as of next()) as parameter in case there is a succeeding Coupler (as of hasNext()) and returns the operation's result or the default value in case there is no succeeding Coupler or the successor is null. The operation to be invoked must have a single argument being of type Coupler.
      Type Parameters:
      SUBJECT - The instance which is subject of operation.
      RET - The return type of the operation to be invoked.
      Parameters:
      aSuccessor - The instance on which to invoke the successor operation.
      aOperation - The successor operation (having a single argument of type Coupler) to be invoked.
      aDefaultValue - The default value to be returned in case there is no successor or succeeding Coupler.
      Returns:
      The according result of the invoked operation or the given default value in case there is no successor or succeeding Coupler.
    • isValid

      boolean isValid()
      To be used by an element's method being invoked with a Coupler instance as argument belonging to a chain of elements. Returns true in case the Coupler is in a valid state for the operation to be executed. In case isValid() returns false, then the operation should skip execution and pass the succeeding Coupler as of next() to its successor element in the chain.
      Specified by:
      isValid in interface org.refcodes.mixin.ValidAccessor