Package org.spongepowered.asm.util
Class ConstraintParser.Constraint
java.lang.Object
org.spongepowered.asm.util.ConstraintParser.Constraint
- Enclosing class:
- ConstraintParser
public static class ConstraintParser.Constraint
extends java.lang.Object
A constraint. Constraints are parsed from string expressions which are
always of the form:
<token>(<constraint>)
token is normalised to uppercase and must be provided by the environment.
constraint is an integer range specified in one of the following formats:
()
- The token value must be present in the environment, but can have any value
(1234)
- The token value must be exactly equal to
1234 (1234+) (1234-) (1234>)
- All of these variants mean the same thing, and can be read as "1234 or greater"
(<1234)
- Less than 123
(<=1234)
- Less than or equal to 1234 (equivalent to
1234<) (>1234)
- Greater than 1234
(>=1234)
- Greater than or equal to 1234 (equivalent to
1234 >) (1234-1300)
- Value must be between 1234 and 1300 (inclusive)
(1234+10)
- Value must be between 1234 and 1234+10 (1234-1244 inclusive)
All whitespace is ignored in constraint declarations. The following declarations are equivalent:
token(123-456) token ( 123 - 456 )
Multiple constraints should be separated by semicolon (;)
and are conjoined by an implied logical AND operator. That
is: all constraints must pass for the constraint to be considered valid.
-
Field Summary
Fields Modifier and Type Field Description static ConstraintParser.ConstraintNONE -
Method Summary
Modifier and Type Method Description voidcheck(ITokenProvider environment)Checks the current token against the environment and throws aConstraintViolationExceptionif the constraint is invalidintgetMax()intgetMin()java.lang.StringgetRangeHumanReadable()Gets a human-readable description of the range expressed by this constraintjava.lang.StringgetToken()java.lang.StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
NONE
-
-
Method Details
-
getToken
public java.lang.String getToken() -
getMin
public int getMin() -
getMax
public int getMax() -
check
Checks the current token against the environment and throws aConstraintViolationExceptionif the constraint is invalid- Parameters:
environment- environment to fetch constraints- Throws:
ConstraintViolationException- if constraint is not valid
-
getRangeHumanReadable
public java.lang.String getRangeHumanReadable()Gets a human-readable description of the range expressed by this constraint -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-