code: public void addAttributes(Map<? extends Attribute, ?> attributes,
                                int beginIndex, int endIndex)
      {
          if (attributes == null) {
              throw new NullPointerException();
          }
  
          if (beginIndex < 0 || endIndex > length() || beginIndex > endIndex) {
              throw new IllegalArgumentException("Invalid substring range");
          }
          if (beginIndex == endIndex) {
              if (attributes.isEmpty())
                  return;
              throw new IllegalArgumentException("Can't add attribute to 0-length text");
          }
  
          // make sure we have run attribute data vectors
          if (runCount == 0) {
              createRunAttributeDataVectors();
          }
  
          // break up runs if necessary
          int beginRunIndex = ensureRunBreak(beginIndex);
          int endRunIndex = ensureRunBreak(endIndex);
  
          Iterator iterator = attributes.entrySet().iterator();
          while (iterator.hasNext()) {
              Map.Entry entry = (Map.Entry) iterator.next();
              addAttributeRunData((Attribute) entry.getKey(), entry.getValue(), beginRunIndex, endRunIndex);
          }
      }
docs: Adds a set of attributes to a subrange of the string.
  @param attributes The attributes to be added to the string.
  @param beginIndex Index of the first character of the range.
  @param endIndex Index of the character following the last
  character of the range.
  @exception NullPointerException if <code>attributes</code> is null.
  @exception IllegalArgumentException if beginIndex is less then
  0, endIndex is greater than the length of the string, or
  beginIndex and endIndex together don't define a non-empty
  subrange of the string and the attributes parameter is not an
  empty Map.