org.h2.util
Class StatementBuilder

java.lang.Object
  extended by org.h2.util.StatementBuilder

public class StatementBuilder
extends java.lang.Object

A utility class to build a statement. In addition to the methods supported by StringBuilder, it allows to add a text only in the second iteration. This simplified constructs such as:

 StringBuilder buff = new StringBuilder();
 for (int i = 0; i < args.length; i++) {
     if (i > 0) {
         buff.append(", ");
     }
     buff.append(args[i]);
 }
 
to
 StatementBuilder buff = new StatementBuilder();
 for (String s : args) {
     buff.appendExceptFirst(", ");
     buff.append(a);
 }


Constructor Summary
StatementBuilder()
          Create a new builder.
StatementBuilder(java.lang.String string)
          Create a new builder.
 
Method Summary
 StatementBuilder append(char c)
          Append a character.
 StatementBuilder append(long x)
          Append a number.
 StatementBuilder append(java.lang.String s)
          Append a text.
 void appendExceptFirst(java.lang.String s)
          Append a text, except when this method is called the first time.
 void appendOnlyFirst(java.lang.String s)
          Append a text, but only if appendExceptFirst was never called.
 int length()
          Get the length.
 StatementBuilder resetCount()
          Reset the loop counter.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StatementBuilder

public StatementBuilder()
Create a new builder.


StatementBuilder

public StatementBuilder(java.lang.String string)
Create a new builder.

Parameters:
string - the initial string
Method Detail

append

public StatementBuilder append(java.lang.String s)
Append a text.

Parameters:
s - the text to append
Returns:
itself

append

public StatementBuilder append(char c)
Append a character.

Parameters:
c - the character to append
Returns:
itself

append

public StatementBuilder append(long x)
Append a number.

Parameters:
x - the number to append
Returns:
itself

resetCount

public StatementBuilder resetCount()
Reset the loop counter.

Returns:
itself

appendOnlyFirst

public void appendOnlyFirst(java.lang.String s)
Append a text, but only if appendExceptFirst was never called.

Parameters:
s - the text to append

appendExceptFirst

public void appendExceptFirst(java.lang.String s)
Append a text, except when this method is called the first time.

Parameters:
s - the text to append

toString

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

length

public int length()
Get the length.

Returns:
the length