maspack.util
Class Scan

java.lang.Object
  extended by maspack.util.Scan

public class Scan
extends java.lang.Object

A set of static methods to help scan values from a ReaderTokenizer.


Constructor Summary
Scan()
           
 
Method Summary
static boolean checkForFieldName(ReaderTokenizer rtok, java.lang.String name)
          Checks to see if the next input token corresponds to a specific field name.
static java.awt.Color scanColor(ReaderTokenizer rtok)
          Reads and returns a Color from a tokenizer.
static int scanDoubles(double[] vals, ReaderTokenizer rtok)
          Reads a set of double values, enclosed in square brackets [ ].
static double[] scanDoubles(ReaderTokenizer rtok)
          Reads a set of double values, enclosed in square brackets [ ], and returns them in an array.
static int scanFloats(float[] vals, ReaderTokenizer rtok)
          Reads a set of float values, enclosed in square brackets [ ].
static float[] scanFloats(ReaderTokenizer rtok)
          Reads a set of float values, enclosed in square brackets [ ], and returns them in an array.
static int scanInts(int[] vals, ReaderTokenizer rtok)
          Reads a set of integer values, enclosed in square brackets [ ].
static int[] scanInts(ReaderTokenizer rtok)
          Reads a set of integer values, enclosed in square brackets [ ], and returns them in an array.Values which exceed the allowed range for integers will be truncated in the high order bits.
static int scanLongs(long[] vals, ReaderTokenizer rtok)
          Reads a set of long integer values, enclosed in square brackets [ ].
static long[] scanLongs(ReaderTokenizer rtok)
          Reads a set of long integer values, enclosed in square brackets [ ], and returns them in an array.
static java.lang.String[] scanQuotedStrings(ReaderTokenizer rtok, char quoteChar)
          Reads a set of quoted strings, enclosed in square brackets [ ], and returns them as an array of Strings.
static Scannable scanScannable(ReaderTokenizer rtok, java.lang.Object ref)
          Scans a Scannable object, which is preceeded by it's class name.
static short[] scanShorts(ReaderTokenizer rtok)
          Reads a set of short integer values, enclosed in square brackets [ ], and returns them in an array.
static int scanShorts(short[] vals, ReaderTokenizer rtok)
          Reads a set of short integer values, enclosed in square brackets [ ].
static java.lang.String[] scanWords(ReaderTokenizer rtok)
          Reads a set of words values, enclosed in square brackets [ ], and returns them as an array of Strings.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Scan

public Scan()
Method Detail

scanColor

public static java.awt.Color scanColor(ReaderTokenizer rtok)
                                throws java.io.IOException
Reads and returns a Color from a tokenizer. The color should be represented as either three or four numbers surrounded by square brackets [ ], representing red, green, and blue values, and an optional alpha value, in the range 0 to 1. If alpha is not present, it defaults to 1.

Parameters:
rtok - Tokenizer from which the color is read
Returns:
Color object produced by the input
Throws:
java.io.IOException - if the color is formatted incorrectly or if an I/O error occured

scanDoubles

public static int scanDoubles(double[] vals,
                              ReaderTokenizer rtok)
                       throws java.io.IOException
Reads a set of double values, enclosed in square brackets [ ]. Values are placed in an argument array and the number of values actually read is returned.

Parameters:
vals - array in which values are stored
rtok - Tokenizer from which values are read
Returns:
number of values read
Throws:
java.io.IOException - if the number of values exceeds the size of the array, the values are not numbers or are not enclosed in square brackets, or an I/O error occured

scanDoubles

public static double[] scanDoubles(ReaderTokenizer rtok)
                            throws java.io.IOException
Reads a set of double values, enclosed in square brackets [ ], and returns them in an array.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not numbers or are not enclosed in square brackets, or an I/O error occured

scanFloats

public static int scanFloats(float[] vals,
                             ReaderTokenizer rtok)
                      throws java.io.IOException
Reads a set of float values, enclosed in square brackets [ ]. Values are placed in an argument array and the number of values actually read is returned.

Parameters:
vals - array in which values are stored
rtok - Tokenizer from which values are read
Returns:
number of values read
Throws:
java.io.IOException - if the number of values exceeds the size of the array, the values are not numbers or are not enclosed in square brackets, or an I/O error occured

scanFloats

public static float[] scanFloats(ReaderTokenizer rtok)
                          throws java.io.IOException
