Package io.cui.tools.formatting
Configurable formatting for complex structures
The Problem
Provide a text representation for given complex object. As a plus the formatting should be easily configurable with a simple DSL-style template language.
The Solution
The io.cui.tools.formatting framework presented here.
The starting point is FormatterSupport providing two
methods:
FormatterSupport.getSupportedPropertyNames(): Provides the property names that can be used for formattingFormatterSupport.getAvailablePropertyValues(): Provides a name with with the supported names and values.
The other interface needed is TemplateFormatter defining
the method
TemplateFormatter.format(io.cui.tools.formatting.template.FormatterSupport)
doing the actual formatting.
Sample
Dto PersonName implementingFormatterSupport
final PersonName personName = PersonName.builder()
.setFamilyName("Fischers")
.setGivenName("Fritz")
.setMiddleName("Felix")
.setGivenNameSuffix("Dr.")
.build();
final TemplateFormatter<PersonName> formatter = TemplateFormatterImpl.builder()
.useTemplate("[familyName], [givenName], [middleName] [givenNameSuffix]")
.forType(PersonName.class);
assertEquals("Fischers, Fritz, Felix Dr.", formatter.format(personName));
-
Class Summary Class Description SimpleFormatter Provide concatenation of strings by using String.join(CharSequence, CharSequence...).SimpleFormatter.SimpleFormatterBuilder Internal Builder representationSimpleFormatter.SimpleFormatterBuilder.BuilderWithStrategy Internal Builder representation incorporating a strategy -
Enum Summary Enum Description SimpleFormatter.ValueHandling