MoreObjects.ToStringHelper
Date: 2016-05-24

com.google.common.base

## Class MoreObjects.ToStringHelper

- java.lang.Object
- - com.google.common.base.MoreObjects.ToStringHelper

- Enclosing class:
    MoreObjects

      public static final class MoreObjects.ToStringHelper
      extends java.lang.Object

  Support class for `MoreObjects.toStringHelper(java.lang.Object)`.
  Since:
    18.0 (since 2.0 as `Objects.ToStringHelper`).

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, boolean value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, char value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, double value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, float value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, int value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, long value)` Adds a name/value pair to the formatted output in `name=value` format.
    `MoreObjects.ToStringHelper` | `add(java.lang.String name, java.lang.Object value)` Adds a name/value pair to the formatted output in `name=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(java.lang.Object value)` Adds an unnamed value to the formatted output.
    `MoreObjects.ToStringHelper` | `omitNullValues()` Configures the `MoreObjects.ToStringHelper` so `toString()` will ignore properties with null value.
    `java.lang.String` | `toString()` Returns a string in the format specified by `MoreObjects.toStringHelper(Object)`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### omitNullValues

          public MoreObjects.ToStringHelper omitNullValues()

      Configures the `MoreObjects.ToStringHelper` so `toString()` will ignore properties with null value. The order of calling this method, relative to the `add()`/`addValue()` methods, is not significant.
      Since:
        18.0 (since 12.0 as `Objects.ToStringHelper.omitNullValues()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       @Nullable
                                       java.lang.Object value)

      Adds a name/value pair to the formatted output in `name=value` format. If `value` is `null`, the string `"null"` is used, unless `omitNullValues()` is called, in which case this name/value pair will not be added.

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       boolean value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       char value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       double value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       float value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       int value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### add

          public MoreObjects.ToStringHelper add(java.lang.String name,
                                       long value)

      Adds a name/value pair to the formatted output in `name=value` format.
      Since:
        18.0 (since 11.0 as `Objects.ToStringHelper.add()`).

    - #### addValue

          public MoreObjects.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 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

          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

          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

          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

          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

          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

          @CheckReturnValue
          public java.lang.String toString()

      Returns a string in the format specified by `MoreObjects.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 class `java.lang.Object`