com.fedmest.cw.keyboard
Interface KeyboardInputValidator<T>

Type Parameters:
T - the type of data that the conversion of the input string typed by the user will return.
All Known Implementing Classes:
BooleanValidator, CharChoiceValidator, CharValidator, DateValidator, DoubleValidator, FloatValidator, IntValidator, LongValidator, ValueTypeValidator

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.

Version:
1.0
Author:
Federico Mestrone

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

checkInput

T checkInput(java.lang.String txt)
             throws java.lang.NullPointerException,
                    KeyboardInputException
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:
java.lang.NullPointerException - if the input string is null
KeyboardInputException - if validation against the input string failed

cancelValue

T cancelValue()
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.