Class Objects.ToStringHelper
- java.lang.Object
-
- com.google.common.base.Objects.ToStringHelper
-
- Enclosing class:
- Objects
public static final class Objects.ToStringHelper extends java.lang.Object
Support class forObjects.toStringHelper(java.lang.Object)
.- Since:
- 2.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objects.ToStringHelper
add(java.lang.String name, boolean value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, char value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, double value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, float value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, int value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, long value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
add(java.lang.String name, java.lang.Object value)
Adds a name/value pair to the formatted output inname=value
format.Objects.ToStringHelper
addValue(boolean value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(char value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(double value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(float value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(int value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(long value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
addValue(java.lang.Object value)
Adds an unnamed value to the formatted output.Objects.ToStringHelper
omitNullValues()
Configures theObjects.ToStringHelper
sotoString()
will ignore properties with null value.java.lang.String
toString()
Returns a string in the format specified byObjects.toStringHelper(Object)
.
-
-
-
Method Detail
-
omitNullValues
public Objects.ToStringHelper omitNullValues()
Configures theObjects.ToStringHelper
sotoString()
will ignore properties with null value. The order of calling this method, relative to theadd()
/addValue()
methods, is not significant.- Since:
- 12.0
-
add
public Objects.ToStringHelper add(java.lang.String name, @Nullable java.lang.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
public Objects.ToStringHelper add(java.lang.String name, boolean value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
add
public Objects.ToStringHelper add(java.lang.String name, char value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
add
public Objects.ToStringHelper add(java.lang.String name, double value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
add
public Objects.ToStringHelper add(java.lang.String name, float value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
add
public Objects.ToStringHelper add(java.lang.String name, int value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
add
public Objects.ToStringHelper add(java.lang.String name, long value)
Adds a name/value pair to the formatted output inname=value
format.- Since:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.ToStringHelper addValue(@Nullable java.lang.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
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
addValue
public Objects.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:
- 11.0 (source-compatible since 2.0)
-
toString
public java.lang.String toString()
Returns a string in the format specified byObjects.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).
- Overrides:
toString
in classjava.lang.Object
-
-