All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class oplan.util.Util

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

public class Util
extends Object
Class for useful static methods.


Constructor Index

 o Util()

Method Index

 o askLine(String)
Simple, text-based user interaction.
 o breakStringAtFirst(String, String)
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.
 o printLines(String[])
Print the elements of a String[] array to System.out as lines.
 o readLine(InputStream)
Reads a line from an InputStream and returns it as a String.

Constructors

 o Util
 public Util()

Methods

 o breakStringAtFirst
 public static String[] breakStringAtFirst(String s,
                                           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 "".

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

 o askLine
 public static String askLine(String prompt)
Simple, text-based user interaction. askLine pronts 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.

 o readLine
 public static String readLine(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().


All Packages  Class Hierarchy  This Package  Previous  Next  Index