< prev index next >

src/java.base/share/classes/java/text/Format.java

Print this page




 116  * friends in {@link DateFormat}.
 117  *
 118  * <h3><a id="synchronization">Synchronization</a></h3>
 119  *
 120  * <p>
 121  * Formats are generally not synchronized.
 122  * It is recommended to create separate format instances for each thread.
 123  * If multiple threads access a format concurrently, it must be synchronized
 124  * externally.
 125  *
 126  * @see          java.text.ParsePosition
 127  * @see          java.text.FieldPosition
 128  * @see          java.text.NumberFormat
 129  * @see          java.text.DateFormat
 130  * @see          java.text.MessageFormat
 131  * @author       Mark Davis
 132  * @since 1.1
 133  */
 134 public abstract class Format implements Serializable, Cloneable {
 135 

 136     private static final long serialVersionUID = -299282585814624189L;
 137 
 138     /**
 139      * Sole constructor.  (For invocation by subclass constructors, typically
 140      * implicit.)
 141      */
 142     protected Format() {
 143     }
 144 
 145     /**
 146      * Formats an object to produce a string. This is equivalent to
 147      * <blockquote>
 148      * {@link #format(Object, StringBuffer, FieldPosition) format}<code>(obj,
 149      *         new StringBuffer(), new FieldPosition(0)).toString();</code>
 150      * </blockquote>
 151      *
 152      * @param obj    The object to format
 153      * @return       Formatted string.
 154      * @exception IllegalArgumentException if the Format cannot format the given
 155      *            object


 332               AttributedCharacterIterator iterator,
 333               AttributedCharacterIterator.Attribute key, Object value) {
 334         AttributedString as = new AttributedString(iterator);
 335 
 336         as.addAttribute(key, value);
 337         return as.getIterator();
 338     }
 339 
 340 
 341     /**
 342      * Defines constants that are used as attribute keys in the
 343      * <code>AttributedCharacterIterator</code> returned
 344      * from <code>Format.formatToCharacterIterator</code> and as
 345      * field identifiers in <code>FieldPosition</code>.
 346      *
 347      * @since 1.4
 348      */
 349     public static class Field extends AttributedCharacterIterator.Attribute {
 350 
 351         // Proclaim serial compatibility with 1.4 FCS

 352         private static final long serialVersionUID = 276966692217360283L;
 353 
 354         /**
 355          * Creates a Field with the specified name.
 356          *
 357          * @param name Name of the attribute
 358          */
 359         protected Field(String name) {
 360             super(name);
 361         }
 362     }
 363 
 364 
 365     /**
 366      * FieldDelegate is notified by the various <code>Format</code>
 367      * implementations as they are formatting the Objects. This allows for
 368      * storage of the individual sections of the formatted String for
 369      * later use, such as in a <code>FieldPosition</code> or for an
 370      * <code>AttributedCharacterIterator</code>.
 371      * <p>




 116  * friends in {@link DateFormat}.
 117  *
 118  * <h3><a id="synchronization">Synchronization</a></h3>
 119  *
 120  * <p>
 121  * Formats are generally not synchronized.
 122  * It is recommended to create separate format instances for each thread.
 123  * If multiple threads access a format concurrently, it must be synchronized
 124  * externally.
 125  *
 126  * @see          java.text.ParsePosition
 127  * @see          java.text.FieldPosition
 128  * @see          java.text.NumberFormat
 129  * @see          java.text.DateFormat
 130  * @see          java.text.MessageFormat
 131  * @author       Mark Davis
 132  * @since 1.1
 133  */
 134 public abstract class Format implements Serializable, Cloneable {
 135 
 136     @java.io.Serial
 137     private static final long serialVersionUID = -299282585814624189L;
 138 
 139     /**
 140      * Sole constructor.  (For invocation by subclass constructors, typically
 141      * implicit.)
 142      */
 143     protected Format() {
 144     }
 145 
 146     /**
 147      * Formats an object to produce a string. This is equivalent to
 148      * <blockquote>
 149      * {@link #format(Object, StringBuffer, FieldPosition) format}<code>(obj,
 150      *         new StringBuffer(), new FieldPosition(0)).toString();</code>
 151      * </blockquote>
 152      *
 153      * @param obj    The object to format
 154      * @return       Formatted string.
 155      * @exception IllegalArgumentException if the Format cannot format the given
 156      *            object


 333               AttributedCharacterIterator iterator,
 334               AttributedCharacterIterator.Attribute key, Object value) {
 335         AttributedString as = new AttributedString(iterator);
 336 
 337         as.addAttribute(key, value);
 338         return as.getIterator();
 339     }
 340 
 341 
 342     /**
 343      * Defines constants that are used as attribute keys in the
 344      * <code>AttributedCharacterIterator</code> returned
 345      * from <code>Format.formatToCharacterIterator</code> and as
 346      * field identifiers in <code>FieldPosition</code>.
 347      *
 348      * @since 1.4
 349      */
 350     public static class Field extends AttributedCharacterIterator.Attribute {
 351 
 352         // Proclaim serial compatibility with 1.4 FCS
 353         @java.io.Serial
 354         private static final long serialVersionUID = 276966692217360283L;
 355 
 356         /**
 357          * Creates a Field with the specified name.
 358          *
 359          * @param name Name of the attribute
 360          */
 361         protected Field(String name) {
 362             super(name);
 363         }
 364     }
 365 
 366 
 367     /**
 368      * FieldDelegate is notified by the various <code>Format</code>
 369      * implementations as they are formatting the Objects. This allows for
 370      * storage of the individual sections of the formatted String for
 371      * later use, such as in a <code>FieldPosition</code> or for an
 372      * <code>AttributedCharacterIterator</code>.
 373      * <p>


< prev index next >