1 7 8 20 21 package java.text; 22 23 import java.io.Serializable ; 24 25 116 public abstract class Format implements Serializable , Cloneable { 117 118 private static final long serialVersionUID = -299282585814624189L; 119 120 132 public final String format (Object obj) { 133 return format(obj, new StringBuffer (), new FieldPosition (0)).toString(); 134 } 135 136 154 public abstract StringBuffer format(Object obj, 155 StringBuffer toAppendTo, 156 FieldPosition pos); 157 158 181 public AttributedCharacterIterator formatToCharacterIterator(Object obj) { 182 return createAttributedCharacterIterator(format(obj)); 183 } 184 185 206 public abstract Object parseObject (String source, ParsePosition pos); 207 208 217 public Object parseObject(String source) throws ParseException { 218 ParsePosition pos = new ParsePosition (0); 219 Object result = parseObject(source, pos); 220 if (pos.index == 0) { 221 throw new ParseException ("Format.parseObject(String) failed", 222 pos.errorIndex); 223 } 224 return result; 225 } 226 227 232 public Object clone() { 233 try { 234 return super.clone(); 235 } catch (CloneNotSupportedException e) { 236 return null; 238 } 239 } 240 241 246 253 AttributedCharacterIterator createAttributedCharacterIterator(String s) { 254 AttributedString as = new AttributedString (s); 255 256 return as.getIterator(); 257 } 258 259 269 AttributedCharacterIterator createAttributedCharacterIterator( 270 AttributedCharacterIterator [] iterators) { 271 AttributedString as = new AttributedString (iterators); 272 273 return as.getIterator(); 274 } 275 276 286 AttributedCharacterIterator createAttributedCharacterIterator( 287 String string, AttributedCharacterIterator.Attribute key, 288 Object value) { 289 AttributedString as = new AttributedString (string); 290 291 as.addAttribute(key, value); 292 return as.getIterator(); 293 } 294 295 305 AttributedCharacterIterator createAttributedCharacterIterator( 306 AttributedCharacterIterator iterator, 307 AttributedCharacterIterator.Attribute key, Object value) { 308 AttributedString as = new AttributedString (iterator); 309 310 as.addAttribute(key, value); 311 return as.getIterator(); 312 } 313 314 315 323 public static class Field extends AttributedCharacterIterator.Attribute { 324 325 private static final long serialVersionUID = 276966692217360283L; 327 328 333 protected Field(String name) { 334 super(name); 335 } 336 } 337 338 339 352 interface FieldDelegate { 353 365 public void formatted(Format.Field attr, Object value, int start, 366 int end, StringBuffer buffer); 367 368 379 public void formatted(int fieldID, Format.Field attr, Object value, 380 int start, int end, StringBuffer buffer); 381 } 382 } 383 | Popular Tags |