Package gaiasky.util.parse
Class Parser
java.lang.Object
gaiasky.util.parse.Parser
Parser utilities.
- Since:
- 10/02/2015 14:29:47
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
parseBoolean(Object what)
Method used to parse accepted boolean values in incoming messagesstatic double
parseDouble(String input)
Quick double string parser that can handle negative and positive doubles but not exponents.static double
parseDoubleException(String input)
Quick double string parser that can handle negative and positive doubles but not exponents.static float
parseFloat(String input)
Convenience method which uses the double parser and casts the result.static float[]
parseFloatArray(String input)
Parses a float array in the form '[a, b, c, ...]static float[]
parseFloatArrayException(String input)
Parses a float array in the form '[a, b, c, ...]static float
parseFloatException(String input)
Convenience method which uses the double parser and casts the result.static int
Parses an integer.static int
parseIntException(String str)
Parses an integer.static long
Quick long string parser that can handle negative and positive values.static long
parseLongException(String input)
Quick long string parser that can handle negative and positive values.
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
parseLong
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
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
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
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
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
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
Parses an integer. Throws aNumberFormatException
if the input is not a valid integer representation.- Parameters:
str
- The input string.- Returns:
- The integer representation of the string.
- Throws:
NumberFormatException
-
parseFloat
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
Convenience method which uses the double parser and casts the result. Please checkparseDoubleException(String)
- Parameters:
input
- The input string.- Returns:
- The parsed float, or
Float.NaN
if the parsing failed. - Throws:
NumberFormatException
- if the parsing failed.
-
parseFloatArray
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
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
-