|
Java Case Studies | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--phw.util.Ask
This Ask class contains a set of static methods for safe interactive input of individual primitive types. They will not return until an acceptable answer has been entered. The implementation techniques draw on those in the `Java Gently' textbook by Judy Bishop.
| Method Summary | |
static boolean |
Boolean(java.lang.String prompt)
Ask.Boolean issues the prompt and returns a boolean depending on the first non-white-space character typed. |
static byte |
Byte(java.lang.String prompt,
byte min,
byte max)
Ask.Byte issues the prompt and returns a byte between min and max inclusive. |
static char |
Char(java.lang.String prompt,
char[] valid)
Ask.Char issues the prompt and returns a char depending on the first non-white-space character typed. |
static double |
Double(java.lang.String prompt,
double min,
double max)
Ask.Double issues the prompt and returns a double between min and max inclusive. |
static float |
Float(java.lang.String prompt,
float min,
float max)
Ask.Float issues the prompt and returns a float between min and max inclusive. |
static boolean |
getOneTokenReply()
Ask.getOneTokenReply returns whether multiple response tokens will be rejected. |
static int |
Int(java.lang.String prompt,
int min,
int max)
Ask.Int issues the prompt and returns an int between min and max inclusive. |
static long |
Long(java.lang.String prompt,
long min,
long max)
Ask.Long issues the prompt and returns an long between min and max inclusive. |
static void |
setOneTokenReply(boolean b)
Ask.setOneTokenReply (true) specifies that more than one token in the user reply will be rejected, even if the first token is valid. |
static short |
Short(java.lang.String prompt,
short min,
short max)
Ask.Short issues the prompt and returns a short between min and max inclusive. |
static java.lang.String |
string(java.lang.String prompt)
Ask.string issues the prompt and returns the String that is typed. |
static void |
Void(java.lang.String prompt)
Ask.Void issues the prompt and returns when |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Method Detail |
public static int Int(java.lang.String prompt,
int min,
int max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.
public static long Long(java.lang.String prompt,
long min,
long max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.
public static byte Byte(java.lang.String prompt,
byte min,
byte max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.
public static short Short(java.lang.String prompt,
short min,
short max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.
public static float Float(java.lang.String prompt,
float min,
float max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.
public static double Double(java.lang.String prompt,
double min,
double max)
prompt - the string used to prompt for input.min - user input must have a value >= min.max - user input must have a value <= max.public static boolean Boolean(java.lang.String prompt)
prompt - the string used to prompt for input.
public static char Char(java.lang.String prompt,
char[] valid)
prompt - the string used to prompt for input.valid - the array of characters defining valid user responses.public static void Void(java.lang.String prompt)
prompt - the string used to prompt for a public static java.lang.String string(java.lang.String prompt)
prompt - the string used to prompt for input.public static void setOneTokenReply(boolean b)
Ask.setOneTokenReply (false) specifies that multiple tokens are allowed, but that only the first will be processed.
The false allows user input to be documented with comments (in the second and following tokens) explaining the meaning of the first token, which contains the actual data. This is useful when preparing user input as a file, from which the standard input stream will later be redirected, so that each line of input can be documented.
b - if true, the response must consist of a single token
- otherwise, multiple tokens are allowed but only the first will be processed.public static boolean getOneTokenReply()
|
Java Case Studies | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||