ewe.sys
Class Convert

java.lang.Object
  extended byewe.sys.Convert

public class Convert
extends Object

Convert is used to convert between objects and basic types.


Field Summary
static int FORMAT_UNSIGNED
          This is an option for formatInt and formatLong.
static int FORMAT_UPPERCASE
          This is an option for formatXXX.
 
Constructor Summary
protected Convert()
           
 
Method Summary
static String formatDouble(double value)
          Convert a double value into a String of characters.
static int formatDouble(double value, char[] dest, int offset)
          Convert a double value into a String of characters or calculate the number of characters needed to convert the integer into the String of characters.
static int formatDouble(double value, char[] dest, int offset, int options)
          Convert a double value into a String of characters or calculate the number of characters needed to convert the long into the String of characters.
static String formatInt(int value)
          Convert an integer into a String of characters.
static int formatInt(int value, char[] dest, int offset)
          Convert an integer into a String of characters or calculate the number of characters needed to convert the integer into the String of characters.
static int formatInt(int value, char[] dest, int offset, int radix, int options)
          Convert an integer into a String of characters or calculate the number of characters needed to convert the integer into the String of characters.
static String formatInt(int value, int radix)
          Convert an integer into a String of characters.
static String formatLong(long value)
          Convert a long value into a String of characters.
static int formatLong(long value, char[] dest, int offset)
          Convert a long value into a String of characters or calculate the number of characters needed to convert the integer into the String of characters.
static int formatLong(long value, char[] dest, int offset, int radix, int options)
          Convert a long value into a String of characters or calculate the number of characters needed to convert the long into the String of characters.
static String formatLong(long value, int radix)
          Convert a long value into a String of characters.
static String intToHexString(int value)
          Convert the value to an unsigned hex string.
static String longToHexString(long value)
          Convert the value to an unsigned hex string.
static double parseDouble(char[] chars, int offset, int length)
          Parse a double precision floating point decimal number.
static double parseDouble(String value)
          Parse a double precision floating point decimal number.
static int parseInt(char[] str, int offset, int length, int radix)
          Convert a String to an integer using the specified radix.
static int parseInt(String str)
          Convert a String to an integer.
static int parseInt(String str, int radix)
          Convert a String to an integer using the specified radix.
static long parseLong(char[] str, int offset, int length, int radix)
          Convert a String to an integer using the specified radix.
static long parseLong(String str)
          Convert a String to a long value.
static long parseLong(String str, int radix)
          Convert a String to a long value using the specified radix.
static boolean toBoolean(String s)
           
static char toChar(String s)
           
static double toDouble(char[] chars, int start, int length)
          Convert a string of characters to a double value returning zero if the format is bad.
static double toDouble(String s)
          Convert a string of characters to a double value returning zero if the format is bad.
static double toDoubleBitwise(long l)
          Convert the 64-bit bitwise equivalent of a double value back to the double value.
static float toFloat(char[] chars, int start, int length)
          Convert a string of characters to a double value returning zero if the format is bad.
static float toFloat(String s)
          Convert a string of characters to a float value returning zero if the format is bad.
static float toFloatBitwise(int i)
          Converts the given IEEE 754 bit representation of a float to a float.
static int toInt(char[] chars, int start, int length)
          Convert a string of characters to an int value returning zero if the format is bad.
static int toInt(String s)
          Convert a string of characters to a int value returning zero if the format is bad.
static int toIntBitwise(float f)
          Converts the given float to its bit representation in IEEE 754 format.
static long toLong(char[] chars, int start, int length)
          Convert a string of characters to a long value returning zero if the format is bad.
static long toLong(String s)
          Convert a string of characters to long value returning zero if the format is bad.
static long toLongBitwise(double d)
          Get the 64-bit bitwise equivalent of the double value.
static String toString(boolean b)
          Converts the given boolean to a String.
static String toString(char c)
          Converts the given char to a String.
static String toString(double d)
          Converts the given double to a String.
static String toString(float f)
          Converts the given float to a String.
static String toString(int i)
          Converts the given int to a String.
static String toString(long l)
          Converts the given long to a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

FORMAT_UNSIGNED

