ix.util
Class Util

java.lang.Object
  |
  +--ix.util.Util

public class Util
extends java.lang.Object

Class for useful static methods.


Inner Class Summary
static class Util.NameGenerator
          Name generator a la gensym.
 
Constructor Summary
Util()
           
 
Method Summary
static java.lang.String askLine(java.lang.String prompt)
          Simple, text-based user interaction.
static java.util.List breakIntoLines(java.lang.String text)
          Returns a List of the lines in a string.
static java.lang.String[] breakStringAtFirst(java.lang.String s, java.lang.String separator)
          breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after.
static java.lang.String capitalizeString(java.lang.String s)
          Returns a copy of the string in which the first character is in upper case and the rest of the string is left as it was.
static void displayMessage(java.awt.Component parentComponent, java.lang.String text)
          Displays a text message in a dialogue box.
static java.lang.String firstLine(java.lang.String s)
          Returns the first line of a string.
static java.lang.String generateName(java.lang.String base)
          Generates a name unique within this VM that begins with the specified base string.
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(java.io.InputStream is)
          Reads a line from an InputStream and returns it as a String.
static java.lang.String repeatString(java.lang.String s, int count)
          Returns a String made by appending a specified string count times.
static java.lang.String restLines(java.lang.String s)
          Returns the rest of a string after the first line has been removed.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

printGreeting

public static void printGreeting(java.lang.String name)
A method to print the name of the system, the release version, and the release date.

displayMessage

public static void displayMessage(java.awt.Component parentComponent,
                                  java.lang.String text)
Displays a text message in a dialogue box.
Parameters:
parentComponent - determines the Frame in which dialogs are displayed.
text - the contents of the message.

breakStringAtFirst

public static java.lang.String[] breakStringAtFirst(java.lang.String s,
                                                    java.lang.String separator)
breakStringAtFirst takes a string containing fields separated by a (string) delimiter and returns a two-element string array containing the substring before the first occurrence of the char, and the substring after. Neither substring contains the delimiter. If the delimiter does not appear in the string at all, the values are the string and "".

firstLine

public static java.lang.String firstLine(java.lang.String s)
Returns the first line of a string.

restLines

public static java.lang.String restLines(java.lang.String s)
Returns the rest of a string after the first line has been removed.

breakIntoLines

public static java.util.List breakIntoLines(java.lang.String text)
Returns a List of the lines in a string.

quote

public static java.lang.String quote(java.lang.String text)
Puts double quotes around a string. This is useful to indicate the boundaries of the string when it's included in other text such as in an error or warning message.

capitalizeString

public static java.lang.String capitalizeString(java.lang.String s)
Returns a copy of the string in which the first character is in upper case and the rest of the string is left as it was.

repeatString

public static java.lang.String repeatString(java.lang.String s,
                                            int count)
Returns a String made by appending a specified string count times.

generateName

public static java.lang.String generateName(java.lang.String base)
Generates a name unique within this VM that begins with the specified base string. (Note that "unique" means unique among the names generated in this way; the same string might, of course, be constructed in some other way.)

printLines

public static void printLines(java.lang.String[] lines)
Print the elements of a String[] array to System.out as lines.

askLine

public static java.lang.String askLine(java.lang.String prompt)
Simple, text-based user interaction. askLine prints a prompt to System.out and returns a String containing the next line from System.in.

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.


readLine

public static java.lang.String readLine(java.io.InputStream is)
Reads a line from an InputStream and returns it as a String. In Java, we seem to have to write this ourself unless we wrap a special stream (or Reader) around whatever we want to read. Here we provide a static method, because that's easier to mix with other operations. The only InputStream method called is read().