Package com.helixframework.mapper
Class Mappers
java.lang.Object
com.helixframework.mapper.Mappers
Factory and composition helpers for mapper types.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> Mapper<A, B> combine(ToMapper<A, B> toMapper, FromMapper<A, B> fromMapper) Creates a bidirectional mapper from one-way mapper implementations.static <A,B, C> Mapper<A, C> Composes two bidirectional mappers.static <A,B> Mapper<A, B> decorate(Mapper<A, B> mapper, MapperDecorator<A, B> decorator) Wraps a mapper with a named decorator.static <A,B> FromMapper<A, B> from(BiFunction<B, MappingContext, A> fromFunction) Creates a reverse one-way mapper from a mapping function.static <A,B> Mapper<A, B> of(BiFunction<A, MappingContext, B> toFunction, BiFunction<B, MappingContext, A> fromFunction) Creates a bidirectional mapper from two mapping functions.static <A,B> ToMapper<A, B> to(BiFunction<A, MappingContext, B> toFunction) Creates a one-way mapper from a mapping function.static <A,B> Mapper<A, B> wrap(Mapper<A, B> mapper, UnaryOperator<MappingContext> contextDecorator) Wraps a mapper with a context decorator.
-
Method Details
-
to
Creates a one-way mapper from a mapping function.- Type Parameters:
A- the source typeB- the target type- Parameters:
toFunction- the mapping function- Returns:
- the mapper
-
from
Creates a reverse one-way mapper from a mapping function.- Type Parameters:
A- the target typeB- the source type- Parameters:
fromFunction- the mapping function- Returns:
- the mapper
-
of
public static <A,B> Mapper<A,B> of(BiFunction<A, MappingContext, B> toFunction, BiFunction<B, MappingContext, A> fromFunction) Creates a bidirectional mapper from two mapping functions.- Type Parameters:
A- the source typeB- the target type- Parameters:
toFunction- the forward mapping functionfromFunction- the reverse mapping function- Returns:
- the mapper
-
combine
Creates a bidirectional mapper from one-way mapper implementations.- Type Parameters:
A- the source typeB- the target type- Parameters:
toMapper- the forward mapperfromMapper- the reverse mapper- Returns:
- the mapper
-
compose
Composes two bidirectional mappers.- Type Parameters:
A- the initial source typeB- the intermediate typeC- the final target type- Parameters:
first- the first mappersecond- the second mapper- Returns:
- the composed mapper
-
wrap
public static <A,B> Mapper<A,B> wrap(Mapper<A, B> mapper, UnaryOperator<MappingContext> contextDecorator) Wraps a mapper with a context decorator.- Type Parameters:
A- the source typeB- the target type- Parameters:
mapper- the mapper to wrapcontextDecorator- the context decorator- Returns:
- the wrapped mapper
-
decorate
Wraps a mapper with a named decorator.- Type Parameters:
A- the source typeB- the target type- Parameters:
mapper- the mapper to decoratedecorator- the decorator to apply- Returns:
- the decorated mapper
-