nl.lxtreme.ols.util.swing.validation
Class NumberValidator

java.lang.Object
  extended by nl.lxtreme.ols.util.swing.validation.NumberValidator
All Implemented Interfaces:
IValidator

public final class NumberValidator
extends Object
implements IValidator

Provides a simple number validator.


Constructor Summary
NumberValidator()
          Creates a new NumberValidator instance for integer decimal values.
NumberValidator(Class<?> aType)
          Creates a new NumberValidator instance for numeric (decimal) values of the given type.
NumberValidator(Class<?> aType, int aRadix)
          Creates a new NumberValidator instance for numeric values of the given type and radix.
NumberValidator(int aRadix)
          Creates a new NumberValidator instance for integer values with a given radix.
 
Method Summary
static boolean isFloatType(Class<?> aType)
          Returns whether or not the given type represents a numeric floating-point type.
static boolean isIntegerType(Class<?> aType)
          Returns whether or not the given type represents a numeric integer-like type.
static boolean isNumericType(Class<?> aType)
          Returns whether or not the given type represents a numeric type.
protected  Number parse(String aInputText)
          Parses the given input to a number, if possible.
 boolean validate(Object aValue)
          Validates the given value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberValidator

public NumberValidator()
Creates a new NumberValidator instance for integer decimal values.


NumberValidator

public NumberValidator(Class<?> aType)
Creates a new NumberValidator instance for numeric (decimal) values of the given type.

Parameters:
aType - the numeric type (Integer, Long, ...) to expect.

NumberValidator

public NumberValidator(Class<?> aType,
                       int aRadix)
Creates a new NumberValidator instance for numeric values of the given type and radix.

Parameters:
aType - the numeric type (Integer, Long, ...) to expect;
aRadix - the radix of the values to expect (2, 8, 10, 16).
Throws:
IllegalArgumentException - in case the given type was either a float or double and the radix is not 10.

NumberValidator

public NumberValidator(int aRadix)
Creates a new NumberValidator instance for integer values with a given radix.

Parameters:
aRadix - the radix of the values to expect (2, 8, 10, 16).
Method Detail

isFloatType

public static boolean isFloatType(Class<?> aType)
Returns whether or not the given type represents a numeric floating-point type.

Parameters:
aType - the type to test, can be null.
Returns:
true if the given type represents a floating-point type, false otherwise.

isIntegerType

public static boolean isIntegerType(Class<?> aType)
Returns whether or not the given type represents a numeric integer-like type.

Parameters:
aType - the type to test, can be null.
Returns:
true if the given type represents a integer-like type, false otherwise.

isNumericType

public static boolean isNumericType(Class<?> aType)
Returns whether or not the given type represents a numeric type.

Parameters:
aType - the type to test, can be null.
Returns:
true if the given type represents a numeric type, false otherwise.

validate

public boolean validate(Object aValue)
Description copied from interface: IValidator
Validates the given value.

Specified by:
validate in interface IValidator
Parameters:
aValue - the value to validate, can be null or any object.
Returns:
true if the given value is correct, false otherwise.
See Also:
IValidator.validate(java.lang.Object)

parse

protected final Number parse(String aInputText)
Parses the given input to a number, if possible.

Parameters:
aInputText - the text to parse as number, cannot be null.
Returns:
the parsed number, can be null in case the given text could not be parsed.


Copyright © 2012 L'Xtreme IT consultancy. All Rights Reserved.