View Javadoc
1   package org.pojomatic.formatter;
2   
3   import org.pojomatic.Pojomator;
4   import org.pojomatic.PropertyElement;
5   
6   /**
7    * A formatter to aid in creating a {@code String} representation of a POJO.
8    *
9    * Any implementation of {@code EnhancedPojoFormatter} must have a public no-argument constructor. A new instance will
10   * be created for each time that {@link Pojomator#doToString(Object)} is called. Consequently, implementations do
11   * <em>not</em> need to be thread safe.
12   *
13   * @since 2.0
14   * @see DefaultEnhancedPojoFormatter
15   */
16  @SuppressWarnings("deprecation")
17  public interface EnhancedPojoFormatter extends PojoFormatter {
18    /**
19     * Append the {@code String} which should appear at the beginning of the result of
20     * {@code toString()} to the supplied StringBuilder.
21     *
22     * @param builder the builder to append to.
23     * @param pojoClass the class for which {@code toString()} is being called
24     * @see Object#toString()
25     */
26    void appendToStringPrefix(StringBuilder builder, Class<?> pojoClass);
27  
28    /**
29     * Append the {@code String} which should appear at the end of the result of
30     * {@code toString()} to the supplied StringBuilder.
31     *
32     * @param builder the builder to append to.
33     * @param pojoClass the class for which {@code toString()} is being called
34     * @see Object#toString()
35     */
36    void appendToStringSuffix(StringBuilder builder, Class<?> pojoClass);
37  
38    /**
39     * Append the {@code String} prefix for a given {@code PropertyElement} to the supplied
40     * StringBuilder. This method will be called once for each property used in the result of
41     * {@code toString()}, in the order in which those properties will appear in that result,
42     * and before the call to {@link PropertyFormatter#format(Object)} for the property's value.
43     *
44     * @param builder the builder to append to.
45     * @param property the property for which to generate a prefix
46     */
47    void appendPropertyPrefix(StringBuilder builder, PropertyElement property);
48  
49    /**
50     * Append the {@code String} suffix for a given {@code PropertyElement} to the supplied
51     * StringBuilder. This method will be called once after each call to
52     * {@link PropertyFormatter#format(Object)} for the property's value.
53     *
54     * @param builder the builder to append to.
55     * @param property the property for which to generate a suffix
56     */
57    void appendPropertySuffix(StringBuilder builder, PropertyElement property);
58  }