utilities
Class SimpleInput

java.lang.Object
  |
  +--utilities.SimpleInput

public class SimpleInput
extends java.lang.Object

A helper class that allows words, numbers, and booleans to be read from an input stream. This can be either System.in or a named file. All methods throw a RuntimeException object if EOF is reached when a value is requested.


Constructor Summary
SimpleInput()
          Read input from System.in.
SimpleInput(java.io.File details)
          Read input from the given file.
SimpleInput(java.lang.String file)
          Read input from the given file.
 
Method Summary
 void discardLine()
          Discard the remainder of the current line, if any.
 java.lang.String getDelimiters()
          Return the current set of delimiters used in tokenizing the input.
 boolean nextBoolean()
          Find the next boolean word on the input.
 double nextDouble()
          Find the next numeric value on the input.
 float nextFloat()
          Find the next numeric value on the input.
 int nextInt()
          Find the next numeric value on the input.
 java.lang.String nextLine()
          Return the next input line.
 long nextLong()
          Find the next numeric value on the input.
 short nextShort()
          Find the next numeric value on the input.
 java.lang.String nextWord()
          Find the next word on the input.
 void setDelimiters(java.lang.String d)
          Mutator for the delimiters to be used in tokenizing the input.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleInput

public SimpleInput()
Read input from System.in.

SimpleInput

public SimpleInput(java.lang.String file)
            throws java.lang.RuntimeException
Read input from the given file.
Parameters:
file - Read input from the named file.
Throws:
java.lang.RuntimeException - if file cannot be opened.

SimpleInput

public SimpleInput(java.io.File details)
            throws java.lang.RuntimeException
Read input from the given file.
Parameters:
details - Read input from the given file.
Throws:
java.lang.RuntimeException - if file cannot be opened.
Method Detail

nextShort

public short nextShort()
                throws java.lang.RuntimeException
Find the next numeric value on the input. Non-numerical input is skipped. A floating point number on the input is truncated.
Returns:
The next number from the input stream as a short.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextInt

public int nextInt()
            throws java.lang.RuntimeException
Find the next numeric value on the input. Non-numerical input is skipped. A floating point number on the input is truncated.
Returns:
The next number from the input stream as an int.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextLong

public long nextLong()
              throws java.lang.RuntimeException
Find the next numeric value on the input. Non-numerical input is skipped. A floating point number on the input is truncated.
Returns:
The next number from the input stream as a long.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextFloat

public float nextFloat()
                throws java.lang.RuntimeException
Find the next numeric value on the input. Non-numerical input is skipped. A floating point number on the input is truncated.
Returns:
The next floating point number from the input stream as a float.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextDouble

public double nextDouble()
                  throws java.lang.RuntimeException
Find the next numeric value on the input. Non-numerical input is skipped.
Returns:
The next floating point number from the input stream as a double.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextWord

public java.lang.String nextWord()
                          throws java.lang.RuntimeException
Find the next word on the input. This does not distinguish numbers from words.
Returns:
The next token from the input stream as a String.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.
See Also:
StringTokenizer

nextBoolean

public boolean nextBoolean()
                    throws java.lang.RuntimeException
Find the next boolean word on the input. This will be either true, false, t, or f, ignoring case. Numerical input and non-boolean words are skipped.
Returns:
A boolean value corresponding to the next boolean word on the input stream.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

nextLine

public java.lang.String nextLine()
                          throws java.lang.RuntimeException
Return the next input line. This will discard the remainder of the current line, if any.
Returns:
The next line on the input stream as a string.
Throws:
java.lang.RuntimeException - if end-of-file has been reached.

discardLine

public void discardLine()
Discard the remainder of the current line, if any.
Since:
Version 1.3

getDelimiters

public java.lang.String getDelimiters()
Return the current set of delimiters used in tokenizing the input.
Returns:
The delimiters currently in use by the string tokenizer. By default these are space and tab.

setDelimiters

public void setDelimiters(java.lang.String d)
Mutator for the delimiters to be used in tokenizing the input.
Parameters:
The - new string of delimiters. By default these are " \t".