Class Mappers

java.lang.Object
com.helixframework.mapper.Mappers

public final class Mappers extends Object
Factory and composition helpers for mapper types.
  • Method Details

    • to

      public static <A, B> ToMapper<A,B> to(BiFunction<A,MappingContext,B> toFunction)
      Creates a one-way mapper from a mapping function.
      Type Parameters:
      A - the source type
      B - the target type
      Parameters:
      toFunction - the mapping function
      Returns:
      the mapper
    • from

      public static <A, B> FromMapper<A,B> from(BiFunction<B,MappingContext,A> fromFunction)
      Creates a reverse one-way mapper from a mapping function.
      Type Parameters:
      A - the target type
      B - 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 type
      B - the target type
      Parameters:
      toFunction - the forward mapping function
      fromFunction - the reverse mapping function
      Returns:
      the mapper
    • combine

      public static <A, B> Mapper<A,B> combine(ToMapper<A,B> toMapper, FromMapper<A,B> fromMapper)
      Creates a bidirectional mapper from one-way mapper implementations.
      Type Parameters:
      A - the source type
      B - the target type
      Parameters:
      toMapper - the forward mapper
      fromMapper - the reverse mapper
      Returns:
      the mapper
    • compose

      public static <A, B, C> Mapper<A,C> compose(Mapper<A,B> first, Mapper<B,C> second)
      Composes two bidirectional mappers.
      Type Parameters:
      A - the initial source type
      B - the intermediate type
      C - the final target type
      Parameters:
      first - the first mapper
      second - 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 type
      B - the target type
      Parameters:
      mapper - the mapper to wrap
      contextDecorator - the context decorator
      Returns:
      the wrapped mapper
    • decorate

      public static <A, B> Mapper<A,B> decorate(Mapper<A,B> mapper, MapperDecorator<A,B> decorator)
      Wraps a mapper with a named decorator.
      Type Parameters:
      A - the source type
      B - the target type
      Parameters:
      mapper - the mapper to decorate
      decorator - the decorator to apply
      Returns:
      the decorated mapper