com.fedmest.cw.keyboard.validators
Class BooleanValidator

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

public final class BooleanValidator
extends ValueTypeValidator<java.lang.Boolean>

This class is used internally by the KeyboardUtils.readBoolFromKeyboard() 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.Boolean cancelValue()
          Allows you to specify the return value to offer when the user cancels input on a cancelable instance of KeyboardUtils .
 java.lang.Boolean 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 BooleanValidator getInstance()
          Returns the only available instance of this class
 
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

getInstance

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

Returns:
the instance

checkInput

public java.lang.Boolean 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.Boolean 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.