org.extex.scanner.type.tokens
Class Tokens

java.lang.Object
  extended by org.extex.scanner.type.tokens.Tokens
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Token>, FixedTokens
Direct Known Subclasses:
ImmutableTokens, MacroPattern

public class Tokens
extends java.lang.Object
implements java.io.Serializable, FixedTokens, java.lang.Iterable<Token>

This class is a container for a list of Tokens.

Version:
$Revision:4399 $
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(Token t)
          Creates a new object.
 
Method Summary
 void add(Token t)
          Add another token to the end of the 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()
          Returns a hash code value for the object.
 void insert(int index, Token t)
          Add a token to the list at a certain position.
 java.util.Iterator<Token> iterator()
          
 int length()
          Getter for the length of the token register, this is the number of elements contained.
 Token pop()
          Remove the first toke from the list and return it.
 void push(Token token)
          Push a token to the front of the list.
 Token removeFirst()
          Remove the last token from the list and return it.
 Token removeLast()
          Remove the last token from the list and return it.
 void show(Tokens toks, TokenFactory factory, long esc)
          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.
 void toString(java.lang.StringBuilder sb)
          Print the token into a StringBuilder.
 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(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(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)

Overrides:
equals in class java.lang.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()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
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

iterator

public java.util.Iterator<Token> iterator()

Specified by:
iterator in interface java.lang.Iterable<Token>
See Also:
Iterable.iterator()

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

pop

public Token pop()
Remove the first toke from the list and return it.

Returns:
the token taken from the from the front of the list or null if the list is empty

push

public void push(Token token)
Push a token to the front of the list.

Parameters:
token - the token to push

removeFirst

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

Returns:
the first token or null

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(Tokens toks,
                 TokenFactory factory,
                 long esc)
          throws CatcodeException
Determine the printable representation of the object and append it to a list of Tokens.

Parameters:
toks - the tokens to add to
factory - the token factory
esc - the escape character
Throws:
CatcodeException - in case of an error

toString

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

Specified by:
toString in interface FixedTokens
Overrides:
toString in class java.lang.Object
Returns:
a String, which show all tokens in the list

toString

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

Parameters:
sb - the target string builder

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()
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)
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)