Class MoreObjects.ToStringHelper
- java.lang.Object
-
- com.google.common.base.MoreObjects.ToStringHelper
-
- Enclosing class:
- MoreObjects
public static final class MoreObjects.ToStringHelper extends Object
Support class forMoreObjects.toStringHelper(java.lang.Object)
.- Since:
- 18.0 (since 2.0 as
Objects.ToStringHelper
). - Author:
- Jason Lee
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MoreObjects.ToStringHelper
add(String name, boolean value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, char value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, double value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, float value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, int value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, long value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
add(String name, Object value)
Adds a name/value pair to the formatted output inname=value
format.MoreObjects.ToStringHelper
addValue(boolean value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(char value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(double value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(float value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(int value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(long value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
addValue(Object value)
Adds an unnamed value to the formatted output.MoreObjects.ToStringHelper
omitEmptyValues()
Configures theMoreObjects.ToStringHelper
sotoString()
will ignore properties with empty values.MoreObjects.ToStringHelper
omitNullValues()
Configures theMoreObjects.ToStringHelper
sotoString()
will ignore properties with null value.String
toString()
Returns a string in the format specified byMoreObjects.toStringHelper(Object)
.
-
-
-
Method Detail
-
omitNullValues
@CanIgnoreReturnValue public MoreObjects.ToStringHelper omitNullValues()
Configures theMoreObjects.ToStringHelper
sotoString()
will ignore properties with null value. The order of calling this method, relative to theadd()
/addValue()
methods, is not significant.- Since:
- 18.0 (since 12.0 as
Objects.ToStringHelper.omitNullValues()
).
-
omitEmptyValues
@CanIgnoreReturnValue public MoreObjects.ToStringHelper omitEmptyValues()
Configures theMoreObjects.ToStringHelper
sotoString()
will ignore properties with empty values. The order of calling this method, relative to theadd()
/addValue()
methods, is not significant.Note: in general, code should assume that the string form returned by
ToStringHelper
for a given object may change. In particular, the list of types which are checked for emptiness is subject to change. We currently checkCharSequence
s,Collection
s,Map
s, optionals (including Guava's), and arrays.- Since:
- NEXT
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, @CheckForNull Object value)
Adds a name/value pair to the formatted output inname=value
format. Ifvalue
isnull
, the string"null"
is used, unlessomitNullValues()
is called, in which case this name/value pair will not be added.
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, boolean value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, char value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, double value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, float value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, int value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
add
@CanIgnoreReturnValue public MoreObjects.ToStringHelper add(String name, long value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.add()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(@CheckForNull Object value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, Object)
instead and give value a readable name.
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(boolean value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, boolean)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(char value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, char)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(double value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, double)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(float value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, float)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(int value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, int)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
addValue
@CanIgnoreReturnValue public MoreObjects.ToStringHelper addValue(long value)
Adds an unnamed value to the formatted output.It is strongly encouraged to use
add(String, long)
instead and give value a readable name.- Since:
- 18.0 (since 11.0 as
Objects.ToStringHelper.addValue()
).
-
toString
public String toString()
Returns a string in the format specified byMoreObjects.toStringHelper(Object)
.After calling this method, you can keep adding more properties to later call toString() again and get a more complete representation of the same object; but properties cannot be removed, so this only allows limited reuse of the helper instance. The helper allows duplication of properties (multiple name/value pairs with the same name can be added).
-
-