Module de.cuioss.java.tools
Package de.cuioss.tools.formatting
package de.cuioss.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 de.cuioss.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(de.cuioss.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));
-
ClassDescriptionProvide concatenation of strings by using String.join(CharSequence, CharSequence...).Internal Builder representationInternal Builder representation incorporating a strategy