Class Parser

java.lang.Object
gaiasky.util.parse.Parser

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

    • Parser

      public Parser()
  • Method Details

    • parseLong

      public static long parseLong(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(String input) throws 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:
      NumberFormatException - If the given input can not be parsed
    • parseDouble

      public static double parseDouble(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(String input) throws 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:
      NumberFormatException - If the input string is invalid
    • parseBoolean

      public static boolean parseBoolean(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(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(String str) throws 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:
      NumberFormatException
    • parseFloat

      public static float parseFloat(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(String input) throws NumberFormatException
      Convenience method which uses the double parser and casts the result. Please check parseDoubleException(String)
      Parameters:
      input - The input string.
      Returns:
      The parsed float, or Float.NaN if the parsing failed.
      Throws:
      NumberFormatException - if the parsing failed.
    • parseFloatArray

      public static float[] parseFloatArray(String input)
      Parses a float array in the form '[a, b, c, ...]
      Parameters:
      input - The input string.
      Returns:
      The parsed float array, or null if the parsing failed.
    • parseFloatArrayException

      public static float[] parseFloatArrayException(String input) throws NumberFormatException
      Parses a float array in the form '[a, b, c, ...]
      Parameters:
      input - The input string.
      Returns:
      The parsed float array, or null if the parsing failed.
      Throws:
      NumberFormatException