Class TypeFormat
- java.lang.Object
-
- javolution37.javolution.lang.TypeFormat
-
public final class TypeFormat extends java.lang.ObjectThis class provides utility methods to parse
CharSequenceinto primitive types and to format primitive types into anAppendable.Methods from this class do not create temporary objects and are typically faster than standard library methods (e.g
TypeFormat#parseDoubleis up to 15x faster thanDouble.parseDouble).For non-primitive objects, formatting is typically performed using specialized
TextFormatinstances.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.Appendableformat(boolean b, java.lang.Appendable csq)Formats the specifiedbooleanand appends the resulting text to theAppendableargument.static java.lang.Appendableformat(double value, java.lang.Appendable csq)Formats the specifieddoublevalue.static java.lang.Appendableformat(double value, int digits, boolean scientific, boolean showZero, java.lang.Appendable csq)Formats the specifieddoublevalue according to the specified formatting arguments.static java.lang.Appendableformat(float value, java.lang.Appendable csq)Formats the specifiedfloatvalue.static java.lang.Appendableformat(int i, java.lang.Appendable csq)Formats the specifiedintand appends the resulting text (decimal representation) to theAppendableargument.static java.lang.Appendableformat(int i, int radix, java.lang.Appendable csq)Formats the specifiedintin the specified radix and appends the resulting text to theAppendableargument.static java.lang.Appendableformat(long l, java.lang.Appendable csq)Formats the specifiedlongand appends the resulting text (decimal representation) to theAppendableargument.static java.lang.Appendableformat(long l, int radix, java.lang.Appendable csq)Formats the specifiedlongin the specified radix and appends the resulting text to theAppendableargument.static booleanparseBoolean(java.lang.CharSequence csq)Parses the specified character sequence as aboolean.static booleanparseBoolean(java.lang.CharSequence csq, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as aboolean.static byteparseByte(java.lang.CharSequence csq)Parses the specified character sequence as a signed decimalbyte.static byteparseByte(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedbytein the specified radix.static byteparseByte(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedbytein the specified radix.static doubleparseDouble(java.lang.CharSequence csq)Parses the specified character sequence as adouble.static doubleparseDouble(java.lang.CharSequence csq, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as adouble.static floatparseFloat(java.lang.CharSequence csq)Parses the specified character sequence as afloat.static floatparseFloat(java.lang.CharSequence csq, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as afloat.static intparseInt(java.lang.CharSequence csq)Parses the specified character sequence as a signedint.static intparseInt(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedintin the specified radix.static intparseInt(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedintin the specified radix.static longparseLong(java.lang.CharSequence csq)Parses the specified character sequence as a decimallong.static longparseLong(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedlongin the specified radix.static longparseLong(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedlongin the specified radix.static shortparseShort(java.lang.CharSequence csq)Parses the specified character sequence as a signed decimalshort.static shortparseShort(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedshortin the specified radix.static shortparseShort(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedshortin the specified radix.
-
-
-
Method Detail
-
parseBoolean
public static boolean parseBoolean(java.lang.CharSequence csq)
Parses the specified character sequence as aboolean.- Parameters:
csq- the character sequence to parse.- Returns:
- the corresponding boolean value.
- Throws:
java.lang.IllegalArgumentException- if the specified character sequence is different from "true" or "false" ignoring cases.
-
parseBoolean
public static boolean parseBoolean(java.lang.CharSequence csq, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as aboolean.- Parameters:
csq- the character sequence to parse.cursor- the current cursor position (being maintained).- Returns:
- the next boolean value.
- Throws:
java.lang.IllegalArgumentException- if the character sequence from the specified position is different from "true" or "false" ignoring cases.
-
parseByte
public static byte parseByte(java.lang.CharSequence csq)
Parses the specified character sequence as a signed decimalbyte.- Parameters:
csq- the character sequence to parse.- Returns:
parseByte(csq, 10)- Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablebyte.- See Also:
parseByte(CharSequence, int)
-
parseByte
public static byte parseByte(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedbytein the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.- Returns:
- the corresponding
byte. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablebyte.
-
parseByte
public static byte parseByte(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedbytein the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.cursor- the current cursor position (being maintained).- Returns:
- the corresponding
byte. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablebyte.
-
parseShort
public static short parseShort(java.lang.CharSequence csq)
Parses the specified character sequence as a signed decimalshort.- Parameters:
csq- the character sequence to parse.- Returns:
parseShort(csq, 10)- Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableshort.- See Also:
parseShort(CharSequence, int)
-
parseShort
public static short parseShort(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedshortin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.- Returns:
- the corresponding
short. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableshort.
-
parseShort
public static short parseShort(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedshortin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.cursor- the current cursor position (being maintained).- Returns:
- the corresponding
short. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableshort.
-
parseInt
public static int parseInt(java.lang.CharSequence csq)
Parses the specified character sequence as a signedint.- Parameters:
csq- the character sequence to parse.- Returns:
parseInt(csq, 10)- Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableint.- See Also:
parseInt(CharSequence, int)
-
parseInt
public static int parseInt(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedintin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.- Returns:
- the corresponding
int. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableint.
-
parseInt
public static int parseInt(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedintin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.cursor- the current cursor position (being maintained).- Returns:
- the corresponding
int. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsableint.
-
parseLong
public static long parseLong(java.lang.CharSequence csq)
Parses the specified character sequence as a decimallong.- Parameters:
csq- the character sequence to parse.- Returns:
parseLong(csq, 10)- Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablelong.- See Also:
parseLong(CharSequence, int)
-
parseLong
public static long parseLong(java.lang.CharSequence csq, int radix)Parses the specified character sequence as a signedlongin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.- Returns:
- the corresponding
long. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablelong.
-
parseLong
public static long parseLong(java.lang.CharSequence csq, int radix, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as a signedlongin the specified radix.- Parameters:
csq- the character sequence to parse.radix- the radix to be used while parsing.cursor- the current cursor position (being maintained).- Returns:
- the corresponding
long. - Throws:
java.lang.NumberFormatException- if the specified character sequence does not contain a parsablelong.
-
parseFloat
public static float parseFloat(java.lang.CharSequence csq)
Parses the specified character sequence as afloat.- Parameters:
csq- the character sequence to parse.- Returns:
- the float number represented by the specified character sequence.
- Throws:
java.lang.NumberFormatException- if the character sequence does not contain a parsablefloat. /
-
parseFloat
public static float parseFloat(java.lang.CharSequence csq, TextFormat.Cursor cursor)Parses the specified character sequence from the specified position as afloat.- Parameters:
csq- the character sequence to parse.cursor- the current cursor position (being maintained).- Returns:
- the float number represented by the specified character sequence.
- Throws:
java.lang.NumberFormatException- if the character sequence does not contain a parsablefloat. /
-
parseDouble
public static double parseDouble(java.lang.CharSequence csq) throws java.lang.NumberFormatExceptionParses the specified character sequence as adouble.- Parameters:
csq- the character sequence to parse.- Returns:
- the double number represented by this character sequence.
- Throws:
java.lang.NumberFormatException- if the character sequence does not contain a parsabledouble. /
-
parseDouble
public static double parseDouble(java.lang.CharSequence csq, TextFormat.Cursor cursor) throws java.lang.NumberFormatExceptionParses the specified character sequence from the specified position as adouble.- Parameters:
csq- the character sequence to parse.cursor- the current cursor position (being maintained).- Returns:
- the double number represented by this character sequence.
- Throws:
java.lang.NumberFormatException- if the character sequence does not contain a parsabledouble. /
-
format
public static java.lang.Appendable format(boolean b, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedbooleanand appends the resulting text to theAppendableargument.- Parameters:
b- aboolean.csq- theAppendableto append.- Returns:
- the specified
StringBufferobject. - Throws:
java.io.IOException- if an I/O exception occurs.- See Also:
parseBoolean(java.lang.CharSequence)
-
format
public static java.lang.Appendable format(int i, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedintand appends the resulting text (decimal representation) to theAppendableargument.Note: This method is preferred to
Appendable.append(int)as it does not create temporaryStringobjects (several times faster for small numbers).- Parameters:
i- theintnumber.csq- theAppendableto append.- Returns:
- the specified
Appendableobject. - Throws:
java.io.IOException- if an I/O exception occurs.- See Also:
parseInt(java.lang.CharSequence)
-
format
public static java.lang.Appendable format(int i, int radix, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedintin the specified radix and appends the resulting text to theAppendableargument.- Parameters:
i- theintnumber.radix- the radix.csq- theAppendableto append.- Returns:
- the specified
Appendableobject. - Throws:
java.lang.IllegalArgumentException- if radix is not in [2 .. 36] range.java.io.IOException- if an I/O exception occurs.- See Also:
parseInt(CharSequence, int)
-
format
public static java.lang.Appendable format(long l, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedlongand appends the resulting text (decimal representation) to theAppendableargument.Note: This method is preferred to
Appendable.append(long)as it does not create temporaryStringobjects (several times faster for small numbers).- Parameters:
l- thelongnumber.csq- theAppendableto append.- Returns:
- the specified
Appendableobject. - Throws:
java.io.IOException- if an I/O exception occurs.- See Also:
parseLong(java.lang.CharSequence)
-
format
public static java.lang.Appendable format(long l, int radix, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedlongin the specified radix and appends the resulting text to theAppendableargument.- Parameters:
l- thelongnumber.radix- the radix.csq- theAppendableto append.- Returns:
- the specified
Appendableobject. - Throws:
java.lang.IllegalArgumentException- if radix is not in [2 .. 36] range.java.io.IOException- if an I/O exception occurs.- See Also:
parseLong(CharSequence, int)
-
format
public static java.lang.Appendable format(float value, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifiedfloatvalue.- Parameters:
value- thefloatvalue.csq- theAppendableto append.- Returns:
format(value, 10, Math.abs(value) > 1E7, false, sb)- Throws:
java.io.IOException- if an I/O exception occurs.- See Also:
/
-
format
public static java.lang.Appendable format(double value, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifieddoublevalue.Note : This method is preferred to
Double.toString(double)or evenString.valueOf(double)as it does not create temporaryStringorFloatingDecimalobjects (several times faster, e.g. 15x faster forDouble.MAX_VALUE).- Parameters:
value- thedoublevalue.csq- theAppendableto append.- Returns:
format(value, 17, Math.abs(value) > 1E7, false, sb)- Throws:
java.io.IOException- if an I/O exception occurs.- See Also:
/
-
format
public static java.lang.Appendable format(double value, int digits, boolean scientific, boolean showZero, java.lang.Appendable csq) throws java.io.IOExceptionFormats the specifieddoublevalue according to the specified formatting arguments.- Parameters:
value- thedoublevalue.digits- the number of significative digits (excludes exponent).scientific-trueto forces the use of the scientific notation (e.g.1.23E3);falseotherwise.showZero-trueif trailing fractional zeros are represented;falseotherwise.csq- theAppendableto append.- Returns:
- the specified
Appendableobject. - Throws:
java.lang.IllegalArgumentException- if((digits > 19) || (digits <= 0)))java.io.IOException- if an I/O exception occurs. /
-
-
DMelt 3.0 © DataMelt by jWork.ORG