Class ConverterRegistry

java.lang.Object
com.oorian.data.converter.ConverterRegistry

public final class ConverterRegistry extends Object
Registry for bidirectional type converters.

Provides automatic lookup of Converter instances by presentation and model type pair. All built-in converters are pre-registered at class-load time.

Usage:


 // Look up a built-in converter
 Converter<String, Integer> converter = ConverterRegistry.find(String.class, Integer.class);

 // Register a custom converter
 ConverterRegistry.register(String.class, Money.class, new StringToMoneyConverter());
 
Since:
2.1
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Method Details

    • register

      public static <P, M> void register(Class<P> presentationType, Class<M> modelType, Converter<P,M> converter)
      Registers a converter for the given presentation and model type pair.

      If a converter is already registered for the same type pair, it is replaced.

      Type Parameters:
      P - the presentation type
      M - the model type
      Parameters:
      presentationType - the presentation class
      modelType - the model class
      converter - the converter instance
    • find

      public static <P, M> Converter<P,M> find(Class<P> presentationType, Class<M> modelType)
      Finds a converter for the given presentation and model type pair.
      Type Parameters:
      P - the presentation type
      M - the model type
      Parameters:
      presentationType - the presentation class
      modelType - the model class
      Returns:
      the converter, or null if none is registered
    • remove

      public static void remove(Class<?> presentationType, Class<?> modelType)
      Removes the converter registered for the given type pair.
      Parameters:
      presentationType - the presentation class
      modelType - the model class