Package com.helger.commons.string
Class ToStringGenerator
- java.lang.Object
-
- com.helger.commons.string.ToStringGenerator
-
@NotThreadSafe public final class ToStringGenerator extends Object
This is a utility class for easiertoStringmethod creations. It assumes that thetoStringmethod is only used for the representation of the internal state and not for creating human readable formats.A real world example for a final class derived from
Objector a base class looks like this:@Override public String toString () { return new ToStringGenerator (this).append ("member1", member1).append ("member2", member2).toString (); }For a derived class, the typical code looks like this, assuming that the base class also used the
ToStringGenerator:@Override public String toString () { return ToStringGenerator.getDerived (super.toString ()) .append ("member3", member3) .append ("member4", member4) .toString (); }- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONSTANT_NULLString to be emitted fornullvaluesstatic StringCONSTANT_PASSWORDString to be emited for password valuesstatic StringCONSTANT_THISString to be emitted forthisvalues
-
Constructor Summary
Constructors Constructor Description ToStringGenerator(Object aSrc)
-
Method Summary
-
-
-
Field Detail
-
CONSTANT_NULL
public static final String CONSTANT_NULL
String to be emitted fornullvalues- See Also:
- Constant Field Values
-
CONSTANT_THIS
public static final String CONSTANT_THIS
String to be emitted forthisvalues- See Also:
- Constant Field Values
-
CONSTANT_PASSWORD
public static final String CONSTANT_PASSWORD
String to be emited for password values- See Also:
- Constant Field Values
-
-
Method Detail
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, boolean aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable boolean[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, byte aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable byte[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, char aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable char[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, double aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable double[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, float aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable float[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, int aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable int[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, long aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable long[] aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, short aValue)
-
append
@Nonnull public ToStringGenerator append(@Nonnull String sField, @Nullable short[] aValue)
-
appendPassword
@Nonnull public ToStringGenerator appendPassword(@Nonnull String sField)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, boolean bValue, @Nonnull IBooleanPredicate aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, boolean bValue, @Nonnull BooleanSupplier aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, char cValue, @Nonnull ICharPredicate aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, char cValue, @Nonnull BooleanSupplier aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, int nValue, @Nonnull IntPredicate aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, int nValue, @Nonnull BooleanSupplier aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, long nValue, @Nonnull LongPredicate aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, long nValue, @Nonnull BooleanSupplier aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, double dValue, @Nonnull DoublePredicate aFilter)
-
appendIf
@Nonnull public ToStringGenerator appendIf(@Nonnull String sField, double dValue, @Nonnull BooleanSupplier aFilter)
-
appendIf
@Nonnull public <T> ToStringGenerator appendIf(@Nonnull String sField, @Nullable T aValue, @Nonnull Predicate<? super T> aFilter)
-
appendIf
@Nonnull public <T> ToStringGenerator appendIf(@Nonnull String sField, @Nullable T aValue, @Nonnull BooleanSupplier aFilter)
-
appendIfNotNull
@Nonnull public ToStringGenerator appendIfNotNull(@Nonnull String sField, @Nullable Object aValue)
-
appendPasswordIf
@Nonnull public ToStringGenerator appendPasswordIf(@Nonnull String sField, BooleanSupplier aFilter)
-
toString
@Nonnull @Deprecated(forRemoval=false) public String toString()
Deprecated.Don't call this; UsegetToString()instead
-
getDerived
@Nonnull public static ToStringGenerator getDerived(@Nonnull String sSuperToString)
Create aToStringGeneratorfor derived classes where the base class also uses theToStringGenerator. This avoids that the implementing class name is emitted more than once.- Parameters:
sSuperToString- Always pass insuper.toString ()- Returns:
- Never
null
-
-