AbstractFormatValidator (Apache Commons Validator 1.11.0 API)
Description: declaration: package: org.apache.commons.validator.routines, class: AbstractFormatValidator

# Class AbstractFormatValidator

java.lang.Object
org.apache.commons.validator.routines.AbstractFormatValidator

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `AbstractCalendarValidator, AbstractNumberValidator`

public abstract class AbstractFormatValidator extends Object implements Serializable
Abstracts class for Format based Validation.

This is a base class for building Date and Number Validators using format parsing.

Since:
  1.3.0
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractFormatValidator(boolean strict)`
  Constructs an instance with the specified strict setting.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `format(Object value)`
  Formats an object into a `String` using the default Locale.
  `String`
  `format(Object value, String pattern)`
  Formats an object into a `String` using the specified pattern.
  `String`
  `format(Object value, String pattern, Locale locale)`
  Formats an object using the specified pattern and/or `Locale`.
  `protected String`
  `format(Object value, Format formatter)`
  Formats a value with the specified `Format`.
  `String`
  `format(Object value, Locale locale)`
  Formats an object into a `String` using the specified Locale.
  `protected abstract Format`
  `getFormat(String pattern, Locale locale)`
  get a `Format` for the specified pattern and/or `Locale`.
  `boolean`
  `isStrict()`
  Tests whether validated values should adhere strictly to the `Format` used.
  `boolean`
  `isValid(String value)`
  Validates using the default `Locale`.
  `boolean`
  `isValid(String value, String pattern)`
  Validates using the specified pattern.
  `abstract boolean`
  `isValid(String value, String pattern, Locale locale)`
  Validates using the specified pattern and/or `Locale`.
  `boolean`
  `isValid(String value, Locale locale)`
  Validates using the specified `Locale`.
  `protected Object`
  `parse(String value, Format formatter)`
  Parses the value with the specified `Format`.
  `protected abstract Object`
  `processParsedValue(Object value, Format formatter)`
  Processes the parsed value, performing any further validation and type conversion required.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AbstractFormatValidator

    public AbstractFormatValidator(boolean strict)
    Constructs an instance with the specified strict setting.
    Parameters:
      `strict` - `true` if strict `Format` parsing should be used.

- ## Method Details

  - ### format

    public String format(Object value)
    Formats an object into a `String` using the default Locale.
    Parameters:
      `value` - The value validation is being performed on.
    Returns:
      The value formatted as a `String`.

  - ### format

    protected String format(Object value, Format formatter)
    Formats a value with the specified `Format`.
    Parameters:
      `value` - The value to be formatted.
      `formatter` - The Format to use.
    Returns:
      The formatted value.

  - ### format

    public String format(Object value, Locale locale)
    Formats an object into a `String` using the specified Locale.
    Parameters:
      `value` - The value validation is being performed on.
      `locale` - The locale to use for the Format.
    Returns:
      The value formatted as a `String`.

  - ### format

    public String format(Object value, String pattern)
    Formats an object into a `String` using the specified pattern.
    Parameters:
      `value` - The value validation is being performed on.
      `pattern` - The pattern used to format the value.
    Returns:
      The value formatted as a `String`.

  - ### format

    public String format(Object value, String pattern, Locale locale)
    Formats an object using the specified pattern and/or `Locale`.
    Parameters:
      `value` - The value validation is being performed on.
      `pattern` - The pattern used to format the value.
      `locale` - The locale to use for the Format.
    Returns:
      The value formatted as a `String`.

  - ### getFormat

    protected abstract Format getFormat(String pattern, Locale locale)
    get a `Format` for the specified pattern and/or `Locale`.
    Parameters:
      `pattern` - The pattern used to validate the value against or `null` to use the default for the `Locale`.
      `locale` - The locale to use for the currency format, system default if null.
    Returns:
      The `NumberFormat` to created.

  - ### isStrict

    public boolean isStrict()
    Tests whether validated values should adhere strictly to the `Format` used.

    Typically implementations of `Format` ignore invalid characters at the end of the value and just stop parsing. For example parsing a date value of `01/01/20x0` using a pattern of `dd/MM/yyyy` will result in a year of `20` if `strict` is set to `false`, whereas setting `strict` to `true` will cause this value to fail validation.

    Returns:
      `true` if strict `Format` parsing should be used.

  - ### isValid

    public boolean isValid(String value)
    Validates using the default `Locale`.
    Parameters:
      `value` - The value validation is being performed on.
    Returns:
      `true` if the value is valid.

  - ### isValid

    public boolean isValid(String value, Locale locale)
    Validates using the specified `Locale`.
    Parameters:
      `value` - The value validation is being performed on.
      `locale` - The locale to use for the Format, defaults to the default
    Returns:
      `true` if the value is valid.

  - ### isValid

    public boolean isValid(String value, String pattern)
    Validates using the specified pattern.
    Parameters:
      `value` - The value validation is being performed on.
      `pattern` - The pattern used to validate the value against.
    Returns:
      `true` if the value is valid.

  - ### isValid

    public abstract boolean isValid(String value, String pattern, Locale locale)
    Validates using the specified pattern and/or `Locale`.
    Parameters:
      `value` - The value validation is being performed on.
      `pattern` - The pattern used to format the value.
      `locale` - The locale to use for the Format, defaults to the default
    Returns:
      `true` if the value is valid.

  - ### parse

    protected Object parse(String value, Format formatter)
    Parses the value with the specified `Format`.
    Parameters:
      `value` - The value to be parsed.
      `formatter` - The Format to parse the value with.
    Returns:
      The parsed value if valid or `null` if invalid.

  - ### processParsedValue

    protected abstract Object processParsedValue(Object value, Format formatter)
    Processes the parsed value, performing any further validation and type conversion required.
    Parameters:
      `value` - The parsed object created.
      `formatter` - The Format used to parse the value with.
    Returns:
      The parsed value converted to the appropriate type if valid or `null` if invalid.