Class ValueUtils
java.lang.Object
net.mtrop.doom.struct.utils.ValueUtils
Simple utility functions around values.
- Author:
- Matthew Tropiano
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TThis function calls the provided callable and returns its value.static <T> TAttempts to parse a string to another object.static BooleanAttempts to parse a boolean from a string.static booleanparseBoolean(String s, boolean def) Attempts to parse a boolean from a string.static boolean[]parseBooleanArray(String s, boolean[] def) Attempts to parse an array of booleans from a string.static boolean[]parseBooleanArray(String s, String separatorRegex, boolean[] def) Attempts to parse an array of booleans from a string.static ByteAttempts to parse a byte from a string.static byteAttempts to parse a byte from a string.static byte[]parseByteArray(String s, byte[] def) Attempts to parse an array of bytes from a string.static byte[]parseByteArray(String s, String separatorRegex, byte[] def) Attempts to parse an array of bytes from a string.static CharacterAttempts to parse a char from a string.static charAttempts to parse a byte from a string.static char[]parseCharArray(String s, char[] def) Attempts to parse an array of chars from a string.static char[]parseCharArray(String s, String separatorRegex, char[] def) Attempts to parse an array of chars from a string.static DoubleAttempts to parse a double from a string.static doubleparseDouble(String s, double def) Attempts to parse a double from a string.static double[]parseDoubleArray(String s, double[] def) Attempts to parse an array of doubles from a string.static double[]parseDoubleArray(String s, String separatorRegex, double[] def) Attempts to parse an array of doubles from a string.static FloatparseFloat(String s) Attempts to parse a float from a string.static floatparseFloat(String s, float def) Attempts to parse a float from a string.static float[]parseFloatArray(String s, float[] def) Attempts to parse an array of floats from a string.static float[]parseFloatArray(String s, String separatorRegex, float[] def) Attempts to parse an array of floats from a string.static IntegerAttempts to parse an int from a string.static intAttempts to parse an int from a string.static int[]parseIntArray(String s, int[] def) Attempts to parse an array of integers from a string.static int[]parseIntArray(String s, String separatorRegex, int[] def) Attempts to parse an array of integers from a string.static LongAttempts to parse a long from a string.static longAttempts to parse a long from a string.static long[]parseLongArray(String s, long[] def) Attempts to parse an array of longs from a string.static long[]parseLongArray(String s, String separatorRegex, long[] def) Attempts to parse an array of longs from a string.static ShortparseShort(String s) Attempts to parse a short from a string.static shortparseShort(String s, short def) Attempts to parse a short from a string.static short[]parseShortArray(String s, short[] def) Attempts to parse an array of shorts from a string.static short[]parseShortArray(String s, String separatorRegex, short[] def) Attempts to parse an array of shorts from a string.
-
Method Details
-
get
This function calls the provided callable and returns its value. This is mostly for filling static fields on classes that would otherwise only need to be put in a static block.- Type Parameters:
T- the return type.- Parameters:
callable- the callable to call.- Returns:
- the result of the callable.
- Throws:
RuntimeException- if an exception occurs.
-
parse
-
parseBoolean
-
parseByte
-
parseShort
-
parseChar
-
parseInt
-
parseLong
-
parseFloat
-
parseDouble
-
parseBoolean
Attempts to parse a boolean from a string. If the string is null or the empty string, this returnsdef. If the string does not equal "true," this returns false.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted boolean or def if the input string is blank.
-
parseByte
Attempts to parse a byte from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted byte or def if the input string is blank.
-
parseShort
Attempts to parse a short from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted short or def if the input string is blank.
-
parseChar
Attempts to parse a byte from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the first character in the string or def if the input string is blank.
-
parseInt
Attempts to parse an int from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted integer or def if the input string is blank.
-
parseLong
Attempts to parse a long from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted long integer or def if the input string is blank.
-
parseFloat
Attempts to parse a float from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted float or def if the input string is blank.
-
parseDouble
Attempts to parse a double from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the interpreted double or def if the input string is blank.
-
parseBooleanArray
Attempts to parse an array of booleans from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"true, false, apple, false"becomes[true, false, false, false]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of booleans or def if the input string is blank.
- See Also:
-
parseByteArray
Attempts to parse an array of bytes from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0, -5, 2, grape"becomes[0, -5, 2, 0]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of bytes or def if the input string is blank.
- See Also:
-
parseShortArray
Attempts to parse an array of shorts from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0, -5, 2, grape"becomes[0, -5, 2, 0]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of shorts or def if the input string is blank.
- See Also:
-
parseCharArray
Attempts to parse an array of chars from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"apple, pear, b, g"becomes['a', 'p', 'b', 'g']- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of characters or def if the input string is blank.
- See Also:
-
parseIntArray
Attempts to parse an array of integers from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0, -5, 2.1, grape"becomes[0, -5, 2, 0]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of integers or def if the input string is blank.
- See Also:
-
parseFloatArray
Attempts to parse an array of floats from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0.5, -5.4, 2, grape"becomes[0.5f, -5.4f, 2.0f, 0f]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of floats or def if the input string is blank.
- See Also:
-
parseLongArray
Attempts to parse an array of longs from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0, -5, 2, grape"becomes[0, -5, 2, 0]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of long integers or def if the input string is blank.
- See Also:
-
parseDoubleArray
Attempts to parse an array of doubles from a string. If the string is null or the empty string, this returnsdef. This assumes that the elements of the array are separated by comma-or-whitespace characters.Example:
"0.5, -5.4, 2, grape"becomes[0.5, -5.4, 2.0, 0.0]- Parameters:
s- the input string.def- the fallback value to return.- Returns:
- the array of doubles or def if the input string is blank.
- See Also:
-
parseBooleanArray
Attempts to parse an array of booleans from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of booleans or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseByteArray
Attempts to parse an array of bytes from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of bytes or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseShortArray
Attempts to parse an array of shorts from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of shorts or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseCharArray
Attempts to parse an array of chars from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of characters or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseIntArray
Attempts to parse an array of integers from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of integers or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseFloatArray
Attempts to parse an array of floats from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of floats or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseLongArray
Attempts to parse an array of longs from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of long integers or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-
parseDoubleArray
Attempts to parse an array of doubles from a string. If the string is null or the empty string, this returnsdef.- Parameters:
s- the input string.separatorRegex- the regular expression to split the string into tokens.def- the fallback value to return.- Returns:
- the array of doubles or def if the input string is blank.
- Throws:
NullPointerException- if separatorRegex is null.- See Also:
-