Interface Translator<T,​R>

  • Type Parameters:
    T - the input type
    R - the output type
    All Known Implementing Classes:
    CustomTranslatorExample.JavaSerializerTranslator

    public interface Translator<T,​R>
    Responsible for translating data value of type T to the value of type R, which is then consumed by the end user services.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default <R1> Translator<T,​R1> chain​(Translator<R,​R1> translator)
      Chains the provided translator R->R1 to the current T->R.
      static <T,​R>
      Translator<T,​R>
      define​(java.util.function.Function<T,​R> translate, java.lang.Class<T> inputType, java.lang.Class<R> outputType)
      Helper method for defining a T->R translator from the translation function and two data types.
      java.lang.Class<T> inputType()  
      java.lang.Class<R> outputType()  
      default <T1> Translator<T1,​R> prepend​(java.util.function.Function<T1,​T> factory, java.lang.Class<T1> inputType)
      Prepends the provided factory to the current translator T->R.
      R translate​(T resource)
      Performs the actual translation.
    • Method Detail

      • translate

        R translate​(T resource)
        Performs the actual translation.
        Parameters:
        resource - input resource
        Returns:
        translated instance
      • inputType

        java.lang.Class<T> inputType()
        Returns:
        input T class
      • outputType

        java.lang.Class<R> outputType()
        Returns:
        output R class
      • define

        static <T,​R> Translator<T,​R> define​(java.util.function.Function<T,​R> translate,
                                                        java.lang.Class<T> inputType,
                                                        java.lang.Class<R> outputType)
        Helper method for defining a T->R translator from the translation function and two data types.
        Type Parameters:
        T - input type
        R - output type
        Parameters:
        translate - actual translator from T to R
        inputType - input T class
        outputType - output R class
        Returns:
        complete T->R translator
      • chain

        default <R1> Translator<T,​R1> chain​(Translator<R,​R1> translator)
        Chains the provided translator R->R1 to the current T->R.

        The resulting translator is T->R->R1.

        Type Parameters:
        R1 - final result type
        Parameters:
        translator - translator to be chained
        Returns:
        the chained translator
      • prepend

        default <T1> Translator<T1,​R> prepend​(java.util.function.Function<T1,​T> factory,
                                                    java.lang.Class<T1> inputType)
        Prepends the provided factory to the current translator T->R.

        The resulting translator is T1->T->R.

        Type Parameters:
        T1 - input type
        Parameters:
        factory - prepending translator function
        inputType - input T1 class
        Returns:
        the prepended translator