-
public abstract class StringifierThe
Stringifierclass provides the ability to define Class -> String conversions using the Definition DSL.A subclass of
Stringifiershould only ever be instantiated once, which is when it is loaded. This is because it is preferable to declare a subclass as anobjectinstead of aclass, as it reduces the redundancy caused by running the configuration constructor property more than once.
-
-
Constructor Summary
Constructors Constructor Description Stringifier(Function1<Stringifier, Unit> configuration)
-
Method Summary
Modifier and Type Method Description final StringgetIndent()The indentation string that is appended before every print in a Definition if the indentation level is higher than 0. final UnitsetIndent(String indent)The indentation string that is appended before every print in a Definition if the indentation level is higher than 0. final <T extends Any> Unitdefine(Function2<Definition, T, String> conversion)Defines a new conversion for this Stringifier.final <T extends Any> Stringconvert(T obj, Definition definition)Converts an object to a Stringusing a conversion gotten from the object's type.-
-
Constructor Detail
-
Stringifier
Stringifier(Function1<Stringifier, Unit> configuration)
- Parameters:
configuration- The configuration for this stringifier, allows declaring conversions upon class initialization.
-
-
Method Detail
-
getIndent
final String getIndent()
The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.
By default, this string is a single tab character,
\t.
-
setIndent
final Unit setIndent(String indent)
The indentation string that is appended before every print in a Definition if the indentation level is higher than 0.
By default, this string is a single tab character,
\t.
-
define
final <T extends Any> Unit define(Function2<Definition, T, String> conversion)
Defines a new conversion for this
Stringifier.A conversion produces a
String, given an object with the type of the specified type parameter, and the receiver type of a conversion is a Definition.- Parameters:
conversion- the conversion to be defined
-
convert
final <T extends Any> String convert(T obj, Definition definition)
Converts an object to a
Stringusing a conversion gotten from the object's type.- Parameters:
obj- the object to be converted based upon its classdefinition- a Definition instance that is used to convert the object to aString
-
-
-
-