ucb.io
Class InputItem

java.lang.Object
  |
  +--ucb.io.InputItem

public class InputItem
extends java.lang.Object

Represents a data item having one of several different types. The type() function returns a tag indicating the kind of data currently contained. The toXXX() functions return the represented value as an object of type XXX, if sensible. The set(...) functions change the the value represented (and its type).

Each InputItem bears an integer tag, retrievable by the type() function, that indicates the type of value it currently contains:

UNDEFINED
Invalid value (never set).
INT
An integer (toInt() and toLong() are valid).
LONG
A long integer (toLong() is valid).
FLOAT
A float value (toFloat() and toDouble() are valid).
DOUBLE
A double value (toDouble() is valid).
STRING
A String value (toString() is valid).
CHAR
A char or String value (toString() is valid; toChar(), toInt(), or toLong() retrieve the first character).

See Also:
FormatReader

Field Summary
static int CHAR
           
static int DOUBLE
           
static int FLOAT
           
static int INT
           
static int LONG
           
static int STRING
           
static int UNDEFINED
           
 
Constructor Summary
InputItem()
          A new InputItem with an undefined value (type UNDEFINED).
 
Method Summary
 void set(char c)
          Set the value of this to given value, and set type() to CHAR.
 void set(double d)
          Set the value of this to given value, and set type() to DOUBLE.
 void set(float f)
          Set the value of this to given value, and set type() to FLOAT.
 void set(int x)
          Set the value of this to given value, and set type() to INT.
 void set(long x)
          Set the value of this to given value, and set type() to LONG.
 void set(java.lang.String s, int type)
          Set the value of this to given value, and set type() to given type, either CHAR or STRING.
 char toChar()
          The value of this InputItem, if it is of type CHAR.
 double toDouble()
          The value of this InputItem, if it is of type DOUBLE or FLOAT.
 float toFloat()
          The value of this InputItem, if it is of type FLOAT.
 int toInt()
          The value of this InputItem, if it is of type INT or CHAR.
 long toLong()
          The value of this InputItem, if it is of type LONG, INT, or CHAR.
 java.lang.String toString()
          The value of this InputItem, if it is of type CHAR or STRING.
 int type()
          The integer tag (UNDEFINED, INT, LONG, FLOAT, DOUBLE, STRING) representing the current value's type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNDEFINED

public static final int UNDEFINED

INT

public static final int INT

LONG

public static final int LONG

FLOAT

public static final int FLOAT

DOUBLE

public static final int DOUBLE

STRING

public static final int STRING

CHAR

public static final int CHAR
Constructor Detail

InputItem

public InputItem()
A new InputItem with an undefined value (type UNDEFINED).
Method Detail

type

public int type()
The integer tag (UNDEFINED, INT, LONG, FLOAT, DOUBLE, STRING) representing the current value's type.

toDouble

public double toDouble()
                throws java.lang.IllegalArgumentException
The value of this InputItem, if it is of type DOUBLE or FLOAT.

toFloat

public float toFloat()
              throws java.lang.IllegalArgumentException
The value of this InputItem, if it is of type FLOAT.

toInt

public int toInt()
          throws java.lang.IllegalArgumentException
The value of this InputItem, if it is of type INT or CHAR.

toLong

public long toLong()
            throws java.lang.IllegalArgumentException
The value of this InputItem, if it is of type LONG, INT, or CHAR.

toChar

public char toChar()
            throws java.lang.IllegalArgumentException
The value of this InputItem, if it is of type CHAR.

toString

public java.lang.String toString()
The value of this InputItem, if it is of type CHAR or STRING.
Overrides:
toString in class java.lang.Object

set

public void set(double d)
Set the value of this to given value, and set type() to DOUBLE.

set

public void set(float f)
Set the value of this to given value, and set type() to FLOAT.

set

public void set(int x)
Set the value of this to given value, and set type() to INT.

set

public void set(long x)
Set the value of this to given value, and set type() to LONG.

set

public void set(char c)
Set the value of this to given value, and set type() to CHAR.

set

public void set(java.lang.String s,
                int type)
Set the value of this to given value, and set type() to given type, either CHAR or STRING.