com.emarsys.ecommon.util
Class ToStringBuilder

java.lang.Object
  extended by com.emarsys.ecommon.util.ToStringBuilder
Direct Known Subclasses:
CollectionToStringBuilder

public class ToStringBuilder
extends java.lang.Object

Provides common default behaviors for Object.toString() implementations.

Author:
Michael "kULO" Kulovits

Field Summary
protected  java.lang.StringBuilder buf
           
protected  char delim
           
static char DELIM
           
 
Constructor Summary
ToStringBuilder()
          Default constructor, creates a new ToStringBuilder instance which uses DELIM as the default delimiter for the toString attributes.
ToStringBuilder(char delim)
          Creates a new ToStringBuilder instance which uses the passed character as the default delimiter for the toString attributes.
 
Method Summary
 ToStringBuilder add(java.lang.Object... objects)
          Appends the String representation of the passed Objects to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.
 ToStringBuilder add(java.lang.Object o)
          Appends the String representation of the passed Object to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.
 ToStringBuilder addAll(java.lang.Iterable<?> it)
          Appends the String representation of the passed Iterable's Object to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.
 ToStringBuilder append(char delimiter, java.lang.Object... objects)
          Appends the String representation of the passed Objects to this ToStringBuilder.
 ToStringBuilder append(java.lang.Object... objects)
          Appends the String representation of the passed Objects to this ToStringBuilder.
 ToStringBuilder append(java.lang.Object o)
          Appends the String representation of the passed Object to this ToStringBuilder.
 ToStringBuilder append(java.lang.Object o, char delimiter)
          Appends the String representation of the passed Object to this ToStringBuilder.
 ToStringBuilder appendAll(char delimiter, java.lang.Iterable<?> it)
          Appends the String representation of the passed Iterable's Objects to this ToStringBuilder.
 ToStringBuilder appendAll(java.lang.Iterable<?> it)
          Appends the String representation of the passed Iterable's Objects to this ToStringBuilder.
static ToStringBuilder getBestFitInstance(java.lang.Object o)
          Returns a new, empty ToStringBuilder instance that fits most for the passed Object.
static ToStringBuilder getDefaultInstance(java.lang.Object o)
          Returns a new ToStringBuilder instance that already contains the passed object's simple class name as a first information.
 char getDelimiter()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DELIM

public static final char DELIM
See Also:
Constant Field Values

buf

protected java.lang.StringBuilder buf

delim

protected char delim
Constructor Detail

ToStringBuilder

public ToStringBuilder()
Default constructor, creates a new ToStringBuilder instance which uses DELIM as the default delimiter for the toString attributes.


ToStringBuilder

public ToStringBuilder(char delim)
Creates a new ToStringBuilder instance which uses the passed character as the default delimiter for the toString attributes.

Parameters:
delim -
Method Detail

getDefaultInstance

public static final ToStringBuilder getDefaultInstance(java.lang.Object o)
Returns a new ToStringBuilder instance that already contains the passed object's simple class name as a first information.

Parameters:
o -
Returns:
a new ToStringBuilder instance with its simple class name appended as first attribute.
See Also:
ToStringBuilder()

getBestFitInstance

public static final ToStringBuilder getBestFitInstance(java.lang.Object o)
Returns a new, empty ToStringBuilder instance that fits most for the passed Object.

Parameters:
o -
Returns:
a newly created ToStringBuilder instance.

append

public ToStringBuilder append(java.lang.Object o)
Appends the String representation of the passed Object to this ToStringBuilder. If its not the first call a DELIMiter will be used to seperate the Strings.

Parameters:
o -
Returns:
this ToStringBuilder

append

public ToStringBuilder append(java.lang.Object... objects)
Appends the String representation of the passed Objects to this ToStringBuilder. A DELIMiter will be used to seperate the Strings.

Parameters:
objects -
Returns:
this ToStringBuilder

appendAll

public ToStringBuilder appendAll(java.lang.Iterable<?> it)
Appends the String representation of the passed Iterable's Objects to this ToStringBuilder. A DELIMiter will be used to seperate the Strings.

Parameters:
objects -
Returns:
this ToStringBuilder

append

public ToStringBuilder append(java.lang.Object o,
                              char delimiter)
Appends the String representation of the passed Object to this ToStringBuilder. If its not the first call the passed delimiter will be used to seperate the Strings.

Parameters:
o -
delimiter -
Returns:
this ToStringBuilder

append

public ToStringBuilder append(char delimiter,
                              java.lang.Object... objects)
Appends the String representation of the passed Objects to this ToStringBuilder. The passed delimiter will be used to seperate the Strings.

Parameters:
delimiter -
objects -
Returns:
this ToStringBuilder

appendAll

public ToStringBuilder appendAll(char delimiter,
                                 java.lang.Iterable<?> it)
Appends the String representation of the passed Iterable's Objects to this ToStringBuilder. The passed delimiter will be used to seperate the Strings.

Parameters:
delimiter -
it -
Returns:
this ToStringBuilder

add

public ToStringBuilder add(java.lang.Object o)
Appends the String representation of the passed Object to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.

Parameters:
o -
Returns:
this ToStringBuilder

add

public ToStringBuilder add(java.lang.Object... objects)
Appends the String representation of the passed Objects to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.

Parameters:
objects -
Returns:
this ToStringBuilder

addAll

public ToStringBuilder addAll(java.lang.Iterable<?> it)
Appends the String representation of the passed Iterable's Object to this ToStringBuilder WITHOUT using a delimiter to seperate it from other toString arguments.

Parameters:
it -
Returns:
this ToStringBuilder

toString

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

getDelimiter

public char getDelimiter()
Returns:
the default delimiter


Copyright © 2010 emarsys AG. All Rights Reserved.