Class RendererAdapter<T,​S>

  • Type Parameters:
    T - The input type for the renderer.
    S - The output type for the renderer.
    All Implemented Interfaces:
    Renderer<T,​S>

    public class RendererAdapter<T,​S>
    extends Object
    implements Renderer<T,​S>
    Adapter class for chaining together two renderers in series to provide flexibility. For example, if we have a Long -> Date renderer that turns a number of milliseconds since epoch into a Java date, and a Date -> String renderer that converts a Java date into its String representation in a particular locale, we can combine the two to create a Long -> String renderer without having to write a separate implementation of the Renderer interface.
    • Constructor Detail

      • RendererAdapter

        public RendererAdapter​(Renderer<T,​? extends R> renderer1,
                               Renderer<R,​S> renderer2)
        Creates an adapter that feeds the output of renderer1 into renderer2.
        Type Parameters:
        R - The intermediate type when transforming objects of type T to objects of type S.
        Parameters:
        renderer1 - A renderer that will translate an object of the input type (T) into an object of the intermediate type (R).
        renderer2 - A renderer that will translate an object of the intermediate type (R) into an object of the output type (S).
    • Method Detail

      • render

        public S render​(T entity)
        Renders an object of one type as an instance of another. For example, if the generic types of this renderer are Date and String, this method would return a String representation of a Date.
        Specified by:
        render in interface Renderer<T,​S>
        Parameters:
        entity - An object to render as a different type.
        Returns:
        A rendering of the parameter.