Reads a set of float values, enclosed in square brackets [ ], and returns them in an array.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not numbers or are not enclosed in square brackets, or an I/O error occured

scanInts

public static int scanInts(int[] vals,
                           ReaderTokenizer rtok)
                    throws java.io.IOException
Reads a set of integer values, enclosed in square brackets [ ]. Values are placed in an argument array and the number of values actually read is returned. Values which exceed the allowed range for integers will be truncated in the high order bits.

Parameters:
vals - array in which values are stored
rtok - Tokenizer from which values are read
Returns:
number of values read
Throws:
java.io.IOException - if the number of values exceeds the size of the array, the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanInts

public static int[] scanInts(ReaderTokenizer rtok)
                      throws java.io.IOException
Reads a set of integer values, enclosed in square brackets [ ], and returns them in an array.Values which exceed the allowed range for integers will be truncated in the high order bits.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanShorts

public static int scanShorts(short[] vals,
                             ReaderTokenizer rtok)
                      throws java.io.IOException
Reads a set of short integer values, enclosed in square brackets [ ]. Values are placed in an argument array and the number of values actually read is returned. Values which exceed the allowed range for shorts will be truncated in the high order bits.

Parameters:
vals - array in which values are stored
rtok - Tokenizer from which values are read
Returns:
number of values read
Throws:
java.io.IOException - if the number of values exceeds the size of the array, the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanShorts

public static short[] scanShorts(ReaderTokenizer rtok)
                          throws java.io.IOException
Reads a set of short integer values, enclosed in square brackets [ ], and returns them in an array. Values which exceed the allowed range for shorts will be truncated in the high order bits.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanLongs

public static int scanLongs(long[] vals,
                            ReaderTokenizer rtok)
                     throws java.io.IOException
Reads a set of long integer values, enclosed in square brackets [ ]. Values are placed in an argument array and the number of values actually read is returned. Values which exceed the allowed range for longs will be truncated in the high order bits.

Parameters:
vals - array in which values are stored
rtok - Tokenizer from which values are read
Returns:
number of values read
Throws:
java.io.IOException - if the number of values exceeds the size of the array, the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanLongs

public static long[] scanLongs(ReaderTokenizer rtok)
                        throws java.io.IOException
Reads a set of long integer values, enclosed in square brackets [ ], and returns them in an array. Values which exceed the allowed range for longs will be truncated in the high order bits.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not integers or are not enclosed in square brackets, or an I/O error occured

scanWords

public static java.lang.String[] scanWords(ReaderTokenizer rtok)
                                    throws java.io.IOException
Reads a set of words values, enclosed in square brackets [ ], and returns them as an array of Strings.

Parameters:
rtok - Tokenizer from which values are read
Returns:
array of values read
Throws:
java.io.IOException - if the values are not words or are not enclosed in square brackets, or an I/O error occured

scanQuotedStrings

public static java.lang.String[] scanQuotedStrings(ReaderTokenizer rtok,
                                                   char quoteChar)
                                            throws java.io.IOException
Reads a set of quoted strings, enclosed in square brackets [ ], and returns them as an array of Strings.

Parameters:
rtok - Tokenizer from which values are read
quoteChar - quote character for the strings
Returns:
array of strings read
Throws:
java.io.IOException - if the strings are not quoted or are not enclosed in square brackets, or an I/O error occured

scanScannable

public static Scannable scanScannable(ReaderTokenizer rtok,
                                      java.lang.Object ref)
                               throws java.io.IOException
Scans a Scannable object, which is preceeded by it's class name. An instance of the object is then created, and is itself then scanned.

Parameters:
rtok - Tokenizer from which values are read
Returns:
scannable object that was read.
Throws:
java.io.IOException - if there was an I/O error or if the Scannable object could not be instantiated.

checkForFieldName

public static boolean checkForFieldName(ReaderTokenizer rtok,
                                        java.lang.String name)
                                 throws java.io.IOException
Checks to see if the next input token corresponds to a specific field name. If not, the token is pushed back and the method returns false. Otherwise, an '=' token is read from the input and the method retuns true.

Parameters:
rtok - Tokenizer from which input is read
name - field name to check for
Returns:
true if the next input token corresponds to the specified field name
Throws:
java.io.IOException - if the field name was present but not followed by an '=' token, or an I/O error occured