Class ToStringHelper


  • public final class ToStringHelper
    extends Object
    Extracted from com.google.common.base.MoreObjects#toStringHelper.
    Since:
    18.0 (since 2.0 as Objects.ToStringHelper).
    Author:
    Jason Lee
    • Constructor Detail

      • ToStringHelper

        public ToStringHelper​(Object subject)
      • ToStringHelper

        public ToStringHelper​(String className)
    • Method Detail

      • add

        public ToStringHelper add​(String name,
                                  @Nullable
                                  Object value)
        Adds a name/value pair to the formatted output in name=value format. If value is null this name/value pair will not be added.
      • add

        public ToStringHelper add​(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 ToStringHelper add​(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 ToStringHelper add​(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 ToStringHelper add​(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 ToStringHelper add​(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 ToStringHelper add​(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()).
      • toString

        public String toString()
        Returns a string.

        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 Object