Javolution 6.0.0 java
TextFormat.java
Go to the documentation of this file.
1 /*
2  * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
3  * Copyright (C) 2012 - Javolution (http://javolution.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */
9 package javolution.text;
10 
11 import java.io.IOException;
12 
14 
51 @Parallelizable
52 public abstract class TextFormat<T> {
53 
67  public abstract T parse(CharSequence csq, Cursor cursor);
68 
76  public abstract Appendable format(T obj, Appendable dest)
77  throws IOException;
78 
89  public T parse(CharSequence csq) throws IllegalArgumentException {
90  Cursor cursor = new Cursor();
91  T obj = parse(csq, cursor);
92  if (!cursor.atEnd(csq))
93  throw new IllegalArgumentException("Extraneous character(s) \""
94  + cursor.tail(csq) + "\"");
95  return obj;
96  }
97 
106  public TextBuilder format(T obj, TextBuilder dest) {
107  try {
108  this.format(obj, (Appendable) dest);
109  return dest;
110  } catch (IOException e) {
111  throw new Error(e); // Cannot happens.
112  }
113  }
114 
121  public String format(T obj) {
122  return this.format(obj, new TextBuilder()).toString();
123 
124  }
125 }
javolution.lang.Parallelizable
Definition: Parallelizable.java:55
javolution
javolution.text.TextFormat.format
String format(T obj)
Definition: TextFormat.java:121
javolution.text.TextBuilder
Definition: TextBuilder.java:29
javolution.text.TextFormat.parse
abstract T parse(CharSequence csq, Cursor cursor)
javolution.text.Cursor
Definition: Cursor.java:44
javolution.lang
Definition: Configurable.java:9
javolution.text.TextFormat.format
TextBuilder format(T obj, TextBuilder dest)
Definition: TextFormat.java:106
javolution.text.TextFormat.parse
T parse(CharSequence csq)
Definition: TextFormat.java:89
javolution.text.Cursor.tail
final CharSequence tail(CharSequence csq)
Definition: Cursor.java:339
javolution.text.TextFormat.format
abstract Appendable format(T obj, Appendable dest)
javolution.text.TextFormat
Definition: TextFormat.java:52
javolution.text.Cursor.atEnd
final boolean atEnd(CharSequence csq)
Definition: Cursor.java:81