Class CastUtils


  • public class CastUtils
    extends Object
    CastUtils Cast different things to different things
    Author:
    Christian Paul
    • Constructor Detail

      • CastUtils

        public CastUtils()
    • Method Detail

      • toInteger

        public static Integer toInteger​(Object o)
        Cast object to integer
        Parameters:
        o - object to cast
        Returns:
        integer
      • toInteger

        public static Integer toInteger​(Object o,
                                        int defaultValue)
        Cast object to integer
        Parameters:
        o - object to cast
        defaultValue - default return value, if object is not castable
        Returns:
        integer
      • toLong

        public static Long toLong​(Object o)
        Cast object to long
        Parameters:
        o - object to cast
        Returns:
        long
      • toLong

        public static Long toLong​(Object o,
                                  long defaultValue)
        Cast object to long
        Parameters:
        o - object to cast
        defaultValue - default return value, if object is not castable
        Returns:
        long
      • toDouble

        public static double toDouble​(Object o)
        Cast object to double
        Parameters:
        o - object to cast
        Returns:
        double
      • toDouble

        public static double toDouble​(Object o,
                                      double defaultValue)
        Cast object to double
        Parameters:
        o - object to cast
        defaultValue - default reurn value, if object is not castable
        Returns:
        double
      • toString

        public static String toString​(Object o)
        Cast object to string
        Parameters:
        o - object to cast
        Returns:
        string
      • toString

        public static String toString​(Object o,
                                      String defaultValue)
        Cast object to string
        Parameters:
        o - object to cast
        defaultValue - default return value, if object is null
        Returns:
        string
      • toListOfStrings

        public static List<String> toListOfStrings​(Object o)
        Cast object to a list of strings
        Parameters:
        o - object to cast
        Returns:
        list of strings
      • toSetOfStrings

        public static Set<String> toSetOfStrings​(Object o)
        Cast object to a set of strings
        Parameters:
        o - object to cast
        Returns:
        set of strings