Class TypeUtils

java.lang.Object
onl.ycode.stormify.TypeUtils

public final class TypeUtils extends Object
Utility class for converting between different types and handling exceptions.
  • Method Details

    • castTo

      public static <F, T> T castTo(Class<T> targetClass, F value)
      Convert a value to the target class
      Type Parameters:
      F - the source class type
      T - the target class type
      Parameters:
      targetClass - the target class
      value - the value to convert
      Returns:
      the converted value
    • registerConversion

      public static <F, T> Function<F,T> registerConversion(Class<F> sourceClass, Class<T> targetClass, Function<F,T> converter)
      Register a conversion function from sourceClass to targetClass. This function will provide custom conversion between classes, when casting objects of different types.
      Type Parameters:
      F - the source class type
      T - the target class type
      Parameters:
      sourceClass - the source class that needs to be converted
      targetClass - the target class that the data should be converted to
      converter - the function that will convert the data
      Returns:
      the previous conversion function if it was already registered
    • getWrapper

      public static Class<?> getWrapper(Class<?> primitive)
      Get the boxed type class for a primitive class
      Parameters:
      primitive - the primitive class
      Returns:
      the boxed class