uk.org.redfelineninja.util
Class Token

java.lang.Object
  |
  +--uk.org.redfelineninja.util.Token

public class Token
extends java.lang.Object

This class is a companion to the various Java tokenizers. It is an immutable class that initializes itself from the current state of a tokenizer.

It is most tightly intergrated with CommandTokenizer but should work with StreamTokenizer.

See Also:
CommandTokenizer, StreamTokenizer

Field Summary
 double nval
           
 java.lang.String sval
           
static int TT_EOF
           
static int TT_EOL
           
static int TT_NUMBER
           
static int TT_WORD
           
 int ttype
           
 
Constructor Summary
Token(CommandTokenizer tokenizer)
          Create a new Token from a CommandTokenizer.
Token(java.io.StreamTokenizer tokenizer)
          Create a new Token from a StreamTokenizer.
Token(java.io.StreamTokenizer tokenizer, char[] s)
          Create a new Token from a StreamTokenizer.
 
Method Summary
static java.lang.Character getCharacter(java.io.StreamTokenizer tok, char[] quotes)
          Try to get a character from the supplied tokenizer.
static boolean getEOF(java.io.StreamTokenizer tok)
          Test whether the supplied tokenizer has reached the end of a file.
static boolean getEOL(java.io.StreamTokenizer tok)
          Test whether the supplied tokenizer has reached the end of a line.
static java.lang.Double getNumber(java.io.StreamTokenizer tok)
          Try to get a number from the supplied tokenizer.
static java.lang.String getString(java.io.StreamTokenizer tok, char[] quotes)
          Try to get a string from the supplied tokenizer.
static java.lang.String getText(java.io.StreamTokenizer tok, char[] quotes)
          Try to get a text token from the supplied tokenizer.
static java.lang.String getWord(java.io.StreamTokenizer tok)
          Try to get a word from the supplied tokenizer.
 boolean isNumeric()
          Test if the Token is numeric.
 boolean isString()
          Test if the token is a quoted string.
 boolean isText()
          Test if sval is defined for this token.
 boolean isWord()
          Test if the token is a single word.
 java.lang.String toString()
          Convert the current token to printable form.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ttype

public final int ttype

nval

public final double nval

sval

public final java.lang.String sval

TT_EOF

public static final int TT_EOF
See Also:
Constant Field Values

TT_EOL

public static final int TT_EOL
See Also:
Constant Field Values

TT_WORD

public static final int TT_WORD
See Also:
Constant Field Values

TT_NUMBER

public static final int TT_NUMBER
See Also:
Constant Field Values
Constructor Detail

Token

public Token(CommandTokenizer tokenizer)
Create a new Token from a CommandTokenizer. All the methods will work correctly.


Token

public Token(java.io.StreamTokenizer tokenizer)
Create a new Token from a StreamTokenizer. The token will be unable to determine what the string deliminators are, therefore the isString() and isText() methods will throw NullPointerExceptions if called. In addition toString() will no longer return quoted strings, it will simply return a quote character. All information will be preserved.


Token

public Token(java.io.StreamTokenizer tokenizer,
             char[] s)
Create a new Token from a StreamTokenizer. The token will treat the the supplied array of characters are the set of all string deliminators. If that set is correct all the methods will work correctly.

Method Detail

toString

public java.lang.String toString()
Convert the current token to printable form.

Overrides:
toString in class java.lang.Object

isNumeric

public final boolean isNumeric()
Test if the Token is numeric.

Returns:
true if the token is numeric

isWord

public final boolean isWord()
Test if the token is a single word.

Returns:
true if the token is a single word

isString

public final boolean isString()
Test if the token is a quoted string.

Returns:
true if the token is a quoted string

isText

public final boolean isText()
Test if sval is defined for this token.

Returns:
true if sval is defined

getNumber

public static final java.lang.Double getNumber(java.io.StreamTokenizer tok)
                                        throws java.io.IOException
Try to get a number from the supplied tokenizer. If we can't get a number then we call pushBack so the token is not consumed.

Returns:
a Double if the input was interpreted as a number otherwise null
java.io.IOException

getText

public static final java.lang.String getText(java.io.StreamTokenizer tok,
                                             char[] quotes)
                                      throws java.io.IOException
Try to get a text token from the supplied tokenizer. If we can't get text then we call pushBack so the token is not consumed.

Parameters:
tok - the tokenizer
quotes - the characters set in the tokenizer to denote strings
Returns:
a String if the input was interpreted as text otherwise null
java.io.IOException

getString

public static final java.lang.String getString(java.io.StreamTokenizer tok,
                                               char[] quotes)
                                        throws java.io.IOException
Try to get a string from the supplied tokenizer. If we can't get a string then we call pushBack so the token is not consumed.

Parameters:
tok - the tokenizer
quotes - the characters set in the tokenizer to denote strings
Returns:
a String if the input was interpreted as a string otherwize null
java.io.IOException

getWord

public static final java.lang.String getWord(java.io.StreamTokenizer tok)
                                      throws java.io.IOException
Try to get a word from the supplied tokenizer. If we can't get a word then we call pushBack so the token is not consumed.

Parameters:
tok - the tokenizer
Returns:
a String if the input was interpreted as a word otherwize null
java.io.IOException

getCharacter

public static final java.lang.Character getCharacter(java.io.StreamTokenizer tok,
                                                     char[] quotes)
                                              throws java.io.IOException
Try to get a character from the supplied tokenizer. If we can't get a character then we call pushBack so the token is not consumed.

Parameters:
tok - the tokenizer
quotes - the characters set in the tokenizer to denote strings
Returns:
a Character if the input was interpreted as a character otherwize null
java.io.IOException

getEOL

public static final boolean getEOL(java.io.StreamTokenizer tok)
                            throws java.io.IOException
Test whether the supplied tokenizer has reached the end of a line. It is assumed that if we reach the EOF marker then we have also reached the end of the line.

Returns:
true if the end of line or file has been reached, false otherwise and the input is pushed back so the token is not consumed
java.io.IOException
See Also:
StreamTokenizer.eolIsSignificant(boolean)

getEOF

public static final boolean getEOF(java.io.StreamTokenizer tok)
                            throws java.io.IOException
Test whether the supplied tokenizer has reached the end of a file. If the test fails we do not consume the token.

Returns:
true if the end of file has been reached.
java.io.IOException