com.realtime.crossfire.jxclient.util
Class NumberParser

java.lang.Object
  extended by com.realtime.crossfire.jxclient.util.NumberParser

public class NumberParser
extends java.lang.Object

Utility class for parsing strings into numbers.


Constructor Summary
private NumberParser()
          Private constructor to prevent instantiation.
 
Method Summary
static boolean parseBoolean(java.lang.String str)
          Parses a boolean constant.
static
<T extends java.lang.Enum<T>>
T
parseEnum(java.lang.Class<T> class_, java.lang.String name, java.lang.String ident)
          Parses an enum constant.
static float parseFloat(java.lang.String str)
          Parses a float constant.
static int parseInt(java.lang.String string, int defaultValue)
          Converts a string into an int value.
static int parseInt(java.lang.String string, int defaultValue, int minValue, int maxValue)
          Converts a string into an int value in the given bounds.
static long parseLong(java.lang.String string, long defaultValue)
          Converts a string into a long value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberParser

private NumberParser()
Private constructor to prevent instantiation.

Method Detail

parseBoolean

public static boolean parseBoolean(@NotNull
                                   java.lang.String str)
                            throws java.io.IOException
Parses 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
                                                                java.lang.Class<T> class_,
                                                                @NotNull
                                                                java.lang.String name,
                                                                @NotNull
                                                                java.lang.String ident)
                                             throws java.io.IOException
Parses an enum constant.

Parameters:
class_ - the enum class the enum constant belongs to
name - the enum constant to parse
ident - 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

parseFloat

public static float parseFloat(@NotNull
                               java.lang.String str)
                        throws java.io.IOException
Parses a float constant.

Parameters:
str - the floating constant string to parse
Returns:
the floating value
Throws:
java.io.IOException - if a parsing error occurs

parseInt

public static int parseInt(@NotNull
                           java.lang.String string,
                           int defaultValue)
Converts a string into an int value.

Parameters:
string - the string to convert
defaultValue - the value to return if the number is not a string
Returns:
the int value

parseInt

public static int parseInt(@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 convert
defaultValue - the value to return if the number is not a string or not within bounds
minValue - the bound's minimum value
maxValue - the bound's maximum value
Returns:
the int value

parseLong

public static long parseLong(@NotNull
                             java.lang.String string,
                             long defaultValue)
Converts a string into a long value.

Parameters:
string - the string to convert
defaultValue - the value to return if the number is not a string
Returns:
the long value