Class CastUtils


  • public class CastUtils
    extends Object
    This class contains utility classes for type conversion.
    Author:
    hmlnarik
    • Constructor Detail

      • CastUtils

        public CastUtils()
    • Method Detail

      • cast

        public static <T> T cast​(Object value,
                                 Class<T> toClass)
        Converts value to destination class (if it can).
        Parameters:
        value - Value to convert
        toClass - Class to convert value to
        Returns:
        Value converted to the given class
        Throws:
        IllegalStateException - if the value cannot be converted to the requested class
      • getCastFunc

        public static <E extends Enum<E>> Function<?,​?> getCastFunc​(Class<?> fromClass,
                                                                          Class<?> toClass)
        Provides a function to convert value of a given class to destination class (if it can).
        Parameters:
        fromClass - Class to convert value from
        toClass - Class to convert value to
        Returns:
        Function fromClass -> toClass converting values from the fromClass to the toClass
        Throws:
        IllegalStateException - if the value cannot be converted to the requested class