|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
T
- the type of data that the conversion of the input string typed by the user will return.public interface KeyboardInputValidator<T>
This interface should be implemented to create new ways of getting input from the keyboard. The framework expects implementations
to validate keyboard input and return appropriate values of the appropriate type for client applications. The
checkInput(String)
method is at the heart of the input process. It is expected to check and parse the input string and
throw KeyboardInputException
if there are problems, or to then convert the string to the type expected if everything was
ok. The KeyboardUtils
input methods will keep on asking the user for a value until validation and conversion succeed.
Method Summary | |
---|---|
T |
cancelValue()
Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils
. |
T |
checkInput(java.lang.String txt)
Takes the input string, checks its validity and converts it to the data type specified by the type argument. |
Method Detail |
---|
T checkInput(java.lang.String txt) throws java.lang.NullPointerException, KeyboardInputException
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.
java.lang.NullPointerException
- if the input string is null
KeyboardInputException
- if validation against the input string failedT cancelValue()
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 |