Package com.dianxin.tori.base.utils
Class EntityString
java.lang.Object
com.dianxin.tori.base.utils.EntityString
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 Summary
ConstructorsConstructorDescriptionEntityString(@NotNull Class<?> clazz) Initializes an entity string using the specified class metadata.EntityString(@NotNull Object entity) Initializes an entity string using the runtime class of the provided instance.EntityString(@NotNull String name) Initializes an entity string using an explicit header identifier. -
Method Summary
Modifier and TypeMethodDescriptionAppends a key-value pair to the output string.addIfNotNull(@NotNull String key, @Nullable Object value) Conditionally appends a key-value pair only when the value is not null.Appends a key-value pair with explicit quotes around the string value (e.g.,name="Tori").toString()
-
Constructor Details
-
EntityString
Initializes an entity string using the runtime class of the provided instance.- Parameters:
entity- the object instance
-
EntityString
Initializes an entity string using the specified class metadata.- Parameters:
clazz- the target class
-
EntityString
Initializes an entity string using an explicit header identifier.- Parameters:
name- the explicit entity name prefix
-
-
Method Details
-
add
Appends a key-value pair to the output string.- Parameters:
key- the attribute namevalue- the attribute value (serialized as"null"if null)- Returns:
- this builder instance
-
addString
Appends a key-value pair with explicit quotes around the string value (e.g.,name="Tori").- Parameters:
key- the attribute namevalue- the string value- Returns:
- this builder instance
-
addIfNotNull
Conditionally appends a key-value pair only when the value is not null.- Parameters:
key- the attribute namevalue- the attribute value- Returns:
- this builder instance
-
toString
-