Class Morph<T>

java.lang.Object
org.klojang.convert.Morph<T>
Type Parameters:
T - The type to which incoming values will be converted

public class Morph<T> extends Object
Performs a wide variety of type conversions.
Author:
Ayco Holleman
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Morph(Class<T> targetType)
    Creates a new Morph instance that will convert values to the specified type.
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts the specified object into an instance of the type specified through the constructor.
    static <U> U
    convert(Object obj, Class<U> targetType)
    Converts the specified object to the specified type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Morph

      public Morph(Class<T> targetType)
      Creates a new Morph instance that will convert values to the specified type.
      Parameters:
      targetType - The type to which to convert values
  • Method Details

    • convert

      public static <U> U convert(Object obj, Class<U> targetType)
      Converts the specified object to the specified type.
      Type Parameters:
      U - The target type
      Parameters:
      obj - The value to convert
      targetType - The Class object corresponding to the target type
      Returns:
      The converted value
      Throws:
      TypeConversionException - If the conversion did not succeed
    • convert

      public T convert(Object obj) throws TypeConversionException
      Converts the specified object into an instance of the type specified through the constructor.
      Parameters:
      obj - The value to convert
      Returns:
      An instance of the target type
      Throws:
      TypeConversionException - If the conversion did not succeed