Class Numbers


  • public final class Numbers
    extends Object
    • Method Detail

      • parseLong

        public static long parseLong​(Object val)
        Parse the given object as a long. The input object can be a String or one of the implementations of Number. You may want to use GuavaUtils.tryParseLong() instead if the input is a nullable string and you want to avoid any exceptions.
        Throws:
        NumberFormatException - if the input is an unparseable string.
        NullPointerException - if the input is null.
        ISE - if the input is not a string or a number.
      • parseInt

        public static int parseInt​(Object val)
        Parse the given object as a int. The input object can be a String or one of the implementations of Number.
        Throws:
        NumberFormatException - if the input is an unparseable string.
        NullPointerException - if the input is null.
        ISE - if the input is not a string or a number.
      • parseBoolean

        public static boolean parseBoolean​(Object val)
        Parse the given object as a boolean. The input object can be a String or Boolean.
        Returns:
        true only if the input is a Boolean representing true or a String of "true".
        Throws:
        NullPointerException - if the input is null.
        ISE - if the input is not a string or a number.
      • tryParseDouble

        public static double tryParseDouble​(@Nullable
                                            Object val,
                                            double nullValue)
        Try parsing the given Number or String object val as double.
        Parameters:
        val -
        nullValue - value to return when input was string type but not parseable into double value
        Returns:
        parsed double value
      • tryParseLong

        public static long tryParseLong​(@Nullable
                                        Object val,
                                        long nullValue)
        Try parsing the given Number or String object val as long.
        Parameters:
        val -
        nullValue - value to return when input was string type but not parseable into long value
        Returns:
        parsed long value
      • tryParseFloat

        public static float tryParseFloat​(@Nullable
                                          Object val,
                                          float nullValue)
        Try parsing the given Number or String object val as float.
        Parameters:
        val -
        nullValue - value to return when input was string type but not parseable into float value
        Returns:
        parsed float value