Class Scope

java.lang.Object
org.refcodes.controlflow.Scope
All Implemented Interfaces:
Coupler, org.refcodes.mixin.IndexAccessor, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.OffsetAccessor, org.refcodes.mixin.ValidAccessor

public class Scope extends Object implements Coupler, org.refcodes.mixin.OffsetAccessor, org.refcodes.mixin.LengthAccessor, org.refcodes.mixin.IndexAccessor
A Scope implements the Coupler interface by determining the validity of an element in the chain by an index relative to a given offset and a given length. E.g. only elements (found at a given index in the chain of elements) within the range of the given length at a given offset are ought to be valid. A length of -1 indicates no length limits at all (e.g. a length of ∞).
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.refcodes.controlflow.Coupler

    Coupler.Operation<SUBJECT,PARAM extends Coupler,RET>

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

    org.refcodes.mixin.IndexAccessor.IndexBuilder<B extends org.refcodes.mixin.IndexAccessor.IndexBuilder<B>>, org.refcodes.mixin.IndexAccessor.IndexMutator, org.refcodes.mixin.IndexAccessor.IndexProperty

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

    org.refcodes.mixin.LengthAccessor.LengthBuilder<B extends org.refcodes.mixin.LengthAccessor.LengthBuilder<B>>, org.refcodes.mixin.LengthAccessor.LengthMutator, org.refcodes.mixin.LengthAccessor.LengthProperty

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

    org.refcodes.mixin.OffsetAccessor.OffsetBuilder<B extends org.refcodes.mixin.OffsetAccessor.OffsetBuilder<B>>, org.refcodes.mixin.OffsetAccessor.OffsetMutator, org.refcodes.mixin.OffsetAccessor.OffsetProperty

    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
  • Constructor Summary

    Constructors
    Constructor
    Description
    Scope(int aOffset)
    Creates a Scope with the given offset without any length limitation.
    Scope(int aOffset, int aLength)
    Creates a Scope for the given offset and with the given length.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    int
    int
    boolean
    Determines whether this Coupler has a succeeding Coupler.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.refcodes.controlflow.Coupler

    invokeNext, invokeNext, invokeNextOr, invokeNextOr
  • Constructor Details

    • Scope

      public Scope(int aOffset, int aLength)
      Creates a Scope for the given offset and with the given length.
      Parameters:
      aOffset - The offset for this scope.
      aLength - The length of this scope.
    • Scope

      public Scope(int aOffset)
      Creates a Scope with the given offset without any length limitation.
      Parameters:
      aOffset - The offset for this scope.
  • Method Details

    • hasNext

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

      public Coupler next()
      Retrieves the succeeding Coupler. In case there is no succeeding Coupler, then an exception is thrown.
      Specified by:
      next in interface Coupler
      Returns:
      The succeeding Coupler.
    • isValid

      public 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 Coupler.isValid() returns false, then the operation should skip execution and pass the succeeding Coupler as of Coupler.next() to its successor element in the chain.
      Specified by:
      isValid in interface Coupler
      Specified by:
      isValid in interface org.refcodes.mixin.ValidAccessor
    • getIndex

      public long getIndex()
      Specified by:
      getIndex in interface org.refcodes.mixin.IndexAccessor
    • getLength

      public int getLength()
      Specified by:
      getLength in interface org.refcodes.mixin.LengthAccessor
    • getOffset

      public int getOffset()
      Specified by:
      getOffset in interface org.refcodes.mixin.OffsetAccessor
    • toString

      public String toString()
      Overrides:
      toString in class Object