public class ToStringBuilder extends Object
String
for
Object.toString()
.
The builder uses a class name and any number of name-value pairs. The format of the output is:
ClassName[name=value,arrayName=[value,value],mapName=[key>value]
Modifier | Constructor and Description |
---|---|
protected |
ToStringBuilder()
Empty constructor; use one of the static methods for creation.
|
Modifier and Type | Method and Description |
---|---|
ToStringBuilder |
append(String name,
boolean value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
boolean[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
byte[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
char value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
char[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
double value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
double[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
float value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
float[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
int value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
int[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
Iterable<?> iterable)
Appends the
name -iterable pair. |
ToStringBuilder |
append(String name,
long value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
long[] values)
Appends the
name -values pair. |
<K,V> ToStringBuilder |
append(String name,
Map<K,V> map)
Appends the
name -map pair. |
ToStringBuilder |
append(String name,
Object value)
Appends the
name -value pair. |
ToStringBuilder |
append(String name,
Object[] values)
Appends the
name -values pair. |
ToStringBuilder |
append(String name,
short[] values)
Appends the
name -values pair. |
static ToStringBuilder |
forClass(Class<?> clazz)
Creates a new
ToStringBuilder for clazz . |
static ToStringBuilder |
forClassName(String className)
Creates a new
ToStringBuilder for className . |
static ToStringBuilder |
forObject(Object object)
Creates a new
ToStringBuilder for object . |
String |
toString() |
protected ToStringBuilder()
public static ToStringBuilder forClassName(String className)
ToStringBuilder
for className
.className
- the name of the Class
whose string is being
builtIllegalArgumentException
- if className
is null
public static ToStringBuilder forClass(Class<?> clazz)
ToStringBuilder
for clazz
. This is
equivalent to calling forClassName(String)
with
Class.getSimpleName()
.clazz
- the Class
whose string is being builtIllegalArgumentException
- if clazz
is null
public static ToStringBuilder forObject(Object object)
ToStringBuilder
for object
. This is
equivalent to calling forClass(Class)
with
Object.getClass()
.object
- the Object
whose string is being builtIllegalArgumentException
- if object
is null
public ToStringBuilder append(String name, Object value)
name
-value
pair. This will use the format
name=value
. The value will use its respective
Object.toString()
, or "null"
will be used if it is
null
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, int value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, long value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, float value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, double value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, char value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, boolean value)
name
-value
pair. This will use the format
name=value
.name
- the name of value
value
- the value to appendIllegalArgumentException
- if name
is null
public <K,V> ToStringBuilder append(String name, Map<K,V> map)
name
-map
pair. This will use the format
name=[key>value,key>value]
. The key and value of map
will use its respective Object.toString()
, or "null"
will be used if it is null
.K
- the type of keyV
- the type of valuename
- the name of map
map
- the Map
to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, Iterable<?> iterable)
name
-iterable
pair. This will use the
format name=[value,value]
. The elements of iterable
will use its Object.toString()
, or "null"
will be used
if it is null
.name
- the name of iterable
iterable
- the Iterable
to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, Object[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
or a value is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, byte[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, short[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, int[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, long[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, float[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, double[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, char[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
public ToStringBuilder append(String name, boolean[] values)
name
-values
pair. This will use the format
name=[value,value]
. Each value of values
will use its
Object.toString()
, or "null"
will be used if
values
is null
.name
- the name of values
values
- the values to appendIllegalArgumentException
- if name
is null
Copyright © 2022 Frostphyr. All rights reserved.