Class ConstraintObject
- Direct Known Subclasses:
EnumeratedListConstraint,FormatConstraint,RangeConstraint
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThisenumerationlists the meta characters: escape, multiple, single, slash. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean[][]The compatibility table: constrained object type/constraint object type.static final intThe no subtype.static final StringThe separator character as a stringstatic final charThe separator character: '/'static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intthe big integer subtype.static final intthe date subtype.static final intthe date subtype.static final intthe decimal subtype.static final intThe enumerated list type.static final intThe format constraint type.static final intthe integer subtype.static final intthe long subtype.static final intThe range constraint type.static final intthe string subtype. -
Constructor Summary
ConstructorsConstructorDescriptionConstraintObject(int constraintType) Builds a constraint object from a constraint type. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConstraintObjectBuilds a constraint from a string representation.booleanstatic StringescapeMetaChar(String value) This method adds anescape charbefore eachmetacharfrom 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.intGets the subtype of the constraint that depends on the type of the constrained value.intReturns the constraint type of this constraint.abstract StringReturns the initialization string of the constraint.inthashCode()abstract booleanReturns big integer status of the constraint.abstract booleanReturns boolean status of the constraint.abstract booleanReturns date status of the constraint.abstract booleanReturns decimal status of the constraint.static booleanisEscapedChar(String value, int index) This method tests if the character at position index in the string value is escaped .abstract booleanReturns integer status of the constraint.abstract booleanReturns long status of the constraint.abstract booleanReturns string status of the constraint.abstract booleanisValidValue(Object value) Tests if the value checks the constraint.static intparseConstraintSubType(String subType) Returns the sub type asintabstract StringtoString()Returnstruethe string that represents the constraint.static StringunescapeMetaChar(String value) This method removes theescape charbefore eachmetacharfrom the input string.static StringUnescapes the separator character.
-
Field Details
-
TYPE_ENUMERATED_LIST
public static final int TYPE_ENUMERATED_LISTThe enumerated list type.- See Also:
-
STRING_TYPE_ENUMERATED_LIST
- See Also:
-
TYPE_RANGE
public static final int TYPE_RANGEThe range constraint type.- See Also:
-
STRING_TYPE_RANGE
- See Also:
-
TYPE_FORMAT
public static final int TYPE_FORMATThe format constraint type.- See Also:
-
STRING_TYPE_FORMAT
- See Also:
-
TYPE_INTEGER
public static final int TYPE_INTEGERthe integer subtype.- See Also:
-
STRING_TYPE_INTEGER
- See Also:
-
TYPE_DECIMAL
public static final int TYPE_DECIMALthe decimal subtype.- See Also:
-
STRING_TYPE_DECIMAL
- See Also:
-
TYPE_STRING
public static final int TYPE_STRINGthe string subtype.- See Also:
-
STRING_TYPE_STRING
- See Also:
-
TYPE_DATE
public static final int TYPE_DATEthe date subtype.- See Also:
-
STRING_TYPE_DATE
- See Also:
-
TYPE_BOOLEAN
public static final int TYPE_BOOLEANthe date subtype.- See Also:
-
STRING_TYPE_BOOLEAN
- See Also:
-
NO_SUBTYPE
public static final int NO_SUBTYPEThe no subtype.- See Also:
-
TYPE_LONG
public static final int TYPE_LONGthe long subtype.- See Also:
-
STRING_TYPE_LONG
- See Also:
-
TYPE_BIG_INTEGER
public static final int TYPE_BIG_INTEGERthe big integer subtype.- See Also:
-
STRING_TYPE_BIG_INTEGER
- See Also:
-
compatibilityTable
public static final boolean[][] compatibilityTableThe compatibility table: constrained object type/constraint object type. -
separatorChar
public static final char separatorCharThe separator character: '/'- See Also:
-
separator
The separator character as a string
-
-
Constructor Details
-
ConstraintObject
public ConstraintObject(int constraintType) Builds a constraint object from a constraint type.- Parameters:
constraintType- the constraint type- See Also:
-
-
Method Details
-
createConstraintFromString
Builds a constraint from a string representation.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:
Eindicates the enumerated list constraint typecompatible_subtypeindicates the type of allowed values, and is one of:IforIntegerLforLongBIforBigIntegerDforBigDecimalSforStringDAforDate(in this case, items must respect ISO 8601 format or be expressed in milliseconds since January 1, 1970, 00:00:00 GMT)
item1toitemNare the N values of the list
An 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:
Rindicates the range constraint typecompatible_subtypeindicates the type of allowed values, and is one of:IforIntegerLforLongDforBigIntegerDforBigDecimalDAforDate(in this case, items must respect ISO 8601 format or be expressed in milliseconds since January 1, 1970, 00:00:00 GMT)
minandmaxare the bounds of the range. If the stringNULLis used as min or max value, it means the related bound is not taken into account.min_typeandmax_typeare interger flags indicating the type of the related bound, and is one ofTYPE_INCLUSIVE(0) orTYPE_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:
Findicates the format constraint typepatternis 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.
- Parameters:
str- the string representation of the constraint- Returns:
- the
ConstraintObjectcomputed from the string or null if the string constraint is invalid
-
isValidValue
Tests if the value checks the constraint.- Parameters:
value- the value to check- Returns:
trueif the value checks the constraint,falseotherwise
-
getConstraintType
public int getConstraintType()Returns the constraint type of this constraint.- Returns:
- The constraint type
- See Also:
-
getConstraintSubType
public int getConstraintSubType()Gets the subtype of the constraint that depends on the type of the constrained value.- Returns:
- The subtype of the constraint
- See Also:
-
isBooleanConstraint
public abstract boolean isBooleanConstraint()Returns boolean status of the constraint.- Returns:
trueif the constrained value is boolean,falseotherwise
-
isIntegerConstraint
public abstract boolean isIntegerConstraint()Returns integer status of the constraint.- Returns:
trueif the constrained value is integer,falseotherwise
-
isLongConstraint
public abstract boolean isLongConstraint()Returns long status of the constraint.- Returns:
trueif the constrained value is long,falseotherwise
-
isDecimalConstraint
public abstract boolean isDecimalConstraint()Returns decimal status of the constraint.- Returns:
trueif the constrained value is big decimal,falseotherwise
-
isBigIntegerConstraint
public abstract boolean isBigIntegerConstraint()Returns big integer status of the constraint.- Returns:
trueif the constrained value is a BigInteger,falseotherwise
-
isDateConstraint
public abstract boolean isDateConstraint()Returns date status of the constraint.- Returns:
trueif the constrained value is date,falseotherwise
-
isStringConstraint
public abstract boolean isStringConstraint()Returns string status of the constraint.- Returns:
trueif the constrained value is string,falseotherwise
-
getInitializationString
Returns the initialization string of the constraint.- Returns:
- The initialization string of the constraint
-
toString
Returnstruethe string that represents the constraint. -
equals
-
hashCode
public int hashCode() -
getAllowedConstraintTypes
public static int[] getAllowedConstraintTypes(int valueType) According to the value type (NUMBER, STRING, DATE, BOOLEAN) to be constrained returns the allowed constraint types.- Returns:
- The allowed constraint types can be
- See Also:
-
parseConstraintSubType
Returns the sub type asint- Parameters:
subType- theStringrepresentation of the subtype- Returns:
- the
intrepresentation of the sub type if exists,NO_SUBTYPEotherwise
-
escapeMetaChar
This method adds anescape charbefore eachmetacharfrom the input string.- Parameters:
value- The string to scan- Returns:
- The string with the
metacharescaped
-
unescapeMetaChar
This method removes theescape charbefore eachmetacharfrom the input string.- Parameters:
value- The string to scan- Returns:
- The string with the
metacharunescaped
-
isEscapedChar
This method tests if the character at position index in the string value is escaped .- Parameters:
value- The string which contains the character to checkindex- The index of the character to check- Returns:
- true if the character is escaped
-
unescapeSeparatorChar
Unescapes the separator character.- Returns:
- The unescaped string
-