com.fedmest.cw.keyboard.validators
Class DoubleValidator

java.lang.Object
  extended by com.fedmest.cw.keyboard.validators.ValueTypeValidator<java.lang.Double>
      extended by com.fedmest.cw.keyboard.validators.DoubleValidator
All Implemented Interfaces:
KeyboardInputValidator<java.lang.Double>

public final class DoubleValidator
extends ValueTypeValidator<java.lang.Double>

This class is used internally by the KeyboardUtils.readDoubleFromKeyboard() methods. It is used as a singleton via getInstance(). There is really no need to use it other than through KeyboardUtils.

Version:
1.0
Author:
Federico Mestrone

Field Summary
 
Fields inherited from class com.fedmest.cw.keyboard.validators.ValueTypeValidator
errorMessage
 
Method Summary
 java.lang.Double cancelValue()
          Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils .
 java.lang.Double checkInput(java.lang.String txt)
          Takes the input string, checks its validity and converts it to the data type specified by the type argument.
static DoubleValidator getInstance()
          Returns the only available instance of this class
static void resetMax()
          This method resets the maximum double value that will be accepted by this validator to the highest possible double value.
static void resetMin()
          This method resets the minimum double value that will be accepted by this validator to the lowest possible double value.
static void resetRange()
          This method resets the minimum and maximum double values that will be accepted by this validator to the lowest and highest possible double values respectively.
static void resetRangeMessage()
          This method resets to the default text the error message that will be displayed to users when the value is out of range ("Value out of range - retry").
static void setMax(double max)
          This method sets the maximum double value that will be accepted by this validator.
static void setMin(double min)
          This method sets the minimum double value that will be accepted by this validator.
static void setRange(double min, double max)
          This method sets the maximum and minimum double values that will be accepted by this validator.
static void setRangeMessage(java.lang.String rangeMessage)
          This method sets the error message that will be displayed to the user if validation fails due to a value being outside of the range specified with setMax(double), setMin(double) or setRange(double, double).
 
Methods inherited from class com.fedmest.cw.keyboard.validators.ValueTypeValidator
resetErrorMessage, setErrorMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setRangeMessage

public static void setRangeMessage(java.lang.String rangeMessage)
This method sets the error message that will be displayed to the user if validation fails due to a value being outside of the range specified with setMax(double), setMin(double) or setRange(double, double). Invoke it before you call any method in KeyboardUtils that uses a class in this validator hierarchy to customize the error message that will be used. Note that the message applies to all subclasses of this class and will be used until reset with resetRangeMessage() or changed with this method again.

Parameters:
rangeMessage - the new error message to display to users

resetRangeMessage

public static void resetRangeMessage()
This method resets to the default text the error message that will be displayed to users when the value is out of range ("Value out of range - retry").

See Also:
setRangeMessage(String)

setMax

public static void setMax(double max)
This method sets the maximum double value that will be accepted by this validator. The value is inclusive. The validator will fail if the input value is greater than the value of the max parameter.

Parameters:
max - the maximum double value allowed in parsing (inclusive)

resetMax

public static void resetMax()
This method resets the maximum double value that will be accepted by this validator to the highest possible double value.

See Also:
setMax(double)

setMin

public static void setMin(double min)
This method sets the minimum double value that will be accepted by this validator. The value is inclusive. The validator will fail if the input value is less than the value of the min parameter.

Parameters:
min - the minimum double value allowed in parsing (inclusive)

resetMin

public static void resetMin()
This method resets the minimum double value that will be accepted by this validator to the lowest possible double value.

See Also:
setMin(double)

setRange

public static void setRange(double min,
                            double max)
This method sets the maximum and minimum double values that will be accepted by this validator. The values are inclusive. The validator will fail if the input value is not within the range specified by the min and max parameters. Invoking this method is equivalent to invoking setMin(double) and setMax(double).

Parameters:
min - the minimum double value allowed in parsing (inclusive)
max - the maximum double value allowed in parsing (inclusive)
See Also:
setMin(double), setMax(double)

resetRange

public static void resetRange()
This method resets the minimum and maximum double values that will be accepted by this validator to the lowest and highest possible double values respectively.

See Also:
setMin(double), setMax(double), resetMin(), resetMax()

getInstance

public static DoubleValidator getInstance()
Returns the only available instance of this class

Returns:
the instance

checkInput

public java.lang.Double checkInput(java.lang.String txt)
                            throws KeyboardInputException
Description copied from interface: KeyboardInputValidator
Takes the input string, checks its validity and converts it to the data type specified by the type argument. If validation fails, a KeyboardInputException is raised and the user will have to type their input again. If a null reference is passed into the method, the method may throw a NullPointerException, so programmers do not need to worry about checking for null pointers.

Parameters:
txt - the input text. If the string is null, NullPointerException will be thrown.
Returns:
the result of converting the typed string into the data type expected
Throws:
KeyboardInputException - if validation against the input string failed

cancelValue

public java.lang.Double cancelValue()
Description copied from interface: KeyboardInputValidator
Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils . Though null should be returned in most cases, this method is useful when - for example - you want to return a primitive type from your validator and can't use null as a return value without causing a bit of inconvenienve in your application code (explicit unboxing and checks for null values).

Returns:
the value to return when user cancels input


Copyright © 2008 Federico Mestrone. All Rights Reserved.