Javolution 6.0.0 java
|
Public Member Functions | |
abstract T | parse (CharSequence csq, Cursor cursor) |
abstract Appendable | format (T obj, Appendable dest) throws IOException |
T | parse (CharSequence csq) throws IllegalArgumentException |
TextBuilder | format (T obj, TextBuilder dest) |
String | format (T obj) |
The service for plain text parsing and formatting; it supports CharSequence and Appendable interfaces for greater flexibility.
Instances of this class are typically retrieved from the current TextContext (OSGi service or not). [code] @DefaultTextFormat(Complex.Cartesian.class) public class Complex extends Number { public static Complex valueOf(CharSequence csq) { return TextContext.getFormat(Complex.class).parse(csq); } public String toString() { return TextContext.getFormat(Complex.class).format(this); } public static class Cartesian extends javolution.text.TextFormat<Complex> { ... } public static class Polar extends javolution.text.TextFormat<Complex> { ... } }[/code]
Text formats can be locally overridden. [code] TextContext ctx = TextContext.enter(); try { ctx.setFormat(Complex.class, Complex.Polar.class); // No impact on others threads. System.out.println(complexMatrix); // Displays complex numbers in polar coordinates. } finally { ctx.exit(); // Reverts to previous cartesian format for complex numbers. }[/code]
For parsing/formatting of primitive types, the TypeFormat utility class is recommended.
Definition at line 52 of file TextFormat.java.
String javolution.text.TextFormat< T >.format | ( | T | obj | ) |
Convenience method to format the specified object to a String.
obj | the object to format. |
Definition at line 121 of file TextFormat.java.
|
abstract |
Formats the specified object into an Appendable
obj | the object to format. |
dest | the appendable destination. |
Appendable
. Referenced by javolution.text.TextBuilder.append(), javolution.text.TextFormat< FastCollection<?> >.format(), and javolution.util.FastCollection< E >.Format.format().
TextBuilder javolution.text.TextFormat< T >.format | ( | T | obj, |
TextBuilder | dest | ||
) |
Convenience method to format the specified object to a TextBuilder; unlike the abstract format method, this method does not throw IOException.
obj | the object to format. |
dest | the appendable destination. |
TextBuilder
. Definition at line 106 of file TextFormat.java.
T javolution.text.TextFormat< T >.parse | ( | CharSequence | csq | ) | throws IllegalArgumentException |
Convenience method to parse the whole character sequence; if there are unread extraneous characters after parsing then an exception is raised.
csq | the CharSequence to parse from the first character to the last. |
IllegalArgumentException | if the syntax of the specified character sequence is incorrect or if there are extraneous characters at the end not parsed. |
Definition at line 89 of file TextFormat.java.
|
abstract |
Reads a portion of the specified CharSequence
from the specified cursor position to produce an object. If parsing succeeds, then the index of the cursor
argument is updated to the index after the last character used.
csq | the character sequence to parse. |
cursor | the cursor holding the current parsing index. |
IllegalArgumentException | if the syntax of the specified character sequence is incorrect. |
UnsupportedOperationException | if parsing is not supported. |
Reimplemented in javolution.util.FastCollection< E >.Format, and javolution.util.Index.Decimal.
Referenced by javolution.xml.XMLFormat< T >.InputElement.getAttribute(), javolution.xml.XMLFormat< T >.Default.newInstance(), and javolution.text.TextFormat< FastCollection<?> >.parse().