de.dante.extex.interpreter.type.tokens
Class Tokens

java.lang.Object
  extended byde.dante.extex.interpreter.type.tokens.Tokens
All Implemented Interfaces:
FixedTokens, java.io.Serializable
Direct Known Subclasses:
ImmutableTokens, MacroPattern

public class Tokens
extends java.lang.Object
implements java.io.Serializable, FixedTokens

This class is a container for a list of Tokens.

Version:
$Revision: 1.24 $
Author:
Gerd Neugebauer, Michael Niedermair
See Also:
Serialized Form

Field Summary
static Tokens EMPTY
          This constant is the empty token register.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
Tokens()
          Creates a new object which does not contain any elements.
Tokens(Context context, java.lang.CharSequence s)
          Creates a new object
Tokens(Context context, long num)
          Creates a new object
Tokens(Token t)
          Creates a new object.
 
Method Summary
 void add(Token t)
          Add another token to the end of the Tokens.
 void add(TokenFactory factory, java.lang.CharSequence s)
          Add all characters from the given String to the list of Tokens.
 void add(Tokens toks)
          Add another token list to the end of the Tokens.
 void clear()
          This method removes all elements from the tokens list.
 boolean equals(java.lang.Object object)
           
 Token get(int i)
          Get a specified token from the toks register.
 int hashCode()
           
 void insert(int index, Token t)
          Add a token to the list at a certain position.
 int length()
          Getter for the length of the token register, this is the number of elements contained.
 Token removeLast()
          Remove the last token from the list and return it.
 void show(Context context, Tokens toks)
          Determine the printable representation of the object and append it to a list of Tokens.
 java.lang.String toString()
          Return a String, which show all tokens in the list.
 void toString(java.lang.StringBuffer sb)
          Print the token into a StringBuffer.
 java.lang.String toText()
          Return a String, which shows all tokens (in text format) in the list.
 java.lang.String toText(UnicodeChar esc)
          Return a String, which shows all tokens (in text format) in the list.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

public static final Tokens EMPTY
This constant is the empty token register.


serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values
Constructor Detail

Tokens

public Tokens()
Creates a new object which does not contain any elements.


Tokens

public Tokens(Context context,
              long num)
       throws InterpreterException
Creates a new object

Each character is converted into a OtherToken and added to the internal list.

Parameters:
context - the interpreter context
num - the number to add
Throws:
InterpreterException - in case of an error

Tokens

public Tokens(Context context,
              java.lang.CharSequence s)
       throws InterpreterException
Creates a new object

Each character of the string is converted into a OtherToken and added to the internal list. An exception is made for spaces which are converted into a SpaceToken.

Parameters:
context - the interpreter context
s - the characters to add in a CharSequence
Throws:
InterpreterException - in case of an error

Tokens

public Tokens(Token t)
Creates a new object.

Parameters:
t - the initial token
Method Detail

add

public void add(Token t)
Add another token to the end of the Tokens.

Parameters:
t - The token to add

add

public void add(TokenFactory factory,
                java.lang.CharSequence s)
         throws CatcodeException
Add all characters from the given String to the list of Tokens. If the string is null then it is ignored: i.e. it is treated like the empty string. The Tokens all have the catcode OTHER with exception of spaces which have the catcode SPACE.

Parameters:
factory - the TokenFactory to acquire new Tokens from
s - the characters to add in a CharSequence
Throws:
CatcodeException - in case of an error

add

public void add(Tokens toks)
Add another token list to the end of the Tokens.

Parameters:
toks - the tokens to add

clear

public void clear()
This method removes all elements from the tokens list. Afterwards the list is empty.


equals

public boolean equals(java.lang.Object object)
See Also:
Object.equals(java.lang.Object)

get

public Token get(int i)
Get a specified token from the toks register.

Specified by:
get in interface FixedTokens
Parameters:
i - the index for the token to get
Returns:
the ith token or null if i is out of bounds

hashCode

public int hashCode()
See Also:
Object.hashCode()

insert

public void insert(int index,
                   Token t)
Add a token to the list at a certain position.

Parameters:
index - the index to add the token to
t - the token to add

length

public int length()
Getter for the length of the token register, this is the number of elements contained.

Specified by:
length in interface FixedTokens
Returns:
the number of elements in the token register

removeLast

public Token removeLast()
Remove the last token from the list and return it. If the list is empty then null is returned.

Returns:
the last token or null

show

public void show(Context context,
                 Tokens toks)
          throws CatcodeException
Description copied from interface: FixedTokens
Determine the printable representation of the object and append it to a list of Tokens.

Specified by:
show in interface FixedTokens
Parameters:
context - the processor context
toks - the tokens to add to
Throws:
CatcodeException
See Also:
FixedTokens.show( de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.type.tokens.Tokens)

toString

public java.lang.String toString()
Return a String, which show all tokens in the list.

Specified by:
toString in interface FixedTokens
Returns:
a String, which show all tokens in the list

toString

public void toString(java.lang.StringBuffer sb)
Print the token into a StringBuffer.

Parameters:
sb - the target string buffer

toText

public java.lang.String toText()
Description copied from interface: FixedTokens
Return a String, which shows all tokens (in text format) in the list.

Specified by:
toText in interface FixedTokens
Returns:
a String, which show all tokens (in text format) in the list
See Also:
FixedTokens.toText()

toText

public java.lang.String toText(UnicodeChar esc)
Description copied from interface: FixedTokens
Return a String, which shows all tokens (in text format) in the list.

Specified by:
toText in interface FixedTokens
Parameters:
esc - the escape character to use
Returns:
a String, which show all tokens (in text format) in the list
See Also:
FixedTokens.toText(UnicodeChar)