Class Chainable

java.lang.Object
com.maybeitssquid.safeascii.Chainable
All Implemented Interfaces:
IntFunction<CharSequence>
Direct Known Subclasses:
Cache, Categorize, Decompose

public abstract class Chainable extends Object implements IntFunction<CharSequence>
Abstract base class for creating a chain of character processing functions.

This class implements IntFunction to transform Unicode codepoints into CharSequences. Implementations can define specific transformation logic in the process(int) method. The default apply(int) implementation facilitates chaining by feeding the output of the processing step into a delegate function.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The upper bound for ASCII codepoints (exclusive).
    protected final IntFunction<CharSequence>
    The next function in the processing chain.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new Chainable instance with the specified delegate.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(int value)
    Applies this processing step and then the delegate to the input value.
    protected final CharSequence
    delegate(int codepoint)
    Invokes the delegate function on the given codepoint.
    protected abstract CharSequence
    process(int codepoint)
    Processes a single codepoint according to the specific logic of this class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ASCII

      public static final int ASCII
      The upper bound for ASCII codepoints (exclusive).
      See Also:
    • delegate

      protected final IntFunction<CharSequence> delegate
      The next function in the processing chain.
  • Constructor Details

    • Chainable

      protected Chainable(IntFunction<CharSequence> delegate)
      Creates a new Chainable instance with the specified delegate.
      Parameters:
      delegate - the next function to apply in the chain
  • Method Details

    • process

      protected abstract CharSequence process(int codepoint)
      Processes a single codepoint according to the specific logic of this class.
      Parameters:
      codepoint - the Unicode codepoint to process
      Returns:
      the transformed character sequence
    • delegate

      protected final CharSequence delegate(int codepoint)
      Invokes the delegate function on the given codepoint.
      Parameters:
      codepoint - the codepoint to pass to the delegate
      Returns:
      the result from the delegate
    • apply

      public CharSequence apply(int value)
      Applies this processing step and then the delegate to the input value.

      This implementation first transforms the input value using process(int). The resulting CharSequence is then decomposed into codepoints, each of which is passed to the delegate(int) method. The results are concatenated and returned.

      Specified by:
      apply in interface IntFunction<CharSequence>
      Parameters:
      value - the input codepoint
      Returns:
      the final processed character sequence