Class Parser


  • public final class Parser
    extends java.lang.Object
    Parser utilities.
    Since:
    10/02/2015 14:29:47
    • Constructor Summary

      Constructors 
      Constructor Description
      Parser()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean parseBoolean​(java.lang.Object what)
      Method used to parse accepted boolean values in incoming messages
      static double parseDouble​(java.lang.String input)
      Quick double string parser that can handle negative and positive doubles but not exponents.
      static double parseDoubleException​(java.lang.String input)
      Quick double string parser that can handle negative and positive doubles but not exponents.
      static float parseFloat​(java.lang.String input)
      Convenience method which uses the double parser and casts the result.
      static float parseFloatException​(java.lang.String input)
      Convenience method which uses the double parser and casts the result.
      static int parseInt​(java.lang.String str)
      Parses an integer.
      static int parseIntException​(java.lang.String str)
      Parses an integer.
      static long parseLong​(java.lang.String input)
      Quick long string parser that can handle negative and positive values.
      static long parseLongException​(java.lang.String input)
      Quick long string parser that can handle negative and positive values.
      • Methods inherited from class java.lang.Object

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

      • Parser

        public Parser()
    • Method Detail

      • parseLong

        public static long parseLong​(java.lang.String input)

        Quick long string parser that can handle negative and positive values.

        Parser supports leading/trailing whitespace.

        Parameters:
        input - String to parse
        Returns:
        Parsed long or 0 if the parsing fails
      • parseLongException

        public static long parseLongException​(java.lang.String input)
                                       throws java.lang.NumberFormatException

        Quick long string parser that can handle negative and positive values.

        Parser supports leading/trailing whitespace.

        Parameters:
        input - String to parse
        Returns:
        Parsed long or 0 if the parsing fails
        Throws:
        java.lang.NumberFormatException - If the given input can not be parsed
      • parseDouble

        public static double parseDouble​(java.lang.String input)

        Quick double string parser that can handle negative and positive doubles but not exponents.

        Parser supports NaN, +/-Inf, exponents and leading/trailing whitespace.

        Parser is mostly locale unaware except for dot and comma for decimal separator.

        Parameters:
        input - String to parse
        Returns:
        Parsed double or Double.NaN if the parsing fails See also parseDoubleException(String) If exceptions on invalid input is necessary
      • parseDoubleException

        public static double parseDoubleException​(java.lang.String input)
                                           throws java.lang.NumberFormatException

        Quick double string parser that can handle negative and positive doubles but not exponents.

        Parser supports NaN, +/-Inf and leading/trailing whitespace.

        Parser is mostly locale unaware except for dot and comma for decimal separator.

        Parameters:
        input - String to parse
        Returns:
        Parsed double or Double.NaN if the parsing fails
        Throws:
        java.lang.NumberFormatException - If the input string is invalid
      • parseBoolean

        public static boolean parseBoolean​(java.lang.Object what)
        Method used to parse accepted boolean values in incoming messages
        Parameters:
        what - What to parse
        Returns:
        True or false (also default return) depending on the value of what
      • parseInt

        public static int parseInt​(java.lang.String str)
        Parses an integer. If the input is not a valid integer representation it returns 0.
        Parameters:
        str - The input string.
        Returns:
        The integer representation of the string.
      • parseIntException

        public static int parseIntException​(java.lang.String str)
                                     throws java.lang.NumberFormatException
        Parses an integer. Throws a NumberFormatException if the input is not a valid integer representation.
        Parameters:
        str - The input string.
        Returns:
        The integer representation of the string.
        Throws:
        java.lang.NumberFormatException
      • parseFloat

        public static float parseFloat​(java.lang.String input)
        Convenience method which uses the double parser and casts the result. It will not throw Please check parseDouble(String).
        Parameters:
        input - The input string.
        Returns:
        The parsed float, or 0 if the parsing failed.
      • parseFloatException

        public static float parseFloatException​(java.lang.String input)
        Convenience method which uses the double parser and casts the result. Please check parseDouble(String)
        Parameters:
        input - The input string.
        Returns:
        The parsed float, or 0 if the parsing failed.