-
public final class DefinitionThe Definition class houses a DSL for building a string from the properties of an object. It maintains indentation level and provides operators and utilities for working with strings.
-
-
Field Summary
Fields Modifier and Type Field Description private final StringBuildercontentprivate final Stringifierstrprivate Integerindent
-
Constructor Summary
Constructors Constructor Description Definition(Stringifier str, Integer indent)
-
Method Summary
Modifier and Type Method Description final StringBuildergetContent()final StringifiergetStr()final IntegergetIndent()final UnitsetIndent(Integer indent)final Stringcontent(Function1<Definition, Unit> definition)Wraps execution around a block that returns the string result of this definition's content. final Unitindent(Integer indent, Function1<Definition, Unit> definition)Sets the indentation level for the specified block. final Unitindent(Function1<Definition, Unit> definition)Increments the indentation level for the specified block before decrementing it after said block is called. final <T extends Any> Stringconvert(T obj)Copies this Definition and provides the parent Stringifier with it and the specified object. final <T extends Any> Stringconvert(List<T> $self, CharSequence separator, CharSequence prefix, CharSequence postfix, Integer limit, CharSequence truncated)Converts every element in the list with the parent Stringifier and joins it to a string. final StringBuilderunaryPlus(Object $self)Adds a value to the content of this definition as a string, applying indentation beforehand. final StringBuilderunaryMinus(Object $self)Adds a value to the content of this definition as a string without applying indentation. final Definitioncopy()Creates a copy of this definition with the same indentation level and parent stringifier. -
-
Constructor Detail
-
Definition
Definition(Stringifier str, Integer indent)
- Parameters:
str- the stringifier this definition belongs toindent- the current indentation level
-
-
Method Detail
-
getContent
final StringBuilder getContent()
-
getStr
final Stringifier getStr()
-
content
final String content(Function1<Definition, Unit> definition)
Wraps execution around a block that returns the string result of this definition's content.
- Parameters:
definition- a block of code that is executed immediately
-
indent
final Unit indent(Integer indent, Function1<Definition, Unit> definition)
Sets the indentation level for the specified block.
- Parameters:
indent- the new indentation level for the blockdefinition- the block this level applies to
-
indent
final Unit indent(Function1<Definition, Unit> definition)
Increments the indentation level for the specified block before decrementing it after said block is called.
- Parameters:
definition- the block the incremented level applies to
-
convert
final <T extends Any> String convert(T obj)
Copies this Definition and provides the parent Stringifier with it and the specified object.
- Parameters:
obj- an object to pass to the stringifier for conversion
-
convert
final <T extends Any> String convert(List<T> $self, CharSequence separator, CharSequence prefix, CharSequence postfix, Integer limit, CharSequence truncated)
Converts every element in the list with the parent Stringifier and joins it to a string.
-
unaryPlus
final StringBuilder unaryPlus(Object $self)
Adds a value to the content of this definition as a string, applying indentation beforehand.
-
unaryMinus
final StringBuilder unaryMinus(Object $self)
Adds a value to the content of this definition as a string without applying indentation.
-
copy
final Definition copy()
Creates a copy of this definition with the same indentation level and parent stringifier.
-
-
-
-