|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectix.util.Util
public class Util
Class for useful static methods that don't belong anywhere else.
Collect
,
Fn
,
Strings
Constructor Summary | |
---|---|
Util()
|
Method Summary | |
---|---|
static java.lang.String |
aClass(java.lang.Class c)
Returns a "nice" name for a class, using dash-syntax rather than Java capitalisation, prefixed by "a" or "an" as appropriate. |
static java.lang.Object |
appendArrays(java.lang.Object[] arrays)
Appends the arrays in an array of arrays. |
static java.lang.Object |
appendArrays(java.lang.Object array1,
java.lang.Object array2)
Appends two arrays. |
static java.lang.String |
askLine(java.lang.String prompt)
Simple, text-based user interaction. |
static java.lang.String |
askLines(java.lang.String prompt)
Prompts for multi-line textual input. |
static java.lang.Class |
classForNameElseNull(java.lang.String name)
Returns the class of the specified name or else null if the class cannot be found. |
static java.lang.Object |
clone(java.lang.Object obj)
Clones an object without any declared checked exceptions. |
static java.lang.Object |
cloneBySerializing(java.lang.Object obj)
Performs a deep-copy clone by serializing then deserialising an object. |
static boolean |
dialogConfirms(java.awt.Component parent,
java.lang.Object text)
Displays a confirmation dialog and returns true or false depending on whether the use selected "Yes" or "No". |
static void |
displayAndWait(java.awt.Component parentComponent,
java.lang.Object message)
Asks the GUI event-handling thread to display a text message in a dialogue box and does not return until this has occurred and the user has dismissed the dialogue. |
static java.lang.String |
getHostName()
Returns the name of the machine that is running this JVM. |
static javax.swing.ImageIcon |
getImageIcon(java.lang.String name)
Constructs an ImageIcon from the named (image) resource. |
static java.lang.String |
getUserName()
Returns the name of the user who started this JVM. |
static java.lang.Object |
makeInstance(java.lang.Class c)
Makes an instance of a class using the 0-argument constructor. |
static java.lang.Object |
makeInstance(java.lang.Class c,
java.lang.Object arg)
Makes an instance of a class using a 1-argument constructor. |
static java.lang.Object |
mustBe(java.lang.Class c,
java.lang.Object o)
Returns an object if it is an instance of the specified class, but throws a ClassCastException if it isn't. |
static void |
notImplemented(java.awt.Component parent,
java.lang.String item)
Brings up a message that the given string item is not yet supported. |
static java.io.Reader |
openURLReader(java.net.URL url)
Returns a Reader for the specified URL based on the InputStream and content encoding obtained by opening a connection to the URL. |
static void |
printGreeting(java.lang.String name)
A method to print the name of the system, the release version, and the release date. |
static void |
printLines(java.lang.String[] lines)
Print the elements of a String[] array to System.out as lines. |
static java.lang.String |
quote(java.lang.String text)
Puts double quotes around a string. |
static java.lang.String |
readLine()
Reads a line from System.in . |
static java.lang.String |
readLine(java.io.InputStream is)
Reads a line from an InputStream and returns it as a String. |
static java.lang.String |
readLines()
Reads lines from System.in . |
static java.lang.String |
readLines(java.io.InputStream in)
Reads lines up to a blank line, then returns all of the lines, except the blank one, concatenated into one string. |
static void |
renameToBackup(java.io.File file)
Renames the file to indicate it is an earlier version so that a new version can then be written. |
static javax.swing.ImageIcon |
resourceImageIcon(java.lang.String name)
Constructs an ImageIcon from the named (image) resource found on the system's class path. |
static void |
run(java.lang.Runnable thunk)
A method that lets you write "run" before the creation of a Runnable. |
static void |
runHooks(java.lang.String when,
java.util.List hooks)
Runs each item, in sequence, in a list of Runnables. |
static java.lang.String |
showInputDialog(java.awt.Component parent,
java.lang.Object message,
java.lang.Object initialValue)
Display a textual input dialog with a specified initial value. |
static void |
sleepSeconds(int seconds)
Sleeps for the specified number of seconds. |
static void |
swingAndWait(java.lang.Runnable thunk)
A version of SwingUtilities.invokeAndWait(Runnable) that does not require local handling of checked exceptions. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Util()
Method Detail |
---|
public static void printGreeting(java.lang.String name)
public static void displayAndWait(java.awt.Component parentComponent, java.lang.Object message)
If this method is called outside the event dispatching
thread, it calls SwingUtilities.invokeAndWait(Runnable)
.
parentComponent
- determines the Frame in which dialogs
are displayed.message
- the contents of the message.public static void swingAndWait(java.lang.Runnable thunk)
RethrownException
- if SwingUtilities.invokeAndWait throws
an InvocationTargetException or InterruptedException.public static void notImplemented(java.awt.Component parent, java.lang.String item)
public static java.lang.String showInputDialog(java.awt.Component parent, java.lang.Object message, java.lang.Object initialValue)
Such a method is provided by JOptionPane in JDK 1.4 and later, but not, it seems, in earlier versions.
public static boolean dialogConfirms(java.awt.Component parent, java.lang.Object text)
swingAndWait(Runnable)
,
displayAndWait(java.awt.Component, Object)
public static void sleepSeconds(int seconds)
public static java.io.Reader openURLReader(java.net.URL url) throws java.io.IOException
java.io.IOException
public static javax.swing.ImageIcon getImageIcon(java.lang.String name)
XML.toURL(String)
public static javax.swing.ImageIcon resourceImageIcon(java.lang.String name)
public static java.lang.String getUserName()
public static java.lang.String getHostName() throws java.net.UnknownHostException
java.net.UnknownHostException
- if it cannot determine the
host name and no "host" parameter has been specified.Parameters
public static java.lang.String quote(java.lang.String text)
public static void run(java.lang.Runnable thunk)
Util.run(new Runnable() { public void run() { ... } });instead of the more awkward
new Runnable() { public void run() { ... } }.run();
public static void runHooks(java.lang.String when, java.util.List hooks)
public static java.lang.Class classForNameElseNull(java.lang.String name)
Class.forName(name)
and catching any
ClassNotFoundException.
public static java.lang.Object makeInstance(java.lang.Class c)
RethrownException
- if the attempt fails, with the
original exception inside it.public static java.lang.Object makeInstance(java.lang.Class c, java.lang.Object arg)
c
- the class to instantiatearg
- an object to pass to the constructor
RethrownException
- if the attempt fails, with the
original exception inside it.public static java.lang.Object clone(java.lang.Object obj)
public static java.lang.Object cloneBySerializing(java.lang.Object obj)
public static java.lang.Object mustBe(java.lang.Class c, java.lang.Object o)
public static java.lang.String aClass(java.lang.Class c)
public static java.lang.Object appendArrays(java.lang.Object[] arrays)
java.lang.IllegalArgumentException
- if there isn't at least
one array to append or if any of the objects to append
isn't an array.public static java.lang.Object appendArrays(java.lang.Object array1, java.lang.Object array2)
java.lang.IllegalArgumentException
- if either of the objects
to append isn't an array.public static void printLines(java.lang.String[] lines)
public static java.lang.String askLine(java.lang.String prompt)
If askLine blocks when reading, we'd like other threads to be able to run; but that doesn't seem to happen reliably. Presumably, this is a bug. In any case, askLine works around the problem by having a loop that checks whether input is available and sleeps for a second if it isn't.
public static java.lang.String askLines(java.lang.String prompt)
askLine(String)
,
readLines()
public static java.lang.String readLine()
System.in
.
readLine(InputStream)
public static java.lang.String readLine(java.io.InputStream is)
public static java.lang.String readLines()
System.in
.
readLines(InputStream)
public static java.lang.String readLines(java.io.InputStream in)
readLine(InputStream)
public static void renameToBackup(java.io.File file)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |