Class ConstraintObject

java.lang.Object
com.highdeal.udr.hci.ConstraintObject
Direct Known Subclasses:
EnumeratedListConstraint, FormatConstraint, RangeConstraint

public abstract class ConstraintObject extends Object
This 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.

  • Field Details

  • 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

      public static ConstraintObject createConstraintFromString(String str)
      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:

      • E indicates the enumerated list constraint type
      • compatible_subtype indicates the type of allowed values, and is one of:
        • I for Integer
        • L for Long
        • BI for BigInteger
        • D for BigDecimal
        • S for String
        • DA 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 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:

      • R indicates the range constraint type
      • compatible_subtype indicates the type of allowed values, and is one of:
        • I for Integer
        • L for Long
        • D for BigInteger
        • D for BigDecimal
        • DA 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 type
      • pattern 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.

      Parameters:
      str - the string representation of the constraint
      Returns:
      the ConstraintObject computed from the string or null if the string constraint is invalid
    • isValidValue

      public abstract boolean isValidValue(Object value)
      Tests if the value checks the constraint.
      Parameters:
      value - the value to check
      Returns:
      true if the value checks the constraint, false otherwise
    • 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:
      true if the constrained value is boolean, false otherwise
    • isIntegerConstraint

      public abstract boolean isIntegerConstraint()
      Returns integer status of the constraint.
      Returns:
      true if the constrained value is integer, false otherwise
    • isLongConstraint

      public abstract boolean isLongConstraint()
      Returns long status of the constraint.
      Returns:
      true if the constrained value is long, false otherwise
    • isDecimalConstraint

      public abstract boolean isDecimalConstraint()
      Returns decimal status of the constraint.
      Returns:
      true if the constrained value is big decimal, false otherwise
    • isBigIntegerConstraint

      public abstract boolean isBigIntegerConstraint()
      Returns big integer status of the constraint.
      Returns:
      true if the constrained value is a BigInteger, false otherwise
    • isDateConstraint

      public abstract boolean isDateConstraint()
      Returns date status of the constraint.
      Returns:
      true if the constrained value is date, false otherwise
    • isStringConstraint

      public abstract boolean isStringConstraint()
      Returns string status of the constraint.
      Returns:
      true if the constrained value is string, false otherwise
    • getInitializationString

      public abstract String getInitializationString()
      Returns the initialization string of the constraint.
      Returns:
      The initialization string of the constraint
    • toString

      public abstract String toString()
      Returns true the string that represents the constraint.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the constraint
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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

      public static int parseConstraintSubType(String subType)
      Returns the sub type as int
      Parameters:
      subType - the String representation of the subtype
      Returns:
      the int representation of the sub type if exists, NO_SUBTYPE otherwise
    • escapeMetaChar

      public static String escapeMetaChar(String value)
      This method adds an escape char before each metachar from the input string.
      Parameters:
      value - The string to scan
      Returns:
      The string with the metachar escaped
    • unescapeMetaChar

      public static String unescapeMetaChar(String value)
      This method removes the escape char before each metachar from the input string.
      Parameters:
      value - The string to scan
      Returns:
      The string with the metachar unescaped
    • isEscapedChar

      public static boolean isEscapedChar(String value, int index)
      This method tests if the character at position index in the string value is escaped .
      Parameters:
      value - The string which contains the character to check
      index - The index of the character to check
      Returns:
      true if the character is escaped
    • unescapeSeparatorChar

      public static String unescapeSeparatorChar(String s)
      Unescapes the separator character.
      Returns:
      The unescaped string