Package blbutil
Class Utilities
java.lang.Object
blbutil.Utilities
Class
Utilities contains miscellaneous static utility methods.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcommandLine(String program, String[] args) Returns a string representation of the command line arguments.static voidduoPrint(PrintWriter out, CharSequence s) Prints the specified string to the specifiedPrintWriterand to standard out.static voidduoPrintln(PrintWriter out, CharSequence s) Prints the specified string to the specifiedPrintWriterand to standard out.static StringelapsedNanos(long nanoseconds) Returns a string representation of the specified elapsed time in the format "H hours M minutes S seconds".static voidexit()Prints "Terminating program." to standard error and terminates the Java virtual machine.static voidPrints the specified string to standard error and then terminates the Java virtual machine.static voidPrints the specified exception, its stack trace and then terminates the Java virtual machine.static voidPrints the specified exception, its stack trace, and the specified string to standard error and then terminates the Java virtual machine.Returns a set of identifiers found in a text file that has one identifier per line.static StringReturns the current minutes and seconds as a string.static voidprintMemoryUse(String msg) Prints a summary of memory use at the time of method invocation to standard output.static voidShuffles the specified array so that a random set of ${code nElements} elements from the array are the first ${code nElements} elements.static voidRandomly shuffles the elements of the specified array.static StringReturns the current local time as a string.
-
Method Details
-
commandLine
Returns a string representation of the command line arguments. The exact details of the representation are unspecified and subject to change.- Parameters:
program- the name of the program's jar file.args- command line arguments.- Returns:
- a string representation of the command line arguments.
-
printMemoryUse
Prints a summary of memory use at the time of method invocation to standard output.- Parameters:
msg- a string a message to be printed with the summary of memory use
-
timeStamp
Returns the current local time as a string. The exact details of the string representation are unspecified and subject to change.- Returns:
- the current local time as a string.
-
minutesAndSeconds
Returns the current minutes and seconds as a string. The exact details of the string representation are unspecified and subject to change.- Returns:
- the current local time as a string.
-
idSet
Returns a set of identifiers found in a text file that has one identifier per line. The empty set is returned if
If anfile == null. Blank lines are ignored, and white-space that begins or ends a line is ignored.IOExceptionis thrown, an error message is printed to standard error and the Java virtual machine is forced to terminate.- Parameters:
file- a text file with one identifier per line- Returns:
- a set of identifiers
- Throws:
IllegalArgumentException- if the specified file does not existIllegalArgumentException- if the specified file is a directoryIllegalArgumentException- if any line of the specified file contains two non-white-space characters separated by one or more white-space characters
-
duoPrint
Prints the specified string to the specifiedPrintWriterand to standard out. The line separator string is not appended to the specified string before printing.- Parameters:
out- a print writers- a string to be printed- Throws:
NullPointerException- ifout == null
-
duoPrintln
Prints the specified string to the specifiedPrintWriterand to standard out. The line separator string is appended to the specified string before printing.- Parameters:
out- a print writers- a string to be printed- Throws:
NullPointerException- ifout == null
-
elapsedNanos
Returns a string representation of the specified elapsed time in the format "H hours M minutes S seconds".- Parameters:
nanoseconds- the elapsed time in nanoseconds- Returns:
- a string representation of the specified elapsed time
-
exit
Prints the specified exception, its stack trace, and the specified string to standard error and then terminates the Java virtual machine.- Parameters:
thr- an exception or error to be printed to standard errorstr- a string to be printed to standard error- Throws:
NullPointerException- ift == null
-
exit
Prints the specified exception, its stack trace and then terminates the Java virtual machine.- Parameters:
t- an exception or error to be printed to standard error- Throws:
NullPointerException- ife == null
-
exit
Prints the specified string to standard error and then terminates the Java virtual machine.- Parameters:
s- a string to be written to standard error
-
exit
public static void exit()Prints "Terminating program." to standard error and terminates the Java virtual machine. -
shuffle
Randomly shuffles the elements of the specified array.- Parameters:
ia- an array to be shuffledrandom- a random number generator- Throws:
NullPointerException- ifia == null || random == null
-
shuffle
Shuffles the specified array so that a random set of ${code nElements} elements from the array are the first ${code nElements} elements. The specified array is unchanged ifnElements <= 0.- Parameters:
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 generator- Throws:
IndexOutOfBoundsException- ifnElements > ia.lengthNullPointerException- ifia == null || random == null
-