Class EntityString

java.lang.Object
com.dianxin.tori.base.utils.EntityString

public final class EntityString extends Object
Fluent builder utility for constructing clean, formatted toString() representations.

Example usage:


 @Override
 public String toString() {
     return new EntityString(this)
         .add("id", 123)
         .add("name", "Tori")
         .toString();
 }
 

Output: ClassName{id=123, name=Tori}

  • Constructor Details

    • EntityString

      public EntityString(@NotNull @NotNull Object entity)
      Initializes an entity string using the runtime class of the provided instance.
      Parameters:
      entity - the object instance
    • EntityString

      public EntityString(@NotNull @NotNull Class<?> clazz)
      Initializes an entity string using the specified class metadata.
      Parameters:
      clazz - the target class
    • EntityString

      public EntityString(@NotNull @NotNull String name)
      Initializes an entity string using an explicit header identifier.
      Parameters:
      name - the explicit entity name prefix
  • Method Details

    • add

      public EntityString add(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Appends a key-value pair to the output string.
      Parameters:
      key - the attribute name
      value - the attribute value (serialized as "null" if null)
      Returns:
      this builder instance
    • addString

      public EntityString addString(@NotNull @NotNull String key, @Nullable @Nullable String value)
      Appends a key-value pair with explicit quotes around the string value (e.g., name="Tori").
      Parameters:
      key - the attribute name
      value - the string value
      Returns:
      this builder instance
    • addIfNotNull

      public EntityString addIfNotNull(@NotNull @NotNull String key, @Nullable @Nullable Object value)
      Conditionally appends a key-value pair only when the value is not null.
      Parameters:
      key - the attribute name
      value - the attribute value
      Returns:
      this builder instance
    • toString

      public String toString()
      Overrides:
      toString in class Object