org.basex.util
Class TokenBuilder

java.lang.Object
  extended by org.basex.util.TokenBuilder

public final class TokenBuilder
extends Object

This class serves as an efficient constructor for byte arrays. It bears some resemblance to Java's StringBuilder.

Author:
Workgroup DBIS, University of Konstanz 2005-10, ISC License, Christian Gruen

Field Summary
 boolean ent
          Entity flag.
 
Constructor Summary
TokenBuilder()
          Empty constructor.
TokenBuilder(byte[] str)
          Constructor, specifying an initial array.
TokenBuilder(int i)
          Constructor, specifying an initial array size.
TokenBuilder(String str)
          Constructor, specifying an initial string.
 
Method Summary
 TokenBuilder add(byte b)
          Adds a single character to the token.
 TokenBuilder add(byte[] b)
          Adds a byte array to the token.
 void add(byte[] b, int s, int e)
          Adds a partial byte array to the token.
 TokenBuilder add(char ch)
          Adds a single character to the token.
 TokenBuilder add(int i)
          Adds an integer to the token.
 TokenBuilder add(Object str, Object... ext)
          Replaces all % characters in the input string by the specified extension objects, which can be byte arrays or any other object.
 TokenBuilder add(String s)
          Adds a string to the token.
 TokenBuilder addUTF(int c)
          Adds the specified UTF8 character.
 void chop()
          Chops leading and trailing whitespaces.
 byte[] finish()
          Returns the token as byte array.
 TokenBuilder high()
          Adds a highlight flag.
 TokenBuilder hl()
          Adds a half new line.
 TokenBuilder nl()
          Adds a new line.
 TokenBuilder norm()
          Adds a norm flag.
 void reset()
          Resets the token buffer.
 int size()
          Returns the number of entries.
 String toString()
           
 boolean wsp()
          Returns true if the token only contains whitespaces.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ent

public boolean ent
Entity flag.

Constructor Detail

TokenBuilder

public TokenBuilder()
Empty constructor.


TokenBuilder

public TokenBuilder(int i)
Constructor, specifying an initial array size.

Parameters:
i - size

TokenBuilder

public TokenBuilder(String str)
Constructor, specifying an initial string.

Parameters:
str - initial string

TokenBuilder

public TokenBuilder(byte[] str)
Constructor, specifying an initial array.

Parameters:
str - initial string
Method Detail

size

public int size()
Returns the number of entries.

Returns:
number of entries

reset

public void reset()
Resets the token buffer.


high

public TokenBuilder high()
Adds a highlight flag. This flag is evaluated by the text renderer in the frontend.

Returns:
self reference

norm

public TokenBuilder norm()
Adds a norm flag. This flag is evaluated by the text renderer in the frontend.

Returns:
self reference

nl

public TokenBuilder nl()
Adds a new line. This flag is evaluated by the text renderer in the frontend.

Returns:
self reference

hl

public TokenBuilder hl()
Adds a half new line. This flag is evaluated by the text renderer in the frontend.

Returns:
self reference

add

public TokenBuilder add(char ch)
Adds a single character to the token.

Parameters:
ch - the character to be added
Returns:
self reference

add

public TokenBuilder add(byte b)
Adds a single character to the token.

Parameters:
b - the character to be added
Returns:
self reference

addUTF

public TokenBuilder addUTF(int c)
Adds the specified UTF8 character.

Parameters:
c - the character to be added
Returns:
self reference

add

public TokenBuilder add(int i)
Adds an integer to the token.

Parameters:
i - the integer to be added
Returns:
self reference

add

public TokenBuilder add(byte[] b)
Adds a byte array to the token.

Parameters:
b - the character array to be added
Returns:
self reference

add

public void add(byte[] b,
                int s,
                int e)
Adds a partial byte array to the token.

Parameters:
b - the character array to be added
s - start position
e - end position

add

public TokenBuilder add(String s)
Adds a string to the token.

Parameters:
s - the string to be added
Returns:
self reference

add

public TokenBuilder add(Object str,
                        Object... ext)
Replaces all % characters in the input string by the specified extension objects, which can be byte arrays or any other object. If a digit is found after %, it is interpreted as insertion position.

Parameters:
str - query information
ext - text text extensions
Returns:
self reference

chop

public void chop()
Chops leading and trailing whitespaces.


wsp

public boolean wsp()
Returns true if the token only contains whitespaces.

Returns:
result of check

finish

public byte[] finish()
Returns the token as byte array.

Returns:
character array

toString

public String toString()
Overrides:
toString in class Object