|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.lang.TypeFormat
public final class TypeFormat
This class provides utility methods to parse CharSequence
into primitive types and to format primitive types into an
Appendable.
Methods from this class do not create temporary objects
and are typically faster than standard library methods (e.g
TypeFormat#parseDouble is up to 15x faster than
Double.parseDouble).
For non-primitive objects, formatting is typically performed using
specialized TextFormat instances.
| Method Summary | |
|---|---|
static java.lang.Appendable |
format(boolean b,
java.lang.Appendable csq)
Formats the specified boolean and appends the resulting
text to the Appendable argument. |
static java.lang.Appendable |
format(double value,
java.lang.Appendable csq)
Formats the specified double value. |
static java.lang.Appendable |
format(double value,
int digits,
boolean scientific,
boolean showZero,
java.lang.Appendable csq)
Formats the specified double value according to the
specified formatting arguments. |
static java.lang.Appendable |
format(float value,
java.lang.Appendable csq)
Formats the specified float value. |
static java.lang.Appendable |
format(int i,
java.lang.Appendable csq)
Formats the specified int and appends the resulting
text (decimal representation) to the Appendable argument. |
static java.lang.Appendable |
format(int i,
int radix,
java.lang.Appendable csq)
Formats the specified int in the specified radix and appends
the resulting text to the Appendable argument. |
static java.lang.Appendable |
format(long l,
java.lang.Appendable csq)
Formats the specified long and appends the resulting
text (decimal representation) to the Appendable argument. |
static java.lang.Appendable |
format(long l,
int radix,
java.lang.Appendable csq)
Formats the specified long in the specified radix and
appends the resulting text to the Appendable argument. |
static boolean |
parseBoolean(java.lang.CharSequence csq)
Parses the specified character sequence as a boolean. |
static boolean |
parseBoolean(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a boolean. |
static byte |
parseByte(java.lang.CharSequence csq)
Parses the specified character sequence as a signed decimal byte. |
static byte |
parseByte(java.lang.CharSequence csq,
int radix)
Parses the specified character sequence as a signed byte
in the specified radix. |
static byte |
parseByte(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a signed byte in the specified radix. |
static double |
parseDouble(java.lang.CharSequence csq)
Parses the specified character sequence as a double. |
static double |
parseDouble(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a double. |
static float |
parseFloat(java.lang.CharSequence csq)
Parses the specified character sequence as a float. |
static float |
parseFloat(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a float. |
static int |
parseInt(java.lang.CharSequence csq)
Parses the specified character sequence as a signed int. |
static int |
parseInt(java.lang.CharSequence csq,
int radix)
Parses the specified character sequence as a signed int
in the specified radix. |
static int |
parseInt(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a signed int in the specified radix. |
static long |
parseLong(java.lang.CharSequence csq)
Parses the specified character sequence as a decimal long. |
static long |
parseLong(java.lang.CharSequence csq,
int radix)
Parses the specified character sequence as a signed long
in the specified radix. |
static long |
parseLong(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a signed long in the specified radix. |
static short |
parseShort(java.lang.CharSequence csq)
Parses the specified character sequence as a signed decimal short. |
static short |
parseShort(java.lang.CharSequence csq,
int radix)
Parses the specified character sequence as a signed short
in the specified radix. |
static short |
parseShort(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
Parses the specified character sequence from the specified position as a signed short in the specified radix. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean parseBoolean(java.lang.CharSequence csq)
boolean.
csq - the character sequence to parse.
java.lang.IllegalArgumentException - if the specified character sequence
is different from "true" or "false" ignoring cases.
public static boolean parseBoolean(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
boolean.
csq - the character sequence to parse.cursor - the current cursor position (being maintained).
java.lang.IllegalArgumentException - if the character sequence from the
specified position is different from "true" or "false" ignoring
cases.public static byte parseByte(java.lang.CharSequence csq)
byte.
csq - the character sequence to parse.
parseByte(csq, 10)
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable byte.parseByte(CharSequence, int)
public static byte parseByte(java.lang.CharSequence csq,
int radix)
byte
in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.
byte.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable byte.
public static byte parseByte(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
byte in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.cursor - the current cursor position (being maintained).
byte.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable byte.public static short parseShort(java.lang.CharSequence csq)
short.
csq - the character sequence to parse.
parseShort(csq, 10)
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable short.parseShort(CharSequence, int)
public static short parseShort(java.lang.CharSequence csq,
int radix)
short
in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.
short.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable short.
public static short parseShort(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
short in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.cursor - the current cursor position (being maintained).
short.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable short.public static int parseInt(java.lang.CharSequence csq)
int.
csq - the character sequence to parse.
parseInt(csq, 10)
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable int.parseInt(CharSequence, int)
public static int parseInt(java.lang.CharSequence csq,
int radix)
int
in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.
int.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable int.
public static int parseInt(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
int in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.cursor - the current cursor position (being maintained).
int.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable int.public static long parseLong(java.lang.CharSequence csq)
long.
csq - the character sequence to parse.
parseLong(csq, 10)
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable long.parseLong(CharSequence, int)
public static long parseLong(java.lang.CharSequence csq,
int radix)
long
in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.
long.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable long.
public static long parseLong(java.lang.CharSequence csq,
int radix,
TextFormat.Cursor cursor)
long in the specified radix.
csq - the character sequence to parse.radix - the radix to be used while parsing.cursor - the current cursor position (being maintained).
long.
java.lang.NumberFormatException - if the specified character sequence
does not contain a parsable long.public static float parseFloat(java.lang.CharSequence csq)
float.
csq - the character sequence to parse.
java.lang.NumberFormatException - if the character sequence does not contain
a parsable float.
/
public static float parseFloat(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
float.
csq - the character sequence to parse.cursor - the current cursor position (being maintained).
java.lang.NumberFormatException - if the character sequence does not contain
a parsable float.
/
public static double parseDouble(java.lang.CharSequence csq)
throws java.lang.NumberFormatException
double.
csq - the character sequence to parse.
java.lang.NumberFormatException - if the character sequence does not contain
a parsable double.
/
public static double parseDouble(java.lang.CharSequence csq,
TextFormat.Cursor cursor)
throws java.lang.NumberFormatException
double.
csq - the character sequence to parse.cursor - the current cursor position (being maintained).
java.lang.NumberFormatException - if the character sequence does not contain
a parsable double.
/
public static java.lang.Appendable format(boolean b,
java.lang.Appendable csq)
throws java.io.IOException
boolean and appends the resulting
text to the Appendable argument.
b - a boolean.csq - the Appendable to append.
StringBuffer object.
java.io.IOException - if an I/O exception occurs.parseBoolean(java.lang.CharSequence)
public static java.lang.Appendable format(int i,
java.lang.Appendable csq)
throws java.io.IOException
int and appends the resulting
text (decimal representation) to the Appendable argument.
Note: This method is preferred to Appendable.append(int)
as it does not create temporary String
objects (several times faster for small numbers).
i - the int number.csq - the Appendable to append.
Appendable object.
java.io.IOException - if an I/O exception occurs.parseInt(java.lang.CharSequence)
public static java.lang.Appendable format(int i,
int radix,
java.lang.Appendable csq)
throws java.io.IOException
int in the specified radix and appends
the resulting text to the Appendable argument.
i - the int number.radix - the radix.csq - the Appendable to append.
Appendable object.
java.lang.IllegalArgumentException - if radix is not in [2 .. 36] range.
java.io.IOException - if an I/O exception occurs.parseInt(CharSequence, int)
public static java.lang.Appendable format(long l,
java.lang.Appendable csq)
throws java.io.IOException
long and appends the resulting
text (decimal representation) to the Appendable argument.
Note: This method is preferred to Appendable.append(long)
as it does not create temporary String
objects (several times faster for small numbers).
l - the long number.csq - the Appendable to append.
Appendable object.
java.io.IOException - if an I/O exception occurs.parseLong(java.lang.CharSequence)
public static java.lang.Appendable format(long l,
int radix,
java.lang.Appendable csq)
throws java.io.IOException
long in the specified radix and
appends the resulting text to the Appendable argument.
l - the long number.radix - the radix.csq - the Appendable to append.
Appendable object.
java.lang.IllegalArgumentException - if radix is not in [2 .. 36] range.
java.io.IOException - if an I/O exception occurs.parseLong(CharSequence, int)
public static java.lang.Appendable format(float value,
java.lang.Appendable csq)
throws java.io.IOException
float value.
value - the float value.csq - the Appendable to append.
format(value, 10, Math.abs(value) > 1E7, false, sb)
java.io.IOException - if an I/O exception occurs./
public static java.lang.Appendable format(double value,
java.lang.Appendable csq)
throws java.io.IOException
double value.
Note : This method is preferred to Double.toString(double)
or even String.valueOf(double) as it
does not create temporary String or
FloatingDecimal objects (several times faster,
e.g. 15x faster for Double.MAX_VALUE).
value - the double value.csq - the Appendable to append.
format(value, 17, Math.abs(value) > 1E7, false, sb)
java.io.IOException - if an I/O exception occurs./
public static java.lang.Appendable format(double value,
int digits,
boolean scientific,
boolean showZero,
java.lang.Appendable csq)
throws java.io.IOException
double value according to the
specified formatting arguments.
value - the double value.digits - the number of significative digits (excludes exponent).scientific - true to forces the use of the scientific
notation (e.g. 1.23E3); false
otherwise.showZero - true if trailing fractional zeros are
represented; false otherwise.csq - the Appendable to append.
Appendable object.
java.lang.IllegalArgumentException - if ((digits > 19) ||
(digits <= 0)))
java.io.IOException - if an I/O exception occurs.
/
|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||