A - the target type of the containing patternB - the target type of the contained subpatternpublic abstract class CachedTransform<A,B> extends RestrictedTransform<A,B>
Transform has expensive computations shared between #isApplicable and apply(A), consider subclassing CachedTransform instead.
Subclasses must implement the tryApply(A) method.
| Modifier and Type | Class and Description |
|---|---|
static class |
CachedTransform.ApplyException
Indicates that a target can not be transformed.
|
| Modifier | Constructor and Description |
|---|---|
protected |
CachedTransform(Pattern<? super B> body)
Creates a new pattern.
|
| Modifier and Type | Method and Description |
|---|---|
B |
apply(A target)
Transforms a target to be matched into a target for the
subpattern.
|
void |
clear(boolean recursively)
Disposes of all internal state related to results and
nondeterminism.
|
boolean |
isDomain(A target) |
boolean |
match(A target)
Attempts to match this pattern against a given object.
|
protected abstract B |
tryApply(A target)
Checks whether a target can be transformed and transforms it.
|
compileIsDomain, compileIsRange, compileMatch, compileMatchAgain, isRange, matchAgaincompileApplybinds, clone, compileClear, compileCut, cut, getBody, isDeterministic, preserves, preserves, setBody, toStringall, all, all, all, all, and, andThen, andThen, any, any, aside, both, clear, compareTo, compile, compileClear, compileCut, compileIsDeterministic, compileSubPattern, compileThis, compileUpTo, cut, DEBUG, either, enPassant, eq, eqNull, equal, filter, flatten, forInstancesOf, limit, main, matchOnce, matchVar, narrow, neq, neqNull, newAll, noMatch, none, or, orElse, orElse, repeat, some, some, some, some, someMatch, startCompile, test, transform, uniquely, variable, variablepublic final boolean match(A target)
match in class RestrictedTransform<A,B>target - the object to match againsttrue if the matching is successful, false if it fails. Which Variables are bound by a
successful or failed match depends.Pattern.binds(Variable),
Pattern.preserves(Variable, boolean)public final boolean isDomain(A target)
This implementation calls tryApply(A) and caches the
result.
isDomain in class RestrictedTransform<A,B>protected abstract B tryApply(A target) throws CachedTransform.ApplyException
target - the object to be matched against.Unary.body to be matched against.CachedTransform.ApplyException - if the target can not be transformed.public B apply(A target)
This implementation returns the result cached by #isApplicable.
apply in class Transform<A,B>target - the target for this pattern to be matched against.Unary.body to be matched against.public void clear(boolean recursively)
PatternThe default implementation does nothing.
see also the complete user documentation .