public static final int FORMAT_UNSIGNED
This is an option for formatInt and formatLong. It specifies that the number should be formatted as unsigned. This is only valid for radixes of 2, 4, 8 and 16.

See Also:
Constant Field Values

FORMAT_UPPERCASE

public static final int FORMAT_UPPERCASE
This is an option for formatXXX. It specifies that any non-digit characters should be in upper case. This is generally only useful in non-decimal radixes. For formatDouble() this specifies that any 'e' character should be in uppercase.

See Also:
Constant Field Values
Constructor Detail

Convert

protected Convert()
Method Detail

toInt

public static int toInt(String s)
Convert a string of characters to a int value returning zero if the format is bad. See parseInt() for a better conversion method.


toFloat

public static float toFloat(String s)
Convert a string of characters to a float value returning zero if the format is bad. See parseDouble() for a better conversion method.


toDouble

public static double toDouble(String s)
Convert a string of characters to a double value returning zero if the format is bad. See parseDouble() for a better conversion method.


toLong

public static long toLong(String s)
Convert a string of characters to long value returning zero if the format is bad. See parseLong() for a better conversion method.


toInt

public static int toInt(char[] chars,
                        int start,
                        int length)
Convert a string of characters to an int value returning zero if the format is bad. See parseInt() for a better conversion method.


toFloat

public static float toFloat(char[] chars,
                            int start,
                            int length)
Convert a string of characters to a double value returning zero if the format is bad. See parseDouble() for a better conversion method.


toDouble

public static double toDouble(char[] chars,
                              int start,
                              int length)
Convert a string of characters to a double value returning zero if the format is bad. See parseDouble() for a better conversion method.


toLong

public static long toLong(char[] chars,
                          int start,
                          int length)
Convert a string of characters to a long value returning zero if the format is bad. See parseLong() for a better conversion method.


toString

public static String toString(boolean b)
Converts the given boolean to a String.


toString

public static String toString(char c)
Converts the given char to a String.


toIntBitwise

public static int toIntBitwise(float f)
Converts the given float to its bit representation in IEEE 754 format.


toFloatBitwise

public static float toFloatBitwise(int i)
Converts the given IEEE 754 bit representation of a float to a float.


toString

public static String toString(float f)
Converts the given float to a String.


toString

public static String toString(int i)
Converts the given int to a String.


toString

public static String toString(double d)
Converts the given double to a String.


toString

public static String toString(long l)
Converts the given long to a String.


toLongBitwise

public static long toLongBitwise(double d)
Get the 64-bit bitwise equivalent of the double value.


toDoubleBitwise

public static double toDoubleBitwise(long l)
Convert the 64-bit bitwise equivalent of a double value back to the double value.


toBoolean

public static boolean toBoolean(String s)

toChar

public static char toChar(String s)

parseInt

public static int parseInt(char[] str,
                           int offset,
                           int length,
                           int radix)
                    throws NumberFormatException
Convert a String to an integer using the specified radix. The String must have only decimal digits or letters (for radix > 10) and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
offset - The index of the first character to parse.
length - The number of characters to parse.
radix - The radix ( >1 and < 37 )
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.
IllegalArgumentException - if the radix is not in the correct range.

parseLong

public static long parseLong(char[] str,
                             int offset,
                             int length,
                             int radix)
                      throws NumberFormatException
Convert a String to an integer using the specified radix. The String must have only decimal digits or letters (for radix > 10) and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
offset - The index of the first character to parse.
length - The number of characters to parse.
radix - The radix ( >1 and < 37 )
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.
IllegalArgumentException - if the radix is not in the correct range.

parseInt

public static int parseInt(String str)
                    throws NumberFormatException
Convert a String to an integer. The String must have only decimal digits and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.

parseInt

public static int parseInt(String str,
                           int radix)
Convert a String to an integer using the specified radix. The String must have only decimal digits or letters (for radix > 10) and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
radix - The radix ( >1 and < 37 )
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.
IllegalArgumentException - if the radix is not in the correct range.

parseLong

public static long parseLong(String str)
                      throws NumberFormatException
Convert a String to a long value. The String must have only decimal digits and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.

parseLong

public static long parseLong(String str,
                             int radix)
