Package gaiasky.util.parse
Class Parser
- java.lang.Object
-
- gaiasky.util.parse.Parser
-
public final class Parser extends java.lang.ObjectParser 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 booleanparseBoolean(java.lang.Object what)Method used to parse accepted boolean values in incoming messagesstatic doubleparseDouble(java.lang.String input)Quick double string parser that can handle negative and positive doubles but not exponents.static doubleparseDoubleException(java.lang.String input)Quick double string parser that can handle negative and positive doubles but not exponents.static floatparseFloat(java.lang.String input)Convenience method which uses the double parser and casts the result.static float[]parseFloatArray(java.lang.String input)Parses a float array in the form '[a, b, c, ...]static float[]parseFloatArrayException(java.lang.String input)Parses a float array in the form '[a, b, c, ...]static floatparseFloatException(java.lang.String input)Convenience method which uses the double parser and casts the result.static intparseInt(java.lang.String str)Parses an integer.static intparseIntException(java.lang.String str)Parses an integer.static longparseLong(java.lang.String input)Quick long string parser that can handle negative and positive values.static longparseLongException(java.lang.String input)Quick long string parser that can handle negative and positive values.
-
-
-
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.NumberFormatExceptionQuick 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.NumberFormatExceptionQuick 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.NumberFormatExceptionParses an integer. Throws aNumberFormatExceptionif 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 checkparseDouble(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) throws java.lang.NumberFormatExceptionConvenience method which uses the double parser and casts the result. Please checkparseDoubleException(String)- Parameters:
input- The input string.- Returns:
- The parsed float, or
Float.NaNif the parsing failed. - Throws:
java.lang.NumberFormatException- if the parsing failed.
-
parseFloatArray
public static float[] parseFloatArray(java.lang.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(java.lang.String input) throws java.lang.NumberFormatExceptionParses 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:
java.lang.NumberFormatException
-
-