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:

The other interface needed is TemplateFormatter defining the method TemplateFormatter.format(de.cuioss.tools.formatting.template.FormatterSupport) doing the actual formatting.

Sample

Dto PersonName implementing FormatterSupport
 

 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));