Package org.atlanmod.commons.function
Interface Converter<T,R>
-
- Type Parameters:
T- the type of the input to the converterR- the type of the result of the converter
- All Superinterfaces:
Function<T,R>
- All Known Subinterfaces:
BinarySerializer<T>,Serializer<T,U>,StringSerializer<T>
- All Known Implementing Classes:
AbstractBinarySerializer,AbstractStringSerializer
@ParametersAreNonnullByDefault public interface Converter<T,R> extends Function<T,R>
A specializedFunctionthat converts an object of typeTto another of typeR.The reverse operation may be strict inverse, meaning that
converter.revert(converter.convert(a)).equals(a)alwaystrue.- See Also:
Function
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Rapply(T t)static <T,U,R>
Converter<T,R>compose(Converter<T,U> before, Converter<U,R> after)Returns a composed converter that first applies thebeforefunction to its input, and then applies theafterfunction to the result.Rconvert(T t)Returns a representation oftas an instance of typeR.static <T,R>
Converter<T,R>from(Function<? super T,? extends R> convertFunc, Function<? super R,? extends T> revertFunc)Creates a converter based on separate forward and backward functions.static <T> Converter<T,T>identity()Creates a converter that always converts or reverses an object to itself.default Converter<R,T>reverse()Returns the reversed converter of this converter.Trevert(R r)Returns a representation ofras an instance of typeT.
-
-
-
Method Detail
-
identity
@Nonnull static <T> Converter<T,T> identity()
Creates a 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,R> Converter<T,R> from(Function<? super T,? extends R> convertFunc, Function<? super R,? extends T> revertFunc)
Creates a converter based on separate forward and backward functions.- Type Parameters:
T- the type of the input to the converterR- the type of the result of the converter- Parameters:
convertFunc- the function used forconvert(Object)revertFunc- the function used forrevert(Object)- Returns:
- a new converter
-
compose
@Nonnull static <T,U,R> Converter<T,R> compose(Converter<T,U> before, Converter<U,R> after)
Returns a composed converter that first applies thebeforefunction to its input, and then applies theafterfunction to the result. This behavior is inverted when callingrevert(Object).- Type Parameters:
T- the type of input to thebeforeconverter, and to the composed functionU- the intermediate typeR- the type of output of theafterconverter, and of the composed function- Parameters:
before- the first converterafter- the second converter- Returns:
- a composed converter
-
convert
R convert(T t)
Returns a representation oftas an instance of typeR.- Parameters:
t- the instance to convert- Returns:
- the converted instance
-
revert
T revert(R r)
Returns a representation ofras an instance of typeT.- Parameters:
r- the instance to convert- Returns:
- the converted instance
-
-