public class Utilities
extends java.lang.Object
Utilities
contains miscellaneous static utility methods.Modifier and Type | Method | Description |
---|---|---|
static java.lang.String |
commandLine(java.lang.String program,
java.lang.String[] args) |
Returns a string representation of the command line arguments.
|
static void |
duoPrint(java.io.PrintWriter out,
java.lang.CharSequence s) |
Prints the specified string to the specified
PrintWriter and
to standard out. |
static void |
duoPrintln(java.io.PrintWriter out,
java.lang.CharSequence s) |
Prints the specified string to the specified
PrintWriter and
to standard out. |
static java.lang.String |
elapsedNanos(long nanoseconds) |
Returns a string representation of the specified elapsed time
in the format "H hours M minutes S seconds".
|
static void |
exit(java.lang.String s) |
Prints the specified string to standard error and then terminates the
Java virtual machine.
|
static void |
exit(java.lang.String s,
java.lang.Throwable t) |
Prints the specified exception, its stack trace, and
the specified string to standard error and then terminates the
Java virtual machine.
|
static void |
exit(java.lang.Throwable t) |
Prints the specified exception, its stack trace, and
the specified string to standard error and then terminates the
Java virtual machine.
|
static java.util.Set<java.lang.String> |
idSet(java.io.File file) |
Returns a set of identifiers found in a text file that has
one identifier per line.
|
static java.lang.String |
minutesAndSeconds() |
Returns the current minutes and seconds as a string.
|
static void |
printMemoryUse(java.lang.String msg) |
Prints a summary of memory use at the time of method invocation
to standard output.
|
static void |
shuffle(int[] ia,
int nElements,
java.util.Random random) |
Shuffles the specified array so that a random set of ${code nElements}
from the array are the first elements.
|
static void |
shuffle(int[] ia,
java.util.Random random) |
Randomly shuffles the elements of the specified array.
|
static java.lang.String |
timeStamp() |
Returns the current local time as a string.
|
public static java.lang.String commandLine(java.lang.String program, java.lang.String[] args)
program
- the name of the program's jar file.args
- command line arguments.public static void printMemoryUse(java.lang.String msg)
msg
- a string a message to be printed with the summary
of memory usepublic static java.lang.String timeStamp()
public static java.lang.String minutesAndSeconds()
public static java.util.Set<java.lang.String> idSet(java.io.File file)
Returns a set of identifiers found in a text file that has
one identifier per line. The empty set is returned if
file == null
. Blank lines are ignored, and white-space that
begins or ends a line is ignored.
IOException
is thrown, an error message is printed
to standard error and the Java virtual machine is forced to terminate.file
- a text file with one identifier per linejava.lang.IllegalArgumentException
- if the specified file does not existjava.lang.IllegalArgumentException
- if the specified file is a directoryjava.lang.IllegalArgumentException
- if any line of the specified
file contains two non-white-space characters separated by one or
more white-space characterspublic static void duoPrint(java.io.PrintWriter out, java.lang.CharSequence s)
PrintWriter
and
to standard out. The line separator string is not appended to the
specified string before printing.out
- a print writers
- a string to be printedjava.lang.NullPointerException
- if out == null
public static void duoPrintln(java.io.PrintWriter out, java.lang.CharSequence s)
PrintWriter
and
to standard out. The line separator string is appended to the
specified string before printing.out
- a print writers
- a string to be printedjava.lang.NullPointerException
- if out == null
public static java.lang.String elapsedNanos(long nanoseconds)
nanoseconds
- the elapsed time in nanosecondspublic static void exit(java.lang.String s, java.lang.Throwable t)
s
- a string to be printed to standard errort
- an exception or error to be printed to standard errorjava.lang.NullPointerException
- if e == null
public static void exit(java.lang.Throwable t)
t
- an exception or error to be printed to standard errorjava.lang.NullPointerException
- if e == null
public static void exit(java.lang.String s)
s
- a string to be written to standard errorpublic static void shuffle(int[] ia, java.util.Random random)
ia
- an array to be shuffledrandom
- a random number generatorjava.lang.NullPointerException
- if ia == null || random == null
public static void shuffle(int[] ia, int nElements, java.util.Random random)
nElements <= 0
.ia
- an array to be shufflednElements
- the size of the random set of elements which
are shuffled to the beginning of the arrayrandom
- a random number generatorjava.lang.IndexOutOfBoundsException
- if nElements > ia.length
java.lang.NullPointerException
- if ia == null || random == null