| java.lang.Object javolution.text.TypeFormat
TypeFormat | final public class TypeFormat (Code) | | This class provides utility methods to parse CharSequence
into primitive types and to format primitive types into any
Appendable .
Methods from this class do not create temporary objects and
are typically faster than standard library methods (see
benchmark).
The number of digits when formatting floating point numbers can be
specified. The default setting for double is 17 digits
or even 16 digits when the conversion is lossless back and forth
(mimic the standard library formatting). For example:[code]
TypeFormat.format(0.2, a) = "0.2" // 17 or 16 digits (as long as lossless conversion), remove trailing zeros.
TypeFormat.format(0.2, 17, false, false, a) = "0.20000000000000001" // Closest 17 digits number.
TypeFormat.format(0.2, 19, false, false, a) = "0.2000000000000000111" // Closest 19 digits.
TypeFormat.format(0.2, 4, false, false, a) = "0.2" // Fixed-point notation, remove trailing zeros.
TypeFormat.format(0.2, 4, false, true, a) = "0.2000" // Fixed-point notation, fixed number of digits.
TypeFormat.format(0.2, 4, true, false, a) = "2.0E-1" // Scientific notation, remove trailing zeros.
TypeFormat.format(0.2, 4, true, true, a) = "2.000E-1" // Scientific notation, fixed number of digits.
[/code]
For non-primitive objects, formatting is typically performed using
specialized
TextFormat instances.
author: Jean-Marie Dautelle version: 4.1, November 30, 2006 |
Method Summary | |
public static Appendable | format(boolean b, Appendable a) Formats the specified boolean and appends the resulting
text to the Appendable argument.
Parameters: b - a boolean . Parameters: a - the Appendable to append. | public static Appendable | format(int i, Appendable a) Formats the specified 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).
Parameters: i - the int number. Parameters: a - the Appendable to append. | public static Appendable | format(int i, int radix, Appendable a) Formats the specified int in the specified radix and appends
the resulting text to the Appendable argument.
Parameters: i - the int number. Parameters: radix - the radix. Parameters: a - the Appendable to append. | public static Appendable | format(long l, Appendable a) Formats the specified 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).
Parameters: l - the long number. Parameters: a - the Appendable to append. | public static Appendable | format(long l, int radix, Appendable a) Formats the specified long in the specified radix and
appends the resulting text to the Appendable argument.
Parameters: l - the long number. Parameters: radix - the radix. Parameters: a - the Appendable to append. | public static boolean | parseBoolean(CharSequence csq) Parses the specified character sequence as a boolean .
Parameters: csq - the character sequence to parse. | public static boolean | parseBoolean(String csq) Equivalent to
TypeFormat.parseBoolean(CharSequence)
(for J2ME compatibility). | public static boolean | parseBoolean(CharSequence csq, Cursor cursor) Parses the specified character sequence from the specified position
as a boolean .
Parameters: csq - the character sequence to parse. Parameters: cursor - the current cursor position (being maintained). | public static byte | parseByte(CharSequence csq) Parses the specified character sequence as a signed decimal
byte .
Parameters: csq - the character sequence to parse. | public static byte | parseByte(CharSequence csq, int radix) Parses the specified character sequence as a signed byte
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. | public static byte | parseByte(CharSequence csq, int radix, Cursor cursor) Parses the specified character sequence from the specified position
as a signed byte in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained). | public static int | parseInt(CharSequence csq) Parses the specified character sequence as a signed int .
Parameters: csq - the character sequence to parse. | public static int | parseInt(String str) Equivalent to
TypeFormat.parseInt(CharSequence) (for J2ME compatibility). | public static int | parseInt(CharSequence csq, int radix) Parses the specified character sequence as a signed int
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. | public static int | parseInt(String str, int radix) Equivalent to
TypeFormat.parseInt(CharSequence,int)
(for J2ME compatibility). | public static int | parseInt(CharSequence csq, int radix, Cursor cursor) Parses the specified character sequence from the specified position
as a signed int in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained) ornull if the whole character sequence is parsed. | public static long | parseLong(CharSequence csq) Parses the specified character sequence as a decimal long .
Parameters: csq - the character sequence to parse. | public static long | parseLong(String str) Equivalent to
TypeFormat.parseLong(CharSequence)
(for J2ME compatibility). | public static long | parseLong(CharSequence csq, int radix) Parses the specified character sequence as a signed long
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. | public static long | parseLong(String str, int radix) Equivalent to
TypeFormat.parseLong(CharSequence,int)
(for J2ME compatibility). | public static long | parseLong(CharSequence csq, int radix, Cursor cursor) Parses the specified character sequence from the specified position
as a signed long in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained) ornull if the whole character sequence is parsed. | public static short | parseShort(CharSequence csq) Parses the specified character sequence as a signed decimal
short .
Parameters: csq - the character sequence to parse. | public static short | parseShort(CharSequence csq, int radix) Parses the specified character sequence as a signed short
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. | public static short | parseShort(CharSequence csq, int radix, Cursor cursor) Parses the specified character sequence from the specified position
as a signed short in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained). |
format | public static Appendable format(boolean b, Appendable a) throws IOException(Code) | | Formats the specified boolean and appends the resulting
text to the Appendable argument.
Parameters: b - a boolean . Parameters: a - the Appendable to append. the specified StringBuffer object. throws: IOException - if an I/O exception occurs. See Also: TypeFormat.parseBoolean |
format | public static Appendable format(int i, Appendable a) throws IOException(Code) | | Formats the specified 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).
Parameters: i - the int number. Parameters: a - the Appendable to append. the specified Appendable object. throws: IOException - if an I/O exception occurs. See Also: TypeFormat.parseInt |
format | public static Appendable format(long l, Appendable a) throws IOException(Code) | | Formats the specified 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).
Parameters: l - the long number. Parameters: a - the Appendable to append. the specified Appendable object. throws: IOException - if an I/O exception occurs. See Also: TypeFormat.parseLong |
parseBoolean | public static boolean parseBoolean(CharSequence csq)(Code) | | Parses the specified character sequence as a boolean .
Parameters: csq - the character sequence to parse. the corresponding boolean value. throws: IllegalArgumentException - if the specified character sequence is different from "true" or "false" ignoring cases. |
parseBoolean | public static boolean parseBoolean(CharSequence csq, Cursor cursor)(Code) | | Parses the specified character sequence from the specified position
as a boolean .
Parameters: csq - the character sequence to parse. Parameters: cursor - the current cursor position (being maintained). the next boolean value. throws: IllegalArgumentException - if the character sequence from the specified position is different from "true" or "false" ignoringcases. |
parseByte | public static byte parseByte(CharSequence csq, int radix)(Code) | | Parses the specified character sequence as a signed byte
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. the corresponding byte . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable byte . |
parseByte | public static byte parseByte(CharSequence csq, int radix, Cursor cursor)(Code) | | Parses the specified character sequence from the specified position
as a signed byte in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained). the corresponding byte . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable byte . |
parseInt | public static int parseInt(CharSequence csq, int radix)(Code) | | Parses the specified character sequence as a signed int
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. the corresponding int . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable int . |
parseInt | public static int parseInt(CharSequence csq, int radix, Cursor cursor)(Code) | | Parses the specified character sequence from the specified position
as a signed int in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained) ornull if the whole character sequence is parsed. the corresponding int . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable int . |
parseLong | public static long parseLong(CharSequence csq, int radix)(Code) | | Parses the specified character sequence as a signed long
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. the corresponding long . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable long . |
parseLong | public static long parseLong(CharSequence csq, int radix, Cursor cursor)(Code) | | Parses the specified character sequence from the specified position
as a signed long in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained) ornull if the whole character sequence is parsed. the corresponding long . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable long . |
parseShort | public static short parseShort(CharSequence csq, int radix)(Code) | | Parses the specified character sequence as a signed short
in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. the corresponding short . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable short . |
parseShort | public static short parseShort(CharSequence csq, int radix, Cursor cursor)(Code) | | Parses the specified character sequence from the specified position
as a signed short in the specified radix.
Parameters: csq - the character sequence to parse. Parameters: radix - the radix to be used while parsing. Parameters: cursor - the current cursor position (being maintained). the corresponding short . throws: NumberFormatException - if the specified character sequencedoes not contain a parsable short . |
|
|