Interface BiConverter<T,​U,​R>

  • Type Parameters:
    T - the type of the first argument to the converter
    U - the type of the second argument to the converter
    R - the type of the result of the converter
    All Superinterfaces:
    BiFunction<T,​U,​R>

    @ParametersAreNonnullByDefault
    public interface BiConverter<T,​U,​R>
    extends BiFunction<T,​U,​R>
    A specialized BiFunction that converts an object of type T to another of type R, by using an object of type U.

    The reverse operation may be strict inverse, meaning that converter.revert(converter.convert(a, c), c).equals(a) always true.

    See Also:
    BiFunction
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default R apply​(T t, U u)  
      R convert​(T t, U u)
      Returns a representation of t as an instance of type R, by using an object of type U.
      static <T,​U,​R>
      BiConverter<T,​U,​R>
      from​(BiFunction<? super T,​? super U,​? extends R> convertFunc, BiFunction<? super R,​? super U,​? extends T> revertFunc)
      Creates a bi-converter based on separate forward and backward functions.
      static <T,​U>
      BiConverter<T,​U,​T>
      identity()
      Creates a bi-converter that always converts or reverses an object to itself.
      default BiConverter<R,​U,​T> reverse()
      Returns the reversed converter of this converter.
      T revert​(R r, U u)
      Returns a representation of r as an instance of type T, by using an object of type U.
    • Method Detail

      • identity

        @Nonnull
        static <T,​U> BiConverter<T,​U,​T> identity()
        Creates a bi-converter that always converts or reverses an object to itself.
        Type Parameters:
        T - the type of the converted instance and the result
        Returns:
        a new converter
      • from

        @Nonnull
        static <T,​U,​R> BiConverter<T,​U,​R> from​(BiFunction<? super T,​? super U,​? extends R> convertFunc,
                                                                       BiFunction<? super R,​? super U,​? extends T> revertFunc)
        Creates a bi-converter based on separate forward and backward functions.
        Type Parameters:
        T - the type of the first argument to the converter
        U - the type of the second argument to the converter
        R - the type of the result of the converter
        Parameters:
        convertFunc - the function used for convert(Object, Object)
        revertFunc - the function used for revert(Object, Object)
        Returns:
        a new converter
      • convert

        R convert​(T t,
                  U u)
        Returns a representation of t as an instance of type R, by using an object of type U.
        Parameters:
        t - the instance to convert
        u - the helper instance
        Returns:
        the converted instance
      • revert

        T revert​(R r,
                 U u)
        Returns a representation of r as an instance of type T, by using an object of type U.
        Parameters:
        r - the instance to convert
        u - the helper instance
        Returns:
        the converted instance
      • reverse

        @Nonnull
        default BiConverter<R,​U,​T> reverse()
        Returns the reversed converter of this converter.
        Returns:
        the reversed converter