org.basex.util
Class TokenBuilder

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

public final class TokenBuilder
extends java.lang.Object

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

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

Field Summary
static byte BOLD
          Bold flag.
static byte HLINE
          Half new line.
static byte MARK
          Mark flag.
static byte NLINE
          New line.
static byte NORM
          Standard flag.
static byte ULINE
          Underline flag.
 
Constructor Summary
TokenBuilder()
          Empty constructor.
TokenBuilder(byte[] token)
          Constructor, specifying an initial token.
TokenBuilder(int capacity)
          Constructor, specifying an initial internal array size.
TokenBuilder(java.lang.String string)
          Constructor, specifying an initial string.
 
Method Summary
 TokenBuilder add(byte[] value)
          Adds a byte array to the token.
 TokenBuilder add(byte[] value, int start, int end)
          Adds part of a byte array to the token.
 TokenBuilder add(int cp)
          Adds the specified UTF8 codepoint.
 TokenBuilder add(java.lang.String string)
          Adds a string to the token.
 TokenBuilder addByte(byte value)
          Adds a byte to the token.
 TokenBuilder addExt(java.lang.Object object, java.lang.Object... ext)
          Adds the string representation of an object: objects of type Throwable are converted to a string representation via Util.message(java.lang.Throwable). objects of type Class are converted via Util.name(Class). null references are replaced by the string "null". byte arrays are directly inserted as tokens. for all other typed, Object.toString() is called. The specified string may contain "%" characters as place holders.
 TokenBuilder addInt(int value)
          Adds an integer value to the token.
 TokenBuilder addLong(long value)
          Adds a number to the token.
 TokenBuilder addSep(java.lang.Object[] objects, java.lang.String sep)
          Adds multiple strings to the token, separated by the specified string.
 TokenBuilder bold()
          Adds a bold flag.
 int cl(int pos)
          Returns the length of the codepoints stored at the specified position.
 int cp(int pos)
          Returns the codepoint stored at the specified position.
 void delete(int pos, int length)
          Deletes bytes from the token.
 byte[] finish()
          Returns the token as byte array.
 byte get(int pos)
          Returns the byte stored at the specified position.
 TokenBuilder hline()
          Adds a half new line.
 TokenBuilder insert(int pos, int cp)
          Inserts the specified UTF8 character.
 boolean isEmpty()
          Tests if the token is empty.
 TokenBuilder nline()
          Adds a new line.
 TokenBuilder norm()
          Adds a norm flag.
 TokenBuilder reset()
          Resets the token buffer.
 void set(int pos, byte value)
          Sets a byte at the specified position.
 int size()
          Returns the number of bytes.
 void size(int s)
          Sets the number of bytes.
 java.lang.String toString()
           
 TokenBuilder trim()
          Trims leading and trailing whitespaces.
 TokenBuilder uline()
          Adds an underline toggle flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HLINE

public static final byte HLINE
Half new line.

See Also:
Constant Field Values

BOLD

public static final byte BOLD
Bold flag.

See Also:
Constant Field Values

NORM

public static final byte NORM
Standard flag.

See Also:
Constant Field Values

MARK

public static final byte MARK
Mark flag.

See Also:
Constant Field Values

ULINE

public static final byte ULINE
Underline flag.

See Also:
Constant Field Values

NLINE

public static final byte NLINE
New line.

See Also:
Constant Field Values
Constructor Detail

TokenBuilder

public TokenBuilder()
Empty constructor.


TokenBuilder

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

Parameters:
capacity - initial array capacity

TokenBuilder

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

Parameters:
string - initial string

TokenBuilder

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

Parameters:
token - initial token
Method Detail

size

public int size()
Returns the number of bytes.

Returns:
number of bytes

size

public void size(int s)
Sets the number of bytes. Note that no bound check is performed by this method.

Parameters:
s - number of bytes

isEmpty

public boolean isEmpty()
Tests if the token is empty.

Returns:
result of check

reset

public TokenBuilder reset()
Resets the token buffer.

Returns:
self reference

bold

public TokenBuilder bold()
Adds a bold flag. This method should only be called to control text rendering in the visual front end.

Returns:
self reference

uline

public TokenBuilder uline()
Adds an underline toggle flag. This method should only be called to control text rendering in the visual front end.

Returns:
self reference

norm

public TokenBuilder norm()
Adds a norm flag. This method should only be called to control text rendering in the visual front end.

Returns:
self reference

nline

public TokenBuilder nline()
Adds a new line. This method should only be called to control text rendering in the visual front end.

Returns:
self reference

hline

public TokenBuilder hline()
Adds a half new line. This method should only be called to control text rendering in the visual front end.

Returns:
self reference

add

public TokenBuilder add(int cp)
Adds the specified UTF8 codepoint.

Parameters:
cp - the codepoint to be added
Returns:
self reference

insert

public TokenBuilder insert(int pos,
                           int cp)
Inserts the specified UTF8 character.

Parameters:
pos - insertion position
cp - the character to be added
Returns:
self reference

cp

public int cp(int pos)
Returns the codepoint stored at the specified position.

Parameters:
pos - position
Returns:
character

cl

public int cl(int pos)
Returns the length of the codepoints stored at the specified position.

Parameters:
pos - position
Returns:
character

get

public byte get(int pos)
Returns the byte stored at the specified position.

Parameters:
pos - position
Returns:
byte

set

public void set(int pos,
                byte value)
Sets a byte at the specified position.

Parameters:
value - byte to be set
pos - position

delete

public void delete(int pos,
                   int length)
Deletes bytes from the token.

Parameters:
pos - position
length - number of bytes to be removed

addByte

public TokenBuilder addByte(byte value)
Adds a byte to the token. ByteList instances should be preferred for the construction of pure byte arrays.

Parameters:
value - the byte to be added
Returns:
self reference

addInt

public TokenBuilder addInt(int value)
Adds an integer value to the token.

Parameters:
value - value to be added
Returns:
self reference

addLong

public TokenBuilder addLong(long value)
Adds a number to the token.

Parameters:
value - value to be added
Returns:
self reference

add

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

Parameters:
value - the byte array to be added
Returns:
self reference

add

public TokenBuilder add(byte[] value,
                        int start,
                        int end)
Adds part of a byte array to the token.

Parameters:
value - the byte array to be added
start - start position
end - end position
Returns:
self reference

add

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

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

addSep

public TokenBuilder addSep(java.lang.Object[] objects,
                           java.lang.String sep)
Adds multiple strings to the token, separated by the specified string.

Parameters:
objects - the object to be added
sep - separator string
Returns:
self reference

addExt

public TokenBuilder addExt(java.lang.Object object,
                           java.lang.Object... ext)
Adds the string representation of an object: The specified string may contain "%" characters as place holders. All place holders will be replaced by the specified extensions. If a digit is specified after the place holder character, it will be interpreted as insertion position.

Parameters:
object - string to be extended
ext - optional extensions
Returns:
self reference

trim

public TokenBuilder trim()
Trims leading and trailing whitespaces.

Returns:
self reference

finish

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

Returns:
character array

toString

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