public class Shell
extends java.lang.Object
null
values and to enter arrays (String/int
) as a
list of comma separated values.
Constructor and Description |
---|
Shell() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
filter(java.lang.String input)
Filter input for some special cases.
|
int[] |
getIntArray(java.util.Scanner scanner)
Get an array of
int separated by commas from the scanner. |
static java.util.Random |
getRandom()
Get the shells random number generator.
|
java.lang.String[] |
getStrArray(java.util.Scanner scanner)
Get an array of
String separated by commas from the scanner. |
java.lang.String |
getStringOrNull(java.util.Scanner scanner)
Retrieve a String from the scanner, filtering it for convenience.
|
static void |
main(java.lang.String[] args)
Entry point to shell.
|
void |
ooMain(java.lang.String[] args)
Provide a main() like method that can be inherited and/or overridden.
|
void |
processCmdsFromFile(java.lang.String fileName)
Process commands from a file.
|
void |
processCommands(java.util.Scanner scanner)
Command interpreter to test code.
|
void |
processOneCommand(java.lang.String cmd,
java.lang.String params)
Process one command.
|
java.lang.String |
rest(java.util.Scanner scanner)
Retrieve a String from the scanner using
nextLine() , to get
everything else in the line and filter it for special values. |
void |
showHelp()
Display a brief help summary for commands implemented by this class
|
static void |
startClock()
Start the millisecond timer
|
static long |
stopClock()
Stop the millisecond timer
|
int[] |
strArrayToIntArray(java.lang.String[] strResult)
Convert an array of
String to an array of int . |
public static void startClock()
public static long stopClock()
public static java.util.Random getRandom()
random
command with a seed.public void showHelp()
protected java.lang.String filter(java.lang.String input)
input
- - the original string"empty!"
,
return ""
. If it is the String "null!"
,
return null
. Otherwise, return the trimmed String.
Override this for more special conditions.public java.lang.String getStringOrNull(java.util.Scanner scanner)
scanner
- - retrieve String from this Scanner.null
).public java.lang.String rest(java.util.Scanner scanner)
nextLine()
, to get
everything else in the line and filter it for special values. This
differs from Scaner.nextLine()
in that the result is trimmed
of leading and trailing blanks, and the special string
null!
scanner
- - retrieve String from this Scanner.null
).public java.lang.String[] getStrArray(java.util.Scanner scanner)
String
separated by commas from the scanner.
A future enhancement will allow quoting so that individual elements may
contain escaped commas.scanner
- - source of the arraynull
, containing the filtered
values.public int[] getIntArray(java.util.Scanner scanner)
int
separated by commas from the scanner.scanner
- - source of the arraynull
, containing the valuespublic int[] strArrayToIntArray(java.lang.String[] strResult)
String
to an array of int
.strResult
- - array of Strings to be converted to intspublic void processOneCommand(java.lang.String cmd, java.lang.String params) throws java.io.FileNotFoundException, java.util.NoSuchElementException
cmd
- - the command to processparams
- - a string containing the parameter(s) (if any)java.io.FileNotFoundException
java.util.NoSuchElementException
public void processCommands(java.util.Scanner scanner)
'#'
. Comments are removed and the resulting string trimmed.
Empty lines are ignored.scanner
- - the source of the commandspublic void processCmdsFromFile(java.lang.String fileName)
fileName
- - name of file containing commandspublic void ooMain(java.lang.String[] args)
args
- - arguments to process. If args
is
null
or of length 0, commands are taken from
System.in
. If args.length
> 0, the
args
are assumed to be one or more file to be
processed using the input
command..public static void main(java.lang.String[] args)
args
- - an array of Strings