Convert a String to a long value using the specified radix. The String must have only decimal digits or letters (for radix > 10) and must start with a '-' if it is negative.

Parameters:
str - The characters to parse.
radix - The radix ( >1 and < 37 )
Returns:
the parsed integer.
Throws:
NumberFormatException - if the String value is not a parsable integer.
IllegalArgumentException - if the radix is not in the correct range.

parseDouble

public static double parseDouble(char[] chars,
                                 int offset,
                                 int length)
                          throws NumberFormatException
Parse a double precision floating point decimal number.

Parameters:
chars - The characters to parse.
offset - The index of the first character.
length - The number of characters to parse.
Returns:
the double value of the string.
Throws:
NumberFormatException - if the string is not parsable.

parseDouble

public static double parseDouble(String value)
                          throws NumberFormatException
Parse a double precision floating point decimal number.

Parameters:
value - The characters to parse.
Returns:
the double value of the string.
Throws:
NumberFormatException - if the string is not parsable.

formatInt

public static int formatInt(int value,
                            char[] dest,
                            int offset,
                            int radix,
                            int options)
Convert an integer into a String of characters or calculate the number of characters needed to convert the integer into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
radix - the radix (>1 and <37).
options - a combination of the FORMAT_XXX options.
Returns:
the number of characters used or needed to format the value.
Throws:
IllegalArgumentException - if the radix is not in the correct range.

formatInt

public static int formatInt(int value,
                            char[] dest,
                            int offset)
Convert an integer into a String of characters or calculate the number of characters needed to convert the integer into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
Returns:
the number of characters used or needed to format the value.

formatInt

public static String formatInt(int value,
                               int radix)
Convert an integer into a String of characters.

Parameters:
value - the value to convert.
radix - the radix (>1 and <37).
Returns:
a new String with the converted integer value.
Throws:
IllegalArgumentException - if the radix is not in the correct range.

formatInt

public static String formatInt(int value)
Convert an integer into a String of characters.

Parameters:
value - the value to convert.
Returns:
a new String with the converted integer value.

formatLong

public static int formatLong(long value,
                             char[] dest,
                             int offset,
                             int radix,
                             int options)
Convert a long value into a String of characters or calculate the number of characters needed to convert the long into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
radix - the radix (>1 and <37).
options - a combination of the FORMAT_XXX options.
Returns:
the number of characters used or needed to format the value.
Throws:
IllegalArgumentException - if the radix is not in the correct range.

formatLong

public static int formatLong(long value,
                             char[] dest,
                             int offset)
Convert a long value into a String of characters or calculate the number of characters needed to convert the integer into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
Returns:
the number of characters used or needed to format the value.

formatLong

public static String formatLong(long value,
                                int radix)
Convert a long value into a String of characters.

Parameters:
value - the value to convert.
radix - the radix (>1 and <37).
Returns:
a new String with the converted integer value.
Throws:
IllegalArgumentException - if the radix is not in the correct range.

formatLong

public static String formatLong(long value)
Convert a long value into a String of characters.

Parameters:
value - the value to convert.
Returns:
a new String with the converted integer value.

formatDouble

public static int formatDouble(double value,
                               char[] dest,
                               int offset,
                               int options)
Convert a double value into a String of characters or calculate the number of characters needed to convert the long into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
options - a combination of the FORMAT_XXX options.
Returns:
the number of characters used or needed to format the value.

formatDouble

public static int formatDouble(double value,
                               char[] dest,
                               int offset)
Convert a double value into a String of characters or calculate the number of characters needed to convert the integer into the String of characters. To calculate the number of characters needed use a null "dest" parameter.

Parameters:
value - the value to convert.
dest - the destination character array. If this is null the
offset - the start index in the character array.
Returns:
the number of characters used or needed to format the value.

formatDouble

public static String formatDouble(double value)
Convert a double value into a String of characters.

Parameters:
value - the value to convert.
Returns:
a new String with the converted integer value.
Throws:
IllegalArgumentException - if the radix is not in the correct range.

intToHexString

public static String intToHexString(int value)
Convert the value to an unsigned hex string.


longToHexString

public static String longToHexString(long value)
Convert the value to an unsigned hex string.