Package com.maybeitssquid.safeascii
Class Chainable
java.lang.Object
com.maybeitssquid.safeascii.Chainable
- All Implemented Interfaces:
IntFunction<CharSequence>
- Direct Known Subclasses:
Cache,Categorize,Decompose
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
FieldsModifier and TypeFieldDescriptionstatic final intThe upper bound for ASCII codepoints (exclusive).protected final IntFunction<CharSequence> The next function in the processing chain. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedChainable(IntFunction<CharSequence> delegate) Creates a new Chainable instance with the specified delegate. -
Method Summary
Modifier and TypeMethodDescriptionapply(int value) Applies this processing step and then the delegate to the input value.protected final CharSequencedelegate(int codepoint) Invokes the delegate function on the given codepoint.protected abstract CharSequenceprocess(int codepoint) Processes a single codepoint according to the specific logic of this class.
-
Field Details
-
ASCII
public static final int ASCIIThe upper bound for ASCII codepoints (exclusive).- See Also:
-
delegate
The next function in the processing chain.
-
-
Constructor Details
-
Chainable
Creates a new Chainable instance with the specified delegate.- Parameters:
delegate- the next function to apply in the chain
-
-
Method Details
-
process
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
Invokes the delegate function on the given codepoint.- Parameters:
codepoint- the codepoint to pass to the delegate- Returns:
- the result from the delegate
-
apply
Applies this processing step and then the delegate to the input value.This implementation first transforms the input
valueusingprocess(int). The resultingCharSequenceis then decomposed into codepoints, each of which is passed to thedelegate(int)method. The results are concatenated and returned.- Specified by:
applyin interfaceIntFunction<CharSequence>- Parameters:
value- the input codepoint- Returns:
- the final processed character sequence
-