|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.fedmest.cw.keyboard.validators.ValueTypeValidator<java.lang.Integer>
com.fedmest.cw.keyboard.validators.IntValidator
public final class IntValidator
This class is used internally by the KeyboardUtils.readIntFromKeyboard()
, KeyboardUtils.readHexFromKeyboard()
,
KeyboardUtils.readOctalFromKeyboard()
and KeyboardUtils.readBinaryFromKeyboard()
methods. It is used as a singleton
via getInstance()
. There is really no need to use it other than through KeyboardUtils
.
Field Summary |
---|
Fields inherited from class com.fedmest.cw.keyboard.validators.ValueTypeValidator |
---|
errorMessage |
Method Summary | |
---|---|
java.lang.Integer |
cancelValue()
Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils
. |
java.lang.Integer |
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 IntValidator |
getInstance()
Returns the only available instance of this class |
static void |
resetMax()
This method resets the maximum integer value that will be accepted by this validator to the highest possible integer value. |
static void |
resetMin()
This method resets the minimum integer value that will be accepted by this validator to the lowest possible integer value. |
static void |
resetRadix()
This method resets the number base to 10 (decimal numbers). |
static void |
resetRange()
This method resets the minimum and maximum integer values that will be accepted by this validator to the lowest and highest possible integer 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(int max)
This method sets the maximum integer value that will be accepted by this validator. |
static void |
setMin(int min)
This method sets the minimum integer value that will be accepted by this validator. |
static void |
setRadix(int radix)
This method sets the number base that will be used the next time you pass this class to KeyboardUtils for validation. |
static void |
setRange(int min,
int max)
This method sets the maximum and minimum integer 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(int) , setMin(int) or setRange(int, int) . |
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 |
---|
public static void setRangeMessage(java.lang.String rangeMessage)
setMax(int)
, setMin(int)
or setRange(int, int)
. 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.
rangeMessage
- the new error message to display to userspublic static void resetRangeMessage()
setRangeMessage(String)
public static void setMax(int max)
max
parameter.
max
- the maximum integer value allowed in parsing (inclusive)public static void resetMax()
setMax(int)
public static void setMin(int min)
min
parameter.
min
- the minimum integer value allowed in parsing (inclusive)public static void resetMin()
setMin(int)
public static void setRange(int min, int max)
min
and max
parameters.
Invoking this method is equivalent to invoking setMin(int)
and setMax(int)
.
min
- the minimum integer value allowed in parsing (inclusive)max
- the maximum integer value allowed in parsing (inclusive)setMin(int)
,
setMax(int)
public static void resetRange()
setMin(int)
,
setMax(int)
,
resetMin()
,
resetMax()
public static void setRadix(int radix)
KeyboardUtils
for validation.
Note that the methods that use this validator in KeyboardUtils
already deal with the radix of numbers to parse, so
there is no need to explicitly call this method.
radix
- the number base to use for integer conversionpublic static void resetRadix()
KeyboardUtils
already deal with the radix of numbers to parse, so there is no need to explicitly call this method.
setRadix(int)
public static IntValidator getInstance()
public java.lang.Integer checkInput(java.lang.String txt) throws KeyboardInputException
KeyboardInputValidator
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.
txt
- the input text. If the string is null, NullPointerException will be thrown.
KeyboardInputException
- if validation against the input string failedpublic java.lang.Integer cancelValue()
KeyboardInputValidator
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).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |