src/java.base/share/classes/java/text/AttributedString.java
changeset 58242 94bb65cb37d3
parent 57895 82a71d82e326
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
   115     }
   115     }
   116 
   116 
   117     /**
   117     /**
   118      * Constructs an AttributedString instance with the given text.
   118      * Constructs an AttributedString instance with the given text.
   119      * @param text The text for this attributed string.
   119      * @param text The text for this attributed string.
   120      * @exception NullPointerException if <code>text</code> is null.
   120      * @throws    NullPointerException if <code>text</code> is null.
   121      */
   121      */
   122     public AttributedString(String text) {
   122     public AttributedString(String text) {
   123         if (text == null) {
   123         if (text == null) {
   124             throw new NullPointerException();
   124             throw new NullPointerException();
   125         }
   125         }
   128 
   128 
   129     /**
   129     /**
   130      * Constructs an AttributedString instance with the given text and attributes.
   130      * Constructs an AttributedString instance with the given text and attributes.
   131      * @param text The text for this attributed string.
   131      * @param text The text for this attributed string.
   132      * @param attributes The attributes that apply to the entire string.
   132      * @param attributes The attributes that apply to the entire string.
   133      * @exception NullPointerException if <code>text</code> or
   133      * @throws    NullPointerException if <code>text</code> or
   134      *            <code>attributes</code> is null.
   134      *            <code>attributes</code> is null.
   135      * @exception IllegalArgumentException if the text has length 0
   135      * @throws    IllegalArgumentException if the text has length 0
   136      * and the attributes parameter is not an empty Map (attributes
   136      * and the attributes parameter is not an empty Map (attributes
   137      * cannot be applied to a 0-length range).
   137      * cannot be applied to a 0-length range).
   138      */
   138      */
   139     public AttributedString(String text,
   139     public AttributedString(String text,
   140                             Map<? extends Attribute, ?> attributes)
   140                             Map<? extends Attribute, ?> attributes)
   169 
   169 
   170     /**
   170     /**
   171      * Constructs an AttributedString instance with the given attributed
   171      * Constructs an AttributedString instance with the given attributed
   172      * text represented by AttributedCharacterIterator.
   172      * text represented by AttributedCharacterIterator.
   173      * @param text The text for this attributed string.
   173      * @param text The text for this attributed string.
   174      * @exception NullPointerException if <code>text</code> is null.
   174      * @throws    NullPointerException if <code>text</code> is null.
   175      */
   175      */
   176     public AttributedString(AttributedCharacterIterator text) {
   176     public AttributedString(AttributedCharacterIterator text) {
   177         // If performance is critical, this constructor should be
   177         // If performance is critical, this constructor should be
   178         // implemented here rather than invoking the constructor for a
   178         // implemented here rather than invoking the constructor for a
   179         // subrange. We can avoid some range checking in the loops.
   179         // subrange. We can avoid some range checking in the loops.
   190      *
   190      *
   191      * @param text The text for this attributed string.
   191      * @param text The text for this attributed string.
   192      * @param beginIndex Index of the first character of the range.
   192      * @param beginIndex Index of the first character of the range.
   193      * @param endIndex Index of the character following the last character
   193      * @param endIndex Index of the character following the last character
   194      * of the range.
   194      * of the range.
   195      * @exception NullPointerException if <code>text</code> is null.
   195      * @throws    NullPointerException if <code>text</code> is null.
   196      * @exception IllegalArgumentException if the subrange given by
   196      * @throws    IllegalArgumentException if the subrange given by
   197      * beginIndex and endIndex is out of the text range.
   197      * beginIndex and endIndex is out of the text range.
   198      * @see java.text.Annotation
   198      * @see java.text.Annotation
   199      */
   199      */
   200     public AttributedString(AttributedCharacterIterator text,
   200     public AttributedString(AttributedCharacterIterator text,
   201                             int beginIndex,
   201                             int beginIndex,
   218      * @param endIndex Index of the character following the last character
   218      * @param endIndex Index of the character following the last character
   219      * of the range.
   219      * of the range.
   220      * @param attributes Specifies attributes to be extracted
   220      * @param attributes Specifies attributes to be extracted
   221      * from the text. If null is specified, all available attributes will
   221      * from the text. If null is specified, all available attributes will
   222      * be used.
   222      * be used.
   223      * @exception NullPointerException if <code>text</code> is null.
   223      * @throws    NullPointerException if <code>text</code> is null.
   224      * @exception IllegalArgumentException if the subrange given by
   224      * @throws    IllegalArgumentException if the subrange given by
   225      * beginIndex and endIndex is out of the text range.
   225      * beginIndex and endIndex is out of the text range.
   226      * @see java.text.Annotation
   226      * @see java.text.Annotation
   227      */
   227      */
   228     public AttributedString(AttributedCharacterIterator text,
   228     public AttributedString(AttributedCharacterIterator text,
   229                             int beginIndex,
   229                             int beginIndex,
   305 
   305 
   306     /**
   306     /**
   307      * Adds an attribute to the entire string.
   307      * Adds an attribute to the entire string.
   308      * @param attribute the attribute key
   308      * @param attribute the attribute key
   309      * @param value the value of the attribute; may be null
   309      * @param value the value of the attribute; may be null
   310      * @exception NullPointerException if <code>attribute</code> is null.
   310      * @throws    NullPointerException if <code>attribute</code> is null.
   311      * @exception IllegalArgumentException if the AttributedString has length 0
   311      * @throws    IllegalArgumentException if the AttributedString has length 0
   312      * (attributes cannot be applied to a 0-length range).
   312      * (attributes cannot be applied to a 0-length range).
   313      */
   313      */
   314     public void addAttribute(Attribute attribute, Object value) {
   314     public void addAttribute(Attribute attribute, Object value) {
   315 
   315 
   316         if (attribute == null) {
   316         if (attribute == null) {
   329      * Adds an attribute to a subrange of the string.
   329      * Adds an attribute to a subrange of the string.
   330      * @param attribute the attribute key
   330      * @param attribute the attribute key
   331      * @param value The value of the attribute. May be null.
   331      * @param value The value of the attribute. May be null.
   332      * @param beginIndex Index of the first character of the range.
   332      * @param beginIndex Index of the first character of the range.
   333      * @param endIndex Index of the character following the last character of the range.
   333      * @param endIndex Index of the character following the last character of the range.
   334      * @exception NullPointerException if <code>attribute</code> is null.
   334      * @throws    NullPointerException if <code>attribute</code> is null.
   335      * @exception IllegalArgumentException if beginIndex is less than 0, endIndex is
   335      * @throws    IllegalArgumentException if beginIndex is less than 0, endIndex is
   336      * greater than the length of the string, or beginIndex and endIndex together don't
   336      * greater than the length of the string, or beginIndex and endIndex together don't
   337      * define a non-empty subrange of the string.
   337      * define a non-empty subrange of the string.
   338      */
   338      */
   339     public void addAttribute(Attribute attribute, Object value,
   339     public void addAttribute(Attribute attribute, Object value,
   340             int beginIndex, int endIndex) {
   340             int beginIndex, int endIndex) {
   354      * Adds a set of attributes to a subrange of the string.
   354      * Adds a set of attributes to a subrange of the string.
   355      * @param attributes The attributes to be added to the string.
   355      * @param attributes The attributes to be added to the string.
   356      * @param beginIndex Index of the first character of the range.
   356      * @param beginIndex Index of the first character of the range.
   357      * @param endIndex Index of the character following the last
   357      * @param endIndex Index of the character following the last
   358      * character of the range.
   358      * character of the range.
   359      * @exception NullPointerException if <code>attributes</code> is null.
   359      * @throws    NullPointerException if <code>attributes</code> is null.
   360      * @exception IllegalArgumentException if beginIndex is less than
   360      * @throws    IllegalArgumentException if beginIndex is less than
   361      * 0, endIndex is greater than the length of the string, or
   361      * 0, endIndex is greater than the length of the string, or
   362      * beginIndex and endIndex together don't define a non-empty
   362      * beginIndex and endIndex together don't define a non-empty
   363      * subrange of the string and the attributes parameter is not an
   363      * subrange of the string and the attributes parameter is not an
   364      * empty Map.
   364      * empty Map.
   365      */
   365      */
   578      *
   578      *
   579      * @param attributes a list of attributes that the client is interested in
   579      * @param attributes a list of attributes that the client is interested in
   580      * @param beginIndex the index of the first character
   580      * @param beginIndex the index of the first character
   581      * @param endIndex the index of the character following the last character
   581      * @param endIndex the index of the character following the last character
   582      * @return an iterator providing access to the text and its attributes
   582      * @return an iterator providing access to the text and its attributes
   583      * @exception IllegalArgumentException if beginIndex is less than 0,
   583      * @throws    IllegalArgumentException if beginIndex is less than 0,
   584      * endIndex is greater than the length of the string, or beginIndex is
   584      * endIndex is greater than the length of the string, or beginIndex is
   585      * greater than endIndex.
   585      * greater than endIndex.
   586      */
   586      */
   587     public AttributedCharacterIterator getIterator(Attribute[] attributes, int beginIndex, int endIndex) {
   587     public AttributedCharacterIterator getIterator(Attribute[] attributes, int beginIndex, int endIndex) {
   588         return new AttributedStringIterator(attributes, beginIndex, endIndex);
   588         return new AttributedStringIterator(attributes, beginIndex, endIndex);