Class Constraint
- All Implemented Interfaces:
Pattern<Object>,Serializable,Cloneable
A pattern of this class can either succeed once or fail, determined by external information that does not depend on a given specific target.
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Constraintall(Constraint... cs) Combines several constraints conjunctively.static Constraintall(List<? extends Constraint> cs) Combines several constraints conjunctively.booleanAttempts to match this pattern against a given object.static Constraintof(boolean constant) Returns a constraint that always succeeds or always fails.static Constraintof(BooleanSupplier supplier) Returns a constraint that delegates to a given supplier.static Constraintsome(Constraint... cs) Combines several constraints disjunctively.static Constraintsome(List<? extends Constraint> cs) Combines several constraints disjunctively.protected abstract booleantest()Checks whether this pattern should succeed or fail.Methods inherited from class eu.bandm.tools.paisley.Atomic
binds, fork, isDeterministic, matchAgain, of, preserves, preservesMethods inherited from class eu.bandm.tools.paisley.AbstractPattern
clone, doclone
-
Constructor Details
-
Constraint
public Constraint()Creates a new instance.
-
-
Method Details
-
match
Attempts to match this pattern against a given object.If the class of this pattern imposes a specific order on matches, the first one is chosen.
The
nulltarget is generally allowed.This implementation ignores
targetand delegates totest().- Parameters:
target- the object to match against, which is not examined- Returns:
trueif the matching is successful,falseif it fails. WhichVariables are bound by a successful or failed match depends.- See Also:
-
test
protected abstract boolean test()Checks whether this pattern should succeed or fail.- Returns:
trueif this pattern should succeed once;falseotherwise
-
of
Returns a constraint that always succeeds or always fails.- Parameters:
constant- whether the constraint should succeed- Returns:
- a constraint that matches a given target if and only if
constantistrue
-
of
Returns a constraint that delegates to a given supplier.- Parameters:
supplier- the supplier to delegate to- Returns:
- a constraint that matches a given target if and only if
supplierreturnstrue - Throws:
NullPointerException- ifsupplieris null
-
all
Combines several constraints conjunctively.The combination behaves like the operator
&&; if any constraint returnsfalse, the subsequent ones are not evaluated at all.- Parameters:
cs- the constraints to combine- Returns:
- a constraint that matches all given constraints in order, and succeeds if they all do
- Throws:
NullPointerException- ifcsis or contains null
-
all
Combines several constraints conjunctively.The combination behaves like the operator
&&; if any constraint returnsfalse, the subsequent ones are not evaluated at all.The given list of constraints is copied by this method; subsequent changes to the given list have no effect on the returned constraint.
- Parameters:
cs- the constraints to combine- Returns:
- a constraint that matches all given constraints in order, and succeeds if they all do
- Throws:
NullPointerException- ifcsis or contains null
-
some
Combines several constraints disjunctively.The combination behaves like the operator
||; if any constraint returnstrue, the subsequent ones are not evaluated at all.- Parameters:
cs- the constraints to combine- Returns:
- a constraint that matches all given constraints in order, and succeeds if any of them does
- Throws:
NullPointerException- ifcsis or contains null
-
some
Combines several constraints disjunctively.The combination behaves like the operator
||; if any constraint returnstrue, the subsequent ones are not evaluated at all.The given list of constraints is copied by this method; subsequent changes to the given list have no effect on the returned constraint.
- Parameters:
cs- the constraints to combine- Returns:
- a constraint that matches all given constraints in order, and succeeds if any of them does
- Throws:
NullPointerException- ifcsis or contains null
-