org.basex.util.list
Class TokenList

java.lang.Object
  extended by org.basex.util.list.ElementList
      extended by org.basex.util.list.TokenList
All Implemented Interfaces:
java.lang.Iterable<byte[]>

public final class TokenList
extends ElementList
implements java.lang.Iterable<byte[]>

This is a simple container for tokens (byte arrays).

Author:
BaseX Team 2005-13, BSD License, Christian Gruen

Field Summary
 
Fields inherited from class org.basex.util.list.ElementList
factor, size
 
Constructor Summary
TokenList()
          Default constructor.
TokenList(byte[][] tokens)
          Lightweight constructor, adopting the specified array.
TokenList(double resize)
          Constructor, specifying a resize factor.
TokenList(int capacity)
          Constructor, specifying an initial internal array size (default is Array.CAPACITY).
TokenList(java.lang.String[] strings)
          Constructor, adopting the elements from the specified array.
TokenList(TokenSet set)
          Constructor, adopting the elements from the specified set.
 
Method Summary
 void add(byte[] element)
          Adds an element.
 void add(long element)
          Adds a long value.
 void add(java.lang.String element)
          Adds a string.
 boolean contains(byte[] element)
          Checks if the specified element is found in the list.
 TokenList copy()
          Creates a copy of this list.
 void deleteAt(int index)
          Deletes the element at the specified position.
 byte[] get(int index)
          Returns the element at the specified position.
 void insert(int index, byte[][] elements)
          Inserts the given elements at the specified position.
 java.util.Iterator<byte[]> iterator()
           
 byte[] peek()
          Returns the uppermost element on the stack, without removing it.
 byte[] pop()
          Pops the uppermost element from the stack.
 void push(byte[] element)
          Pushes an element onto the stack.
 void set(int index, byte[] element)
          Stores an element to the specified position.
 TokenList sort(boolean cs)
          Sorts the elements.
 byte[][] toArray()
          Returns an array with all elements.
 java.lang.String toString()
           
 java.lang.String[] toStringArray()
          Returns an array with all elements as strings.
 
Methods inherited from class org.basex.util.list.ElementList
isEmpty, newSize, newSize, reset, size, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TokenList

public TokenList()
Default constructor.


TokenList

public TokenList(int capacity)
Constructor, specifying an initial internal array size (default is Array.CAPACITY).

Parameters:
capacity - initial array capacity

TokenList

public TokenList(double resize)
Constructor, specifying a resize factor. Smaller values are more memory-saving, while larger will provide better performance.

Parameters:
resize - resize factor

TokenList

public TokenList(byte[][] tokens)
Lightweight constructor, adopting the specified array.

Parameters:
tokens - initial array

TokenList

public TokenList(java.lang.String[] strings)
Constructor, adopting the elements from the specified array.

Parameters:
strings - initial array

TokenList

public TokenList(TokenSet set)
Constructor, adopting the elements from the specified set.

Parameters:
set - set to be added
Method Detail

add

public void add(byte[] element)
Adds an element.

Parameters:
element - element to be added

add

public void add(long element)
Adds a long value.

Parameters:
element - element to be added

add

public void add(java.lang.String element)
Adds a string.

Parameters:
element - element to be added

insert

public void insert(int index,
                   byte[][] elements)
Inserts the given elements at the specified position.

Parameters:
index - inserting position
elements - elements to insert

deleteAt

public void deleteAt(int index)
Deletes the element at the specified position.

Parameters:
index - index of the element to delete

get

public byte[] get(int index)
Returns the element at the specified position.

Parameters:
index - index of the element to return
Returns:
element

set

public void set(int index,
                byte[] element)
Stores an element to the specified position.

Parameters:
index - index of the element to replace
element - element to be stored

pop

public byte[] pop()
Pops the uppermost element from the stack.

Returns:
the popped element

push

public void push(byte[] element)
Pushes an element onto the stack.

Parameters:
element - element

peek

public byte[] peek()
Returns the uppermost element on the stack, without removing it.

Returns:
uppermost element

contains

public boolean contains(byte[] element)
Checks if the specified element is found in the list.

Parameters:
element - element to be found
Returns:
result of check

toArray

public byte[][] toArray()
Returns an array with all elements.

Returns:
array

toStringArray

public java.lang.String[] toStringArray()
Returns an array with all elements as strings.

Returns:
array

sort

public TokenList sort(boolean cs)
Sorts the elements.

Parameters:
cs - respect case sensitivity
Returns:
self reference

iterator

public java.util.Iterator<byte[]> iterator()
Specified by:
iterator in interface java.lang.Iterable<byte[]>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

copy

public TokenList copy()
Creates a copy of this list.

Returns:
copy of this list