org.fopps.model
Class MinMaxValidator

java.lang.Object
  |
  +--org.fopps.model.MinMaxValidator
All Implemented Interfaces:
Validator

public class MinMaxValidator
extends java.lang.Object
implements Validator

Validator which check aginst min/max range.

Author:
Oliver Wieland

Field Summary
static java.lang.Class[] COMPARE_TO_PARAMETERS
           
 
Constructor Summary
MinMaxValidator(java.lang.Class pClass)
          Creates a new min/max validator by a class instance.
MinMaxValidator(java.lang.Number min, java.lang.Number max)
          Creates a new min/max validator.
 
Method Summary
 boolean check(java.lang.Number pNumber)
          Checks given value agaisnt the validator's rules.
static int compareTo(java.lang.Number a, java.lang.Number b)
          Invokes compareTo on two numbers.
 java.lang.Number firstValue()
          Returns the first valid number of the validator.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPARE_TO_PARAMETERS

public static java.lang.Class[] COMPARE_TO_PARAMETERS
Constructor Detail

MinMaxValidator

public MinMaxValidator(java.lang.Number min,
                       java.lang.Number max)
                throws ValidatorException
Creates a new min/max validator. Both values must have same type. Minimum or maximum may be null, but not both.


MinMaxValidator

public MinMaxValidator(java.lang.Class pClass)
                throws ValidatorException
Creates a new min/max validator by a class instance. Min/max corresponds to the domain ranges of the given class.

Example: new MinMaxValidator(Byte.class) is equal to new MinMaxValidator(new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE)))

Parameters:
pClass - Class to use for min/max. Must be a subclass of Number.
Throws:
ValidatorException, - if argument does not denote a valid class
ValidatorException
Method Detail

check

public boolean check(java.lang.Number pNumber)
              throws ValidatorException
Checks given value agaisnt the validator's rules.

Specified by:
check in interface Validator
Throws:
ValidatorException, - if value is invalid
ValidatorException

firstValue

public java.lang.Number firstValue()
Returns the first valid number of the validator. This is useful to set an initial value.

Specified by:
firstValue in interface Validator

compareTo

public static int compareTo(java.lang.Number a,
                            java.lang.Number b)
                     throws java.lang.Exception
Invokes compareTo on two numbers. This is necessary since Number does not implement Comparable

Returns:
0, if one or both instances are null or the result of a.compareTo(b).
java.lang.Exception
See Also:
Comparable.compareTo(Object)

main

public static void main(java.lang.String[] args)


Fopps 0.19 - Copyright © 2002 Oliver Wieland. All Rights Reserved.