Class NumberParser
- java.lang.Object
-
- com.realtime.crossfire.jxclient.util.NumberParser
-
public class NumberParser extends java.lang.ObjectUtility class for parsing strings into numbers.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanparseBoolean(@NotNull java.lang.String str)Parses a boolean constant.static <T extends java.lang.Enum<T>>
TparseEnum(@NotNull java.lang.Class<T> class_, @NotNull java.lang.String name, @NotNull java.lang.String ident)Parses an enum constant.static floatparseFloat(@NotNull java.lang.String str)Parses a float constant.static intparseInt(@NotNull java.lang.String string, int defaultValue)Converts a string into an int value.static intparseInt(@NotNull java.lang.String string, int defaultValue, int minValue, int maxValue)Converts a string into an int value in the given bounds.static longparseLong(@NotNull java.lang.String string, long defaultValue)Converts a string into a long value.
-
-
-
Method Detail
-
parseInt
public static int parseInt(@NotNull @NotNull java.lang.String string, int defaultValue)Converts a string into an int value.- Parameters:
string- the string to convertdefaultValue- the value to return if the number is not a string- Returns:
- the int value
-
parseInt
public static int parseInt(@NotNull @NotNull java.lang.String string, int defaultValue, int minValue, int maxValue)Converts a string into an int value in the given bounds.- Parameters:
string- the string to convertdefaultValue- the value to return if the number is not a string or not within boundsminValue- the bound's minimum valuemaxValue- the bound's maximum value- Returns:
- the int value
-
parseLong
public static long parseLong(@NotNull @NotNull java.lang.String string, long defaultValue)Converts a string into a long value.- Parameters:
string- the string to convertdefaultValue- the value to return if the number is not a string- Returns:
- the long value
-
parseFloat
public static float parseFloat(@NotNull @NotNull java.lang.String str) throws java.io.IOExceptionParses a float constant.- Parameters:
str- the floating constant string to parse- Returns:
- the floating value
- Throws:
java.io.IOException- if a parsing error occurs
-
parseBoolean
public static boolean parseBoolean(@NotNull @NotNull java.lang.String str) throws java.io.IOExceptionParses a boolean constant.- Parameters:
str- the boolean constant string to parse- Returns:
- the boolean value
- Throws:
java.io.IOException- if a parsing error occurs
-
parseEnum
@NotNull public static <T extends java.lang.Enum<T>> T parseEnum(@NotNull @NotNull java.lang.Class<T> class_, @NotNull @NotNull java.lang.String name, @NotNull @NotNull java.lang.String ident) throws java.io.IOExceptionParses an enum constant.- Type Parameters:
T- the enum class- Parameters:
class_- the enum class the enum constant belongs toname- the enum constant to parseident- the description of the enum class for building error messages- Returns:
- the enum constant
- Throws:
java.io.IOException- if the enum constant does not exist
-
-