org.srplib.validation
Class Validators

java.lang.Object
  extended by org.srplib.validation.Validators

public class Validators
extends Object

Contains static factory method constructing validators.

Author:
Anton Pechinsky

Constructor Summary
Validators()
           
 
Method Summary
static Validator<String> email()
          Creates email address validators.
static Validator<String> length(int minimum, int maximum)
          Creates string length validators.
static Validator<String> maxLength(int maximum)
          Creates maximal string length validators.
static Validator<String> minLength(int minimum)
          Creates minimal string length validators.
static ValidationError newError(String message)
          Creates new validation error basing on simple string message.
static ValidationError newError(String message, Object formField)
          Creates new validation error basing on simple string message and associate it with specified form field.
static Validator<String> phone()
          Creates phone validators.
static
<T extends Number>
Validator<T>
positive()
          Creates number validators.
static
<T extends Comparable<T>>
Validator<T>
range(T minimum, T maximum)
          Creates value range validators.
static Validator<String> regexp(String regexp)
          Creates validators which matches string against specified regular expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Validators

public Validators()
Method Detail

newError

public static ValidationError newError(String message)
Creates new validation error basing on simple string message.

Parameters:
message - String error message.
Returns:
ValidationError validation error

newError

public static ValidationError newError(String message,
                                       Object formField)
Creates new validation error basing on simple string message and associate it with specified form field.

Parameters:
message - String error message.
formField - FormField a field where validation error has been detected.
Returns:
ValidationError validation error

length

public static Validator<String> length(int minimum,
                                       int maximum)
Creates string length validators. Checks if string length is in specified range.

Parameters:
minimum - minimal string length (inclusive).
maximum - maximal string length (inclusive).
Returns:
Validator
See Also:
StringLengthValidator

minLength

public static Validator<String> minLength(int minimum)
Creates minimal string length validators. Checks if string length is not less than specified minimum.

Parameters:
minimum - minimal string length (inclusive).
Returns:
Validator

maxLength

public static Validator<String> maxLength(int maximum)
Creates maximal string length validators. Checks if string length is not greater than specified maximum.

Parameters:
maximum - maximal string length (inclusive).
Returns:
Validator

regexp

public static Validator<String> regexp(String regexp)
Creates validators which matches string against specified regular expression.

Parameters:
regexp - String regular expression.
Returns:
Validator

email

public static Validator<String> email()
Creates email address validators.

Returns:
Validator email address validators.
See Also:
EmailAddressValidator

phone

public static Validator<String> phone()
Creates phone validators.

Returns:
Validator phone validators.

range

public static <T extends Comparable<T>> Validator<T> range(T minimum,
                                                           T maximum)
Creates value range validators. Checks if value is in specified range. May be applied to any subtype of Comparable.

Parameters:
minimum - minimal value (inclusive).
maximum - maximal value (inclusive).
Returns:
Validator value range validators.
See Also:
ValueRangeValidator

positive

public static <T extends Number> Validator<T> positive()
Creates number validators. Checks if Number is positive.

Returns:
Validator positive number validators.
See Also:
PositiveNumberValidator


Copyright © 2012. All Rights Reserved.