public abstract class ConstraintObject
extends java.lang.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).
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 java.lang.String |
separator
The separator character as a string
|
static char |
separatorChar
The separator character: '/'
|
static java.lang.String |
STRING_TYPE_BIG_INTEGER |
static java.lang.String |
STRING_TYPE_BOOLEAN |
static java.lang.String |
STRING_TYPE_DATE |
static java.lang.String |
STRING_TYPE_DECIMAL |
static java.lang.String |
STRING_TYPE_ENUMERATED_LIST |
static java.lang.String |
STRING_TYPE_FORMAT |
static java.lang.String |
STRING_TYPE_INTEGER |
static java.lang.String |
STRING_TYPE_LONG |
static java.lang.String |
STRING_TYPE_RANGE |
static java.lang.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(int constraintType)
Builds a constraint object from a constraint type.
|
| Modifier and Type | Method and Description |
|---|---|
static ConstraintObject |
createConstraintFromString(java.lang.String str)
Builds a constraint from a string representation.
|
boolean |
equals(java.lang.Object obj) |
static java.lang.String |
escapeMetaChar(java.lang.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)
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.
|
int |
getConstraintType()
Returns the constraint type of this constraint.
|
abstract java.lang.String |
getInitializationString()
Returns the initialization string of the constraint.
|
int |
hashCode() |
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.
|
static boolean |
isEscapedChar(java.lang.String value,
int index)
This method tests if the character at position index in the string value is escaped .
|
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(java.lang.Object value)
Tests if the value checks the constraint.
|
static int |
parseConstraintSubType(java.lang.String subType)
Returns the sub type as
int |
abstract java.lang.String |
toString()
Returns
true the string that represents the constraint. |
static java.lang.String |
unescapeMetaChar(java.lang.String value)
This method removes the
escape char before each metachar from the input string. |
static java.lang.String |
unescapeSeparatorChar(java.lang.String s)
Unescapes the separator character.
|
public static final int TYPE_ENUMERATED_LIST
public static final java.lang.String STRING_TYPE_ENUMERATED_LIST
public static final int TYPE_RANGE
public static final java.lang.String STRING_TYPE_RANGE
public static final int TYPE_FORMAT
public static final java.lang.String STRING_TYPE_FORMAT
public static final int TYPE_INTEGER
public static final java.lang.String STRING_TYPE_INTEGER
public static final int TYPE_DECIMAL
public static final java.lang.String STRING_TYPE_DECIMAL
public static final int TYPE_STRING
public static final java.lang.String STRING_TYPE_STRING
public static final int TYPE_DATE
public static final java.lang.String STRING_TYPE_DATE
public static final int TYPE_BOOLEAN
public static final java.lang.String STRING_TYPE_BOOLEAN
public static final int NO_SUBTYPE
public static final int TYPE_LONG
public static final java.lang.String STRING_TYPE_LONG
public static final int TYPE_BIG_INTEGER
public static final java.lang.String STRING_TYPE_BIG_INTEGER
public static final boolean[][] compatibilityTable
public static final char separatorChar
public static final java.lang.String separator
public ConstraintObject(int constraintType)
constraintType - the constraint typeTYPE_ENUMERATED_LIST,
TYPE_FORMAT,
TYPE_RANGEpublic static ConstraintObject createConstraintFromString(java.lang.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 described 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 described 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.
str - the string representation of the constraintConstraintObject computed from the string or null if the string constraint is invalidpublic abstract boolean isValidValue(java.lang.Object value)
value - the value to checktrue if the value checks the constraint,
false otherwisepublic 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 java.lang.String getInitializationString()
public abstract java.lang.String toString()
true the string that represents the constraint.toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic static int[] getAllowedConstraintTypes(int valueType)
TYPE_ENUMERATED_LIST,
TYPE_RANGE,
TYPE_FORMATpublic static int parseConstraintSubType(java.lang.String subType)
intsubType - the String representation of the subtypeint representation of the sub type if exists, NO_SUBTYPE otherwisepublic static java.lang.String escapeMetaChar(java.lang.String value)
escape char before each metachar from the input string.value - The string to scanmetachar escapedpublic static java.lang.String unescapeMetaChar(java.lang.String value)
escape char before each metachar from the input string.value - The string to scanmetachar unescapedpublic static boolean isEscapedChar(java.lang.String value,
int index)
value - The string which contains the character to checkindex - The index of the character to checkpublic static java.lang.String unescapeSeparatorChar(java.lang.String s)