org.openbp.common.util
Class ToStringHelper

java.lang.Object
  extended by org.openbp.common.util.ToStringHelper

public final class ToStringHelper
extends java.lang.Object

Helper class for convenient implementation of toString methods.

Author:
Erich Lauterbach

Field Summary
static int HASHCODE
          Flag for toString: Display hashcode
static int TOSTRING_ABBREVIATED_CLASSNAME
          Flag for toString: Display abbreviated classname
static int TOSTRING_QUALIFIED_CLASSNAME
          Flag for toString: Display qualified classname
static int TOSTRING_UNQUALIFIED_CLASSNAME
          Flag for toString: Display unqualified classname
 
Method Summary
static java.lang.String toString(java.lang.Object o)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String[] properties)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1, java.lang.String property2)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1, java.lang.String property2, java.lang.String property3)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1, java.lang.String property2, java.lang.String property3, java.lang.String property4)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1, java.lang.String property2, java.lang.String property3, java.lang.String property4, java.lang.String property5)
          Returns a string representation of the given object.
static java.lang.String toString(java.lang.Object o, java.lang.String property1, java.lang.String property2, java.lang.String property3, java.lang.String property4, java.lang.String property5, java.lang.String property6)
          Returns a string representation of the given object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOSTRING_QUALIFIED_CLASSNAME

public static final int TOSTRING_QUALIFIED_CLASSNAME
Flag for toString: Display qualified classname

See Also:
Constant Field Values

TOSTRING_ABBREVIATED_CLASSNAME

public static final int TOSTRING_ABBREVIATED_CLASSNAME
Flag for toString: Display abbreviated classname

See Also:
Constant Field Values

TOSTRING_UNQUALIFIED_CLASSNAME

public static final int TOSTRING_UNQUALIFIED_CLASSNAME
Flag for toString: Display unqualified classname

See Also:
Constant Field Values

HASHCODE

public static final int HASHCODE
Flag for toString: Display hashcode

See Also:
Constant Field Values
Method Detail

toString

public static java.lang.String toString(java.lang.Object o)
Returns a string representation of the given object. Convencience method for stateless objects.


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1)
Returns a string representation of the given object. Convencience method for toString(Object,String [])


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1,
                                        java.lang.String property2)
Returns a string representation of the given object. Convencience method for toString(Object, String [])


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1,
                                        java.lang.String property2,
                                        java.lang.String property3)
Returns a string representation of the given object. Convencience method for Object.toString()


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1,
                                        java.lang.String property2,
                                        java.lang.String property3,
                                        java.lang.String property4)
Returns a string representation of the given object. Convencience method for toString(Object, String [])


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1,
                                        java.lang.String property2,
                                        java.lang.String property3,
                                        java.lang.String property4,
                                        java.lang.String property5)
Returns a string representation of the given object. Convencience method for toString(Object, String [])


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String property1,
                                        java.lang.String property2,
                                        java.lang.String property3,
                                        java.lang.String property4,
                                        java.lang.String property5,
                                        java.lang.String property6)
Returns a string representation of the given object. Convencience method for toString(Object, String [])


toString

public static java.lang.String toString(java.lang.Object o,
                                        java.lang.String[] properties)
Returns a string representation of the given object. This method is a standard implemention of the toString method. It will generate a string containing basic object information (see below) and the values of the given properties, which are queried using reflection.

Parameters:
o - Object to display
properties - Table of object properties to display
Returns:
Either "(null)" if 'o' is null or the class name of the object (either qualified or unqualified, dependent on the value of toStringFlags), followed by the hash code of the object as known from the standard implementation of Object.toString.

Example:

"java.lang.Object@83AF"
or
"Object@83AF"

if 'properties' is not null, the given properties will be appended, separated by a new line and indented by two spaces.
Given the properties { "Name", "DisplayName", "Description" } and a DisplayObject the return value may look like:

"DisplayObject@83AF"
" Name = TestObject"
" DisplayName = Test object"
" Description = This is a test object"
If the property inspection causes an exception, "*ERROR*" will be printed as property value.


Copyright © 2011. All Rights Reserved.