|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |
java.lang.Objectjava.lang.Enum<Validators>
org.netbeans.validation.api.builtin.Validators
public enum Validators
An enumeration of validator factories for commonly needed forms of validation such as non-empty strings, valid file names and URLs and so forth.
Also contains static factory methods for validators which do things like match regexp's and split strings and run another validator over the components.
Enum Constant Summary | |
---|---|
CHARACTER_SET_NAME
Factory for validators that require the passed string to be a valid character set name according to the specification of java.nio.Charset.forName(String) . |
|
EMAIL_ADDRESS
Factory for validators that validate standard internet email addresses (name + @ + valid hostname or ip). |
|
FILE_MUST_BE_DIRECTORY
Factory for validators that require that a string represent a file which is a directory, not a data file |
|
FILE_MUST_BE_FILE
Factory for validators that require that a string represent a file which is a file, not a directory |
|
FILE_MUST_EXIST
Factory for validators that require that a string represent a file which exists on disk |
|
FILE_MUST_NOT_EXIST
Validator which only passes non-existent file names |
|
HOST_NAME
Factory for validators that check the validity of an host name (may contain port info) |
|
HOST_NAME_OR_IP_ADDRESS
Factory for validators that check the validity of an IP address or host name (may contain port info) |
|
IP_ADDRESS
Factory for validators that check the validity of an IP address (may contain port info) |
|
JAVA_PACKAGE_NAME
Factory for validators that validate a java package name. |
|
MAY_NOT_START_WITH_DIGIT
Factory for validators that do not allow strings which start with a digit |
|
NO_WHITESPACE
Factory for validators that require that strings not contain whitespace |
|
REQUIRE_JAVA_IDENTIFIER
Factory for validators which require that strings not be a Java keyword |
|
REQUIRE_NON_EMPTY_STRING
Factory for validators which require non-zero length text. |
|
REQUIRE_NON_NEGATIVE_NUMBER
Factory for validators which require a non-negative number (may be floating point or int) |
|
REQUIRE_VALID_FILENAME
Factory for validators which require a legal filename |
|
REQUIRE_VALID_INTEGER
Factory for validators which require a valid integer |
|
REQUIRE_VALID_NUMBER
Factory for validators which require a valid number of some sort |
|
URL_MUST_BE_VALID
Factory for validators that require that a string represent a valid URL |
|
VALID_HEXADECIMAL_NUMBER
Factory for validators that require that strings be a valid hexadecimal number |
Method Summary | ||
---|---|---|
static Validator<java.lang.String> |
disallowChars(char[] chars,
boolean trim)
Get a validator which does fails if any of the characters in the passed char array are contained in the evaluated text |
|
static Validator<java.lang.String> |
encodableInCharset(java.lang.String charsetName)
Get a validator which determines if the passed string can be encoded in the specified encoding. |
|
static Validator<javax.swing.ComboBoxModel> |
forComboBox(boolean trim,
Validator<java.lang.String>... validators)
Get a validator for ComboBoxModels which logically OR's together all of the passed built-in validators. |
|
Validator<javax.swing.ComboBoxModel> |
forComboBoxModel(boolean trim)
Get a validator which operates against ComboBoxModel objects. |
|
Validator<javax.swing.text.Document> |
forDocument(boolean trim)
Get a validator which operates against Document objects. |
|
static Validator<javax.swing.text.Document> |
forDocument(boolean trim,
Validator<java.lang.String>... validators)
Get a validator for documents which logically OR's together all of the passed built-in validators. |
|
static Validator<java.lang.String> |
forFormat(java.text.Format fmt)
Get a validator that uses a specific Format (e.g. |
|
Validator<java.lang.String> |
forString(boolean trim)
Get a validator of strings. |
|
|
forType(java.lang.Class<T> type,
boolean trim)
Get a validator for objects of the requested type. |
|
static Validator<java.lang.String> |
maxLength(int length)
Validator that enforces maximum input length |
|
static Validator<java.lang.String> |
merge(boolean trim,
Validator<java.lang.String>... validators)
Get a validator for strings which logically OR's together all of the passed built-in validators. |
|
static
|
merge(Validator<T>... validators)
Logically OR together multiple validators which work against the same type. |
|
static Validator<java.lang.String> |
minLength(int length)
Validator that enforces minimum input length |
|
static Validator<java.lang.String> |
numberRange(java.lang.Number min,
java.lang.Number max)
Get a validator that guarantees that a number is within a certain range (inclusive) |
|
static Validator<javax.swing.ButtonModel[]> |
oneButtonMustBeSelected(java.lang.String msg)
Get a validator for button models which fails if at least one of the button models is not selected. |
|
static Validator<java.lang.String> |
regexp(java.lang.String regexp,
java.lang.String message,
boolean acceptPartialMatches)
Get a validator which fails if the text to validate does not match a passed regular expression. |
|
static Validator<java.lang.String> |
splitString(java.lang.String regexp,
Validator<java.lang.String> other)
Returns a validator which first splits the string to be evaluated according to the passed regexp, then passes each component of the split string to the passed validator. |
|
Validator<java.lang.String> |
trim()
|
|
static Validator<java.lang.String> |
trimString(Validator<java.lang.String>... others)
Wrap a String validator in one which first calls String.trim() on the strings that will be evaluated. |
|
boolean |
validate(Problems problems,
java.lang.String compName,
java.lang.String model)
Validate the passed model. |
|
static Validator<java.lang.String> |
validNumber(java.util.Locale l)
Create a number validator that uses a specific locale. |
|
static Validators |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. |
|
static Validators[] |
values()
Returns an array containing the constants of this enum type, in the order they are declared. |
Methods inherited from class java.lang.Enum |
---|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Enum Constant Detail |
---|
public static final Validators REQUIRE_NON_EMPTY_STRING
public static final Validators REQUIRE_VALID_FILENAME
public static final Validators REQUIRE_VALID_INTEGER
public static final Validators REQUIRE_NON_NEGATIVE_NUMBER
public static final Validators REQUIRE_VALID_NUMBER
public static final Validators REQUIRE_JAVA_IDENTIFIER
public static final Validators VALID_HEXADECIMAL_NUMBER
public static final Validators NO_WHITESPACE
public static final Validators FILE_MUST_EXIST
public static final Validators FILE_MUST_BE_FILE
public static final Validators FILE_MUST_BE_DIRECTORY
public static final Validators URL_MUST_BE_VALID
public static final Validators IP_ADDRESS
public static final Validators HOST_NAME
public static final Validators HOST_NAME_OR_IP_ADDRESS
public static final Validators MAY_NOT_START_WITH_DIGIT
public static final Validators EMAIL_ADDRESS
Note: This validator is not useful for all legal email addresses - for example, "root" with is a legal email address on a Unix machine. Do not use this validator where users might legitimately expect to be able to enter such unqualified email addresses.
public static final Validators CHARACTER_SET_NAME
java.nio.Charset.forName(String)
.
public static final Validators JAVA_PACKAGE_NAME
public static final Validators FILE_MUST_NOT_EXIST
Method Detail |
---|
public static Validators[] values()
for (Validators c : Validators.values()) System.out.println(c);
public static Validators valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.
java.lang.IllegalArgumentException
- if this enum type has no constant
with the specified name
java.lang.NullPointerException
- if the argument is nullpublic Validator<java.lang.String> forString(boolean trim)
trim
- If true, String.trim() is called before passing the value
to the actual validator
public <T> Validator<T> forType(java.lang.Class<T> type, boolean trim)
T
- The type of object you need a validator fortype
- The class of type Ttrim
- Whether or not the returned validator should trim strings
before doing anything
java.lang.IllegalArgumentException
- if no converter of objects of
type type
to strings has been registeredpublic Validator<javax.swing.text.Document> forDocument(boolean trim)
trim
- If true, the text should be trimmed before validation
public Validator<javax.swing.ComboBoxModel> forComboBoxModel(boolean trim)
trim
- If true, the text should be trimmed before validation
public static Validator<java.lang.String> disallowChars(char[] chars, boolean trim)
chars
- The array of illegal characterstrim
- If true, the text should be trimmed before validation
public static Validator<javax.swing.text.Document> forDocument(boolean trim, Validator<java.lang.String>... validators)
trim
- If true, the text should be trimmed before validationvalidators
- one or more Validators enum constants
public static Validator<java.lang.String> merge(boolean trim, Validator<java.lang.String>... validators)
trim
- If true, the text should be trimmed before validationvalidators
- one or more Validators enum constants
public static Validator<javax.swing.ComboBoxModel> forComboBox(boolean trim, Validator<java.lang.String>... validators)
trim
- If true, the text should be trimmed before validationvalidators
- one or more Validators enum constants
public static Validator<javax.swing.ButtonModel[]> oneButtonMustBeSelected(java.lang.String msg)
msg
- The error message if nothing is selected
public static Validator<java.lang.String> trimString(Validator<java.lang.String>... others)
others
- Another validator of strings
public static Validator<java.lang.String> splitString(java.lang.String regexp, Validator<java.lang.String> other)
regexp
- The pattern to use to split the stringother
- the validator the returned one should delegate to to validate
each component of the split string
public static Validator<java.lang.String> regexp(java.lang.String regexp, java.lang.String message, boolean acceptPartialMatches)
regexp
- The regular expressionmessage
- The output message if there is a problem. The message
may refer to the component name as {0} and the text that has not matched
as {1} if desiredacceptPartialMatches
- if true, will use Matcher.lookingAt()
rather
than Matcher.matches()
public static Validator<java.lang.String> validNumber(java.util.Locale l)
l
- The locale to use
public static Validator<java.lang.String> forFormat(java.text.Format fmt)
Format
(e.g.
NumberFormat
) instance and fails
if fmt.parseObject()
throws a ParseException
fmt
- A java.text.Format
NumberFormat
public static Validator<java.lang.String> encodableInCharset(java.lang.String charsetName)
charsetName
- The name of a character set recognized by
java.nio.Charset
UnsupportedCharsetException
- if the character set is unsupported
IllegalCharsetNameException
- if the character set is illegalpublic static Validator<java.lang.String> numberRange(java.lang.Number min, java.lang.Number max)
min
- The minimum valuemax
- The maximum value
public static Validator<java.lang.String> minLength(int length)
length
-
public static Validator<java.lang.String> maxLength(int length)
length
-
public static <T> Validator<T> merge(Validator<T>... validators)
T
- The type of model (Document, String, etc.) you want to
work withvalidators
- Any number of validators which should be logically
OR'd together, merged into a single validator
public boolean validate(Problems problems, java.lang.String compName, java.lang.String model)
Validator
validate
in interface Validator<java.lang.String>
problems
- A list of problems.compName
- The name of the component in question (may be null in some cases)model
- The model in question
public Validator<java.lang.String> trim()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |