public abstract class ConstraintObject extends Object
Java class represents
the constraint as used by an entity to be constrained; A constraint can be an enumerated list,
a range, or a format.
A constraint has a constraint type (enumerated list, range, format) and a compatible subtype corresponding to the type of the value to be constrained (boolean, integer, decimal, string, date, duration).
A constraint is represented by a String. See the createConstraintFromString(String) method
for more information about the String format.
| Modifier and Type | Class and Description |
|---|---|
static class |
ConstraintObject.MetaChar
This
enumeration lists the meta characters: escape, multiple, single, slash. |
| Modifier and Type | Field and Description |
|---|---|
static boolean[][] |
compatibilityTable
The compatibility table: constrained object type/constraint object type.
|
static int |
NO_SUBTYPE
The no subtype.
|
static String |
separator
The separator character as a string
|
static char |
separatorChar
The separator character: '/'
|
static String |
STRING_TYPE_BIG_INTEGER |
static String |
STRING_TYPE_BOOLEAN |
static String |
STRING_TYPE_DATE |
static String |
STRING_TYPE_DECIMAL |
static String |
STRING_TYPE_ENUMERATED_LIST |
static String |
STRING_TYPE_FORMAT |
static String |
STRING_TYPE_INTEGER |
static String |
STRING_TYPE_LONG |
static String |
STRING_TYPE_RANGE |
static String |
STRING_TYPE_STRING |
static int |
TYPE_BIG_INTEGER
the big integer subtype.
|
static int |
TYPE_BOOLEAN
the date subtype.
|
static int |
TYPE_DATE
the date subtype.
|
static int |
TYPE_DECIMAL
the decimal subtype.
|
static int |
TYPE_ENUMERATED_LIST
The enumerated list type.
|
static int |
TYPE_FORMAT
The format constraint type.
|
static int |
TYPE_INTEGER
the integer subtype.
|
static int |
TYPE_LONG
the long subtype.
|
static int |
TYPE_RANGE
The range constraint type.
|
static int |
TYPE_STRING
the string subtype.
|
| Constructor and Description |
|---|
ConstraintObject() |
| Modifier and Type | Method and Description |
|---|---|
static ConstraintObject |
createConstraintFromString(String str)
Builds a constraint from a string representation.
|
static String |
escapeMetaChar(String value)
This method adds an
escape char before each metachar from the input string. |
static int[] |
getAllowedConstraintTypes(int valueType)
According to the value type (NUMBER, STRING, DATE, BOOLEAN, DURATION)
to be constrained returns the allowed constraint types.
|
int |
getConstraintSubType()
Gets the subtype of the constraint that depends on the type of the constrained value.
|
abstract int |
getConstraintType()
Returns the constraint type of this constraint.
|
abstract String |
getInitializationString()
Returns the initialization string of the constraint.
|
abstract boolean |
isBigIntegerConstraint()
Returns big integer status of the constraint.
|
abstract boolean |
isBooleanConstraint()
Returns boolean status of the constraint.
|
abstract boolean |
isDateConstraint()
Returns date status of the constraint.
|
abstract boolean |
isDecimalConstraint()
Returns decimal status of the constraint.
|
abstract boolean |
isIntegerConstraint()
Returns integer status of the constraint.
|
abstract boolean |
isLongConstraint()
Returns long status of the constraint.
|
abstract boolean |
isStringConstraint()
Returns string status of the constraint.
|
abstract boolean |
isValidValue(Object value)
Tests if the value checks the constraint.
|
static int |
parseConstraintSubType(String subType) |
abstract String |
toString()
Returns
true the string that represents the constraint. |
static String |
unescapeMetaChar(String value) |
static String |
unescapeSeparatorChar(String s)
Unescapes the separator character.
|
public static final int TYPE_ENUMERATED_LIST
public static final String STRING_TYPE_ENUMERATED_LIST
public static final int TYPE_RANGE
public static final String STRING_TYPE_RANGE
public static final int TYPE_FORMAT
public static final String STRING_TYPE_FORMAT
public static final int TYPE_INTEGER
public static final String STRING_TYPE_INTEGER
public static final int TYPE_DECIMAL
public static final String STRING_TYPE_DECIMAL
public static final int TYPE_STRING
public static final String STRING_TYPE_STRING
public static final int TYPE_DATE
public static final String STRING_TYPE_DATE
public static final int TYPE_BOOLEAN
public static final String STRING_TYPE_BOOLEAN
public static final int NO_SUBTYPE
public static final int TYPE_LONG
public static final String STRING_TYPE_LONG
public static final int TYPE_BIG_INTEGER
public static final String STRING_TYPE_BIG_INTEGER
public static final boolean[][] compatibilityTable
public static final char separatorChar
public static final String separator
public static ConstraintObject createConstraintFromString(String str)
Three types of constraints can be defined: enumerated list constraint, range constraint, and format constraint.
Enumerated List Constraint
This type of constraint is decribed by a string that respects the following format:
/E/compatible_subtype/item1/.../itemN/
Where:
E indicates the enumerated list constraint typecompatible_subtype indicates the type of allowed values, and is one of:
I for IntegerL for LongBI for BigIntegerD for BigDecimalS for StringDA for Date (in this case, items must respect ISO 8601 format or
be expressed in milliseconds since January 1, 1970, 00:00:00 GMT)item1 to itemN are the N values of the listAn Object is compatible with an enumerated list constraint if and only if it's instance of the given compatible subtype and equals one of the given items.
Range Constraint
This type of constraint is decribed by a string that respects the following format:
/R/compatible_subtype/min/min_type/max/max_type/
Where:
R indicates the range constraint typecompatible_subtype indicates the type of allowed values, and is one of:
I for IntegerL for LongD for BigIntegerD for BigDecimalDA for Date (in this case, items must respect ISO 8601 format or
be expressed in milliseconds since January 1, 1970, 00:00:00 GMT)min and max are the bounds of the range.
If the string NULL is used as min or max value, it means the related
bound is not taken into account.
min_type and max_type are interger flags indicating the type
of the related bound, and is one of TYPE_INCLUSIVE (0)
or TYPE_EXCLUSIVE (1).
An Object is compatible with an range constraint if and only if it's instance of the given compatible subtype and belongs to the range defined by min and max bounds, and the related bound types.
Format Constraint
This type of constraint is decribed by a string that respects the following format:
/F/pattern/
Where:
F indicates the format constraint typepattern is the pattern that matches the allowed values.
Inside the pattern, each character '*' means any string is valid between
the previous and the following character. The character '?' means
any character is valid at this character position.
An Object is compatible with a format constraint if and only if it's a String matching the given pattern.
public abstract boolean isValidValue(Object value)
true if the value checks the constraint,
false otherwisepublic abstract int getConstraintType()
TYPE_ENUMERATED_LIST,
TYPE_RANGE,
TYPE_FORMATpublic int getConstraintSubType()
TYPE_BOOLEAN,
TYPE_INTEGER,
TYPE_LONG,
TYPE_BIG_INTEGER,
TYPE_DECIMAL,
TYPE_STRING,
TYPE_DATE,
NO_SUBTYPEpublic abstract boolean isBooleanConstraint()
true if the constrained value is boolean, false otherwisepublic abstract boolean isIntegerConstraint()
true if the constrained value is integer, false otherwisepublic abstract boolean isLongConstraint()
true if the constrained value is long, false otherwisepublic abstract boolean isDecimalConstraint()
true if the constrained value is big decimal, false otherwisepublic abstract boolean isBigIntegerConstraint()
true if the constrained value is a BigInteger, false otherwisepublic abstract boolean isDateConstraint()
true if the constrained value is date, false otherwisepublic abstract boolean isStringConstraint()
true if the constrained value is string, false otherwisepublic abstract String getInitializationString()
public abstract String toString()
true the string that represents the constraint.public static int[] getAllowedConstraintTypes(int valueType)
TYPE_ENUMERATED_LIST,
TYPE_RANGE,
TYPE_FORMATpublic static int parseConstraintSubType(String subType)
public static String escapeMetaChar(String value)
escape char before each metachar from the input string.value - The string to scanmetachar escaped