All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, SchemaProblemsSupplier, JavaCodeGenerator, Serializable, Cloneable

public class TextFieldDef extends FieldDef
A FieldDef for text values with optional length limits, blank check, regular expression and trimming.
See Also:
  • Constructor Details

    • TextFieldDef

      public TextFieldDef()
      Creates a field of type FieldType.STRING.
    • TextFieldDef

      public TextFieldDef(String name, FieldType type)
      Creates a field with the given name and type; types other than STRING and CHAR are rejected.
  • Method Details

    • getSchemaProblems

      public void getSchemaProblems(List<SchemaProblem> problems, boolean includeChildren)
      Description copied from interface: SchemaProblemsSupplier
      Adds this element's problems to the list, plus those of its children when includeChildren is true; the default adds none.
      Specified by:
      getSchemaProblems in interface SchemaProblemsSupplier
      Overrides:
      getSchemaProblems in class FieldDef
    • clone

      public TextFieldDef clone()
      Overrides:
      clone in class FieldDef
    • generateJavaCode

      public void generateJavaCode(JavaCodeBuilder code)
      Description copied from interface: JavaCodeGenerator
      Appends Java source code representing this object to the given builder.
      Specified by:
      generateJavaCode in interface JavaCodeGenerator
      Overrides:
      generateJavaCode in class FieldDef
    • validateValueImpl

      protected void validateValueImpl(Object value, ValidationResult result) throws Throwable
      Description copied from class: FieldDef
      Applies the subclass-specific checks to a single (non-array) value, adding any errors to the result; called after the common type, array and allowed-value checks.
      Specified by:
      validateValueImpl in class FieldDef
      Throws:
      Throwable
    • mapValueImpl

      protected Object mapValueImpl(Object value) throws Throwable
      Description copied from class: FieldDef
      Converts a single (non-array) value to this field's type; subclasses override it to parse or adjust values first.
      Overrides:
      mapValueImpl in class FieldDef
      Throws:
      Throwable
    • setEntityDef

      protected TextFieldDef setEntityDef(EntityDef entityDef)
      Description copied from class: FieldDef
      Sets the parent entity; called by EntityDef when this field is added to it.
      Overrides:
      setEntityDef in class FieldDef
    • setName

      public TextFieldDef setName(String name)
      Overrides:
      setName in class FieldDef
    • setDisplayName

      public TextFieldDef setDisplayName(String displayName)
      Description copied from class: FieldDef
      Sets the user-friendly name for this field, used instead of the name in validation messages.
      Overrides:
      setDisplayName in class FieldDef
    • setDescription

      public TextFieldDef setDescription(String description)
      Overrides:
      setDescription in class FieldDef
    • setType

      public TextFieldDef setType(FieldType type)
      Description copied from class: FieldDef
      Sets the data type of this field; each subclass accepts only its own kind of type, such as numeric types for NumericFieldDef.
      Overrides:
      setType in class FieldDef
    • setRequired

      public TextFieldDef setRequired(boolean required)
      Description copied from class: FieldDef
      Indicates if this field must be present and not null to pass validation (defaults to false).
      Overrides:
      setRequired in class FieldDef
    • setMinimumElements

      public TextFieldDef setMinimumElements(Integer minimumElements)
      Description copied from class: FieldDef
      Sets the minimum number of array elements allowed; a non-null value makes this field an array. Negative values are set to zero (0).
      Overrides:
      setMinimumElements in class FieldDef
    • setMaximumElements

      public TextFieldDef setMaximumElements(Integer maximumElements)
      Description copied from class: FieldDef
      Sets the maximum number of array elements allowed; a non-null value makes this field an array. Negative values are set to the max integer and zero (0) means the array must be empty.
      Overrides:
      setMaximumElements in class FieldDef
    • setArray

      public TextFieldDef setArray(boolean array)
      Description copied from class: FieldDef
      Forces this field to be an array by setting the FieldDef.getMinimumElements() to zero (0) if both FieldDef.getMinimumElements() and FieldDef.getMaximumElements() are null, otherwise, does nothing.
      Overrides:
      setArray in class FieldDef
    • setStrictArrays

      public TextFieldDef setStrictArrays(boolean strictArrays)
      Description copied from class: FieldDef
      Indicates if values must match this field's array setting exactly (defaults to true); when false, a single value and a one-element array are interchangeable.
      Overrides:
      setStrictArrays in class FieldDef
    • setAllowedValues

      public TextFieldDef setAllowedValues(ValueMatch<?> allowedValues)
      Description copied from class: FieldDef
      Sets the optional set of values this field allows; they are enforced only when FieldDef.isLimitToAllowedValues() is true.
      Overrides:
      setAllowedValues in class FieldDef
    • setLimitToAllowedValues

      public TextFieldDef setLimitToAllowedValues(boolean limitToAllowedValues)
      Description copied from class: FieldDef
      Indicates if values must be one of FieldDef.getAllowedValues() to pass validation (defaults to false).
      Overrides:
      setLimitToAllowedValues in class FieldDef
    • setPrimaryKeyPosition

      public TextFieldDef setPrimaryKeyPosition(Integer primaryKeyPosition)
      Description copied from class: FieldDef
      Sets the zero-based position of this field in its entity's primary key or null if it is not part of the key.
      Overrides:
      setPrimaryKeyPosition in class FieldDef
    • setPrimaryKeyType

      public TextFieldDef setPrimaryKeyType(PrimaryKeyType primaryKeyType)
      Description copied from class: FieldDef
      Sets the strategy used to generate this primary key field's values; a primary key position must also be set.
      Overrides:
      setPrimaryKeyType in class FieldDef
    • getMinimumLength

      public Integer getMinimumLength()
      The optional least number of characters in values of this field. Negative values will be set to zero (0).
    • setMinimumLength

      public TextFieldDef setMinimumLength(Integer minimumLength)
      Sets the optional least number of characters in values of this field; negative values are set to zero (0).
    • getMaximumLength

      public Integer getMaximumLength()
      The optional most number of characters in values of this field. Negative values will be set to the max integer (2147483647). Zero (0) is allowed, it means the characters must always be zero in length.
    • setMaximumLength

      public TextFieldDef setMaximumLength(Integer maximumLength)
      Sets the optional most number of characters in values of this field; negative values are set to the max integer and zero (0) means values must be empty.
    • isAllowBlank

      public boolean isAllowBlank()
      Indicates if empty strings are allowed as values for this field.
    • setAllowBlank

      public TextFieldDef setAllowBlank(boolean allowBlank)
      Indicates if empty strings are allowed as values for this field (defaults to true).
    • getPattern

      public Pattern getPattern()
      The optional regular expression pattern to use when parsing incoming values during validation (not used during mapping).
    • setPattern

      public TextFieldDef setPattern(Pattern pattern)
      The optional regular expression pattern to use when parsing incoming values during validation (not used during mapping).
    • setPattern

      public TextFieldDef setPattern(String pattern)
      The optional regular expression pattern to use when parsing incoming values during validation (not used during mapping).
    • isTrim

      public boolean isTrim()
      Indicates if leading and trailing whitespace characters should be removed (default is false).
    • setTrim

      public TextFieldDef setTrim(boolean trim)
      Indicates if leading and trailing whitespace characters should be removed (default is false).
    • setPosition

      public TextFieldDef setPosition(Integer position)
      Description copied from class: FieldDef
      Sets the zero-based position of this field in the data or null to locate it by name; mapping renames the field found at this position to this field's name.
      Overrides:
      setPosition in class FieldDef
    • setDefaultValueExpression

      public TextFieldDef setDefaultValueExpression(Expression defaultValueExpression)
      Description copied from class: FieldDef
      The calculated value to set in the data if the field is null or missing.
      Overrides:
      setDefaultValueExpression in class FieldDef
    • setExample

      public TextFieldDef setExample(String example)
      Overrides:
      setExample in class FieldDef
    • setAttributes

      public TextFieldDef setAttributes(Attributes attributes)
      Description copied from class: FieldDef
      Sets the user-defined key-value pairs attached to this field (null is treated as empty).
      Overrides:
      setAttributes in class FieldDef
    • setTags

      public TextFieldDef setTags(Tags tags)
      Description copied from class: FieldDef
      Sets the labels used to organize, filter, and classify this field (null is treated as empty).
      Overrides:
      setTags in class FieldDef
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
      Overrides:
      toRecord in class FieldDef
    • fromRecord

      public TextFieldDef fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Overrides:
      fromRecord in class FieldDef
      Parameters:
      source -
      Returns:
      this instance.
    • toXmlElement

      public Element toXmlElement(Document document)
      Description copied from interface: XmlSerializable
      Returns an element, created with document, describing this object; the default implementation throws a DataException.
      Specified by:
      toXmlElement in interface XmlSerializable
      Overrides:
      toXmlElement in class FieldDef
    • fromXmlElement

      public TextFieldDef fromXmlElement(Element fieldDefElement)
      Specified by:
      fromXmlElement in interface XmlSerializable
      Overrides:
      fromXmlElement in class FieldDef
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class FieldDef
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class FieldDef