Top Description Fields Constructors Methods
org.springframework.core.style

public Class ToStringCreator

extends Object
Class Inheritance
Imports
org.springframework.lang.Nullable, org.springframework.util.Assert

Utility class that builds pretty-printing toString() methods with pluggable styling conventions. By default, ToStringCreator adheres to Spring's toString() styling conventions.
Authors
Keith Donald, Juergen Hoeller
Since
1.2.2

Field Summary

Modifier and TypeField and Description
private final StringBuilder
private static final ToStringStyler
DEFAULT_TO_STRING_STYLER

Default ToStringStyler instance used by this ToStringCreator.

private final Object
private boolean
private final ToStringStyler

Constructor Summary

AccessConstructor and Description
public
ToStringCreator(Object
the object to be stringified
obj
)

Create a ToStringCreator for the given object.

public
ToStringCreator(Object
the object to be stringified
obj
,
ValueStyler
the ValueStyler encapsulating pretty-print instructions
styler
)

Create a ToStringCreator for the given object, using the provided style.

public
ToStringCreator(Object
the object to be stringified
obj
,
ToStringStyler
the ToStringStyler encapsulating pretty-print instructions
styler
)

Create a ToStringCreator for the given object, using the provided style.

Method Summary

Modifier and TypeMethod and Description
public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
byte
the field value
value
)

Append a byte field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
short
the field value
value
)

Append a short field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
int
the field value
value
)

Append a integer field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
long
the field value
value
)

Append a long field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
float
the field value
value
)

Append a float field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
double
the field value
value
)

Append a double field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
boolean
the field value
value
)

Append a boolean field value.

public ToStringCreator

Returns:

this, to support call-chaining
append
(String
the name of the field, usually the member variable name
fieldName
,
Object
the field value
value
)

Append a field value.

public ToStringCreator

Returns:

this, to support call-chaining.
append
(Object
the value to append
value
)

Append the provided value.

private void
public String
toString()

Overrides java.lang.Object.toString.

Return the String representation that this ToStringCreator built.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufferback to summary
private final StringBuilder buffer
DEFAULT_TO_STRING_STYLERback to summary
private static final ToStringStyler DEFAULT_TO_STRING_STYLER

Default ToStringStyler instance used by this ToStringCreator.

objectback to summary
private final Object object
styledFirstFieldback to summary
private boolean styledFirstField
stylerback to summary
private final ToStringStyler styler

Constructor Detail

ToStringCreatorback to summary
public ToStringCreator(Object obj)

Create a ToStringCreator for the given object.

Parameters
obj:Object

the object to be stringified

ToStringCreatorback to summary
public ToStringCreator(Object obj, ValueStyler styler)

Create a ToStringCreator for the given object, using the provided style.

Parameters
obj:Object

the object to be stringified

styler:ValueStyler

the ValueStyler encapsulating pretty-print instructions

ToStringCreatorback to summary
public ToStringCreator(Object obj, ToStringStyler styler)

Create a ToStringCreator for the given object, using the provided style.

Parameters
obj:Object

the object to be stringified

styler:ToStringStyler

the ToStringStyler encapsulating pretty-print instructions

Method Detail

appendback to summary
public ToStringCreator append(String fieldName, byte value)

Append a byte field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:byte

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, short value)

Append a short field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:short

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, int value)

Append a integer field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:int

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, long value)

Append a long field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:long

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, float value)

Append a float field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:float

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, double value)

Append a double field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:double

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, boolean value)

Append a boolean field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:boolean

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(String fieldName, Object value)

Append a field value.

Parameters
fieldName:String

the name of the field, usually the member variable name

value:Object

the field value

Returns:ToStringCreator

this, to support call-chaining

appendback to summary
public ToStringCreator append(Object value)

Append the provided value.

Parameters
value:Object

the value to append

Returns:ToStringCreator

this, to support call-chaining.

printFieldSeparatorIfNecessaryback to summary
private void printFieldSeparatorIfNecessary()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return the String representation that this ToStringCreator built.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override