jdk/src/share/classes/java/lang/AbstractStringBuilder.java
changeset 1223 5c1037124466
parent 2 90ce3da70b43
child 1247 b4c26443dee5
equal deleted inserted replaced
1222:78e3d021d528 1223:5c1037124466
    40  */
    40  */
    41 abstract class AbstractStringBuilder implements Appendable, CharSequence {
    41 abstract class AbstractStringBuilder implements Appendable, CharSequence {
    42     /**
    42     /**
    43      * The value is used for character storage.
    43      * The value is used for character storage.
    44      */
    44      */
    45     char value[];
    45     char[] value;
    46 
    46 
    47     /**
    47     /**
    48      * The count is the number of characters used.
    48      * The count is the number of characters used.
    49      */
    49      */
    50     int count;
    50     int count;
   331      *             <code>this.length()</code>.
   331      *             <code>this.length()</code>.
   332      *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
   332      *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
   333      *             <code>dst.length</code>
   333      *             <code>dst.length</code>
   334      *             </ul>
   334      *             </ul>
   335      */
   335      */
   336     public void getChars(int srcBegin, int srcEnd, char dst[],
   336     public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
   337                                       int dstBegin)
       
   338     {
   337     {
   339         if (srcBegin < 0)
   338         if (srcBegin < 0)
   340             throw new StringIndexOutOfBoundsException(srcBegin);
   339             throw new StringIndexOutOfBoundsException(srcBegin);
   341         if ((srcEnd < 0) || (srcEnd > count))
   340         if ((srcEnd < 0) || (srcEnd > count))
   342             throw new StringIndexOutOfBoundsException(srcEnd);
   341             throw new StringIndexOutOfBoundsException(srcEnd);
   364             throw new StringIndexOutOfBoundsException(index);
   363             throw new StringIndexOutOfBoundsException(index);
   365         value[index] = ch;
   364         value[index] = ch;
   366     }
   365     }
   367 
   366 
   368     /**
   367     /**
   369      * Appends the string representation of the <code>Object</code>
   368      * Appends the string representation of the {@code Object} argument.
   370      * argument.
   369      * <p>
   371      * <p>
   370      * The overall effect is exactly as if the argument were converted
   372      * The argument is converted to a string as if by the method
   371      * to a string by the method {@link String#valueOf(Object)},
   373      * <code>String.valueOf</code>, and the characters of that
   372      * and the characters of that string were then
   374      * string are then appended to this sequence.
   373      * {@link #append(String) appended} to this character sequence.
   375      *
   374      *
   376      * @param   obj   an <code>Object</code>.
   375      * @param   obj   an {@code Object}.
   377      * @return  a reference to this object.
   376      * @return  a reference to this object.
   378      */
   377      */
   379     public AbstractStringBuilder append(Object obj) {
   378     public AbstractStringBuilder append(Object obj) {
   380         return append(String.valueOf(obj));
   379         return append(String.valueOf(obj));
   381     }
   380     }
   382 
   381 
   383     /**
   382     /**
   384      * Appends the specified string to this character sequence.
   383      * Appends the specified string to this character sequence.
   385      * <p>
   384      * <p>
   386      * The characters of the <code>String</code> argument are appended, in
   385      * The characters of the {@code String} argument are appended, in
   387      * order, increasing the length of this sequence by the length of the
   386      * order, increasing the length of this sequence by the length of the
   388      * argument. If <code>str</code> is <code>null</code>, then the four
   387      * argument. If {@code str} is {@code null}, then the four
   389      * characters <code>"null"</code> are appended.
   388      * characters {@code "null"} are appended.
   390      * <p>
   389      * <p>
   391      * Let <i>n</i> be the length of this character sequence just prior to
   390      * Let <i>n</i> be the length of this character sequence just prior to
   392      * execution of the <code>append</code> method. Then the character at
   391      * execution of the {@code append} method. Then the character at
   393      * index <i>k</i> in the new character sequence is equal to the character
   392      * index <i>k</i> in the new character sequence is equal to the character
   394      * at index <i>k</i> in the old character sequence, if <i>k</i> is less
   393      * at index <i>k</i> in the old character sequence, if <i>k</i> is less
   395      * than <i>n</i>; otherwise, it is equal to the character at index
   394      * than <i>n</i>; otherwise, it is equal to the character at index
   396      * <i>k-n</i> in the argument <code>str</code>.
   395      * <i>k-n</i> in the argument {@code str}.
   397      *
   396      *
   398      * @param   str   a string.
   397      * @param   str   a string.
   399      * @return  a reference to this object.
   398      * @return  a reference to this object.
   400      */
   399      */
   401     public AbstractStringBuilder append(String str) {
   400     public AbstractStringBuilder append(String str) {
   433             return this.append((StringBuffer)s);
   432             return this.append((StringBuffer)s);
   434         return this.append(s, 0, s.length());
   433         return this.append(s, 0, s.length());
   435     }
   434     }
   436 
   435 
   437     /**
   436     /**
   438      * Appends a subsequence of the specified <code>CharSequence</code> to this
   437      * Appends a subsequence of the specified {@code CharSequence} to this
   439      * sequence.
   438      * sequence.
   440      * <p>
   439      * <p>
   441      * Characters of the argument <code>s</code>, starting at
   440      * Characters of the argument {@code s}, starting at
   442      * index <code>start</code>, are appended, in order, to the contents of
   441      * index {@code start}, are appended, in order, to the contents of
   443      * this sequence up to the (exclusive) index <code>end</code>. The length
   442      * this sequence up to the (exclusive) index {@code end}. The length
   444      * of this sequence is increased by the value of <code>end - start</code>.
   443      * of this sequence is increased by the value of {@code end - start}.
   445      * <p>
   444      * <p>
   446      * Let <i>n</i> be the length of this character sequence just prior to
   445      * Let <i>n</i> be the length of this character sequence just prior to
   447      * execution of the <code>append</code> method. Then the character at
   446      * execution of the {@code append} method. Then the character at
   448      * index <i>k</i> in this character sequence becomes equal to the
   447      * index <i>k</i> in this character sequence becomes equal to the
   449      * character at index <i>k</i> in this sequence, if <i>k</i> is less than
   448      * character at index <i>k</i> in this sequence, if <i>k</i> is less than
   450      * <i>n</i>; otherwise, it is equal to the character at index
   449      * <i>n</i>; otherwise, it is equal to the character at index
   451      * <i>k+start-n</i> in the argument <code>s</code>.
   450      * <i>k+start-n</i> in the argument {@code s}.
   452      * <p>
   451      * <p>
   453      * If <code>s</code> is <code>null</code>, then this method appends
   452      * If {@code s} is {@code null}, then this method appends
   454      * characters as if the s parameter was a sequence containing the four
   453      * characters as if the s parameter was a sequence containing the four
   455      * characters <code>"null"</code>.
   454      * characters {@code "null"}.
   456      *
   455      *
   457      * @param   s the sequence to append.
   456      * @param   s the sequence to append.
   458      * @param   start   the starting index of the subsequence to be appended.
   457      * @param   start   the starting index of the subsequence to be appended.
   459      * @param   end     the end index of the subsequence to be appended.
   458      * @param   end     the end index of the subsequence to be appended.
   460      * @return  a reference to this object.
   459      * @return  a reference to this object.
   461      * @throws     IndexOutOfBoundsException if
   460      * @throws     IndexOutOfBoundsException if
   462      *                  <code>start</code> or <code>end</code> are negative, or
   461      *             {@code start} is negative, or
   463      *             <code>start</code> is greater than <code>end</code> or
   462      *             {@code start} is greater than {@code end} or
   464      *             <code>end</code> is greater than <code>s.length()</code>
   463      *             {@code end} is greater than {@code s.length()}
   465      */
   464      */
   466     public AbstractStringBuilder append(CharSequence s, int start, int end) {
   465     public AbstractStringBuilder append(CharSequence s, int start, int end) {
   467         if (s == null)
   466         if (s == null)
   468             s = "null";
   467             s = "null";
   469         if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
   468         if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
   481         count = newCount;
   480         count = newCount;
   482         return this;
   481         return this;
   483     }
   482     }
   484 
   483 
   485     /**
   484     /**
   486      * Appends the string representation of the <code>char</code> array
   485      * Appends the string representation of the {@code char} array
   487      * argument to this sequence.
   486      * argument to this sequence.
   488      * <p>
   487      * <p>
   489      * The characters of the array argument are appended, in order, to
   488      * The characters of the array argument are appended, in order, to
   490      * the contents of this sequence. The length of this sequence
   489      * the contents of this sequence. The length of this sequence
   491      * increases by the length of the argument.
   490      * increases by the length of the argument.
   492      * <p>
   491      * <p>
   493      * The overall effect is exactly as if the argument were converted to
   492      * The overall effect is exactly as if the argument were converted
   494      * a string by the method {@link String#valueOf(char[])} and the
   493      * to a string by the method {@link String#valueOf(char[])},
   495      * characters of that string were then {@link #append(String) appended}
   494      * and the characters of that string were then
   496      * to this character sequence.
   495      * {@link #append(String) appended} to this character sequence.
   497      *
   496      *
   498      * @param   str   the characters to be appended.
   497      * @param   str   the characters to be appended.
   499      * @return  a reference to this object.
   498      * @return  a reference to this object.
   500      */
   499      */
   501     public AbstractStringBuilder append(char str[]) {
   500     public AbstractStringBuilder append(char[] str) {
   502         int newCount = count + str.length;
   501         int newCount = count + str.length;
   503         if (newCount > value.length)
   502         if (newCount > value.length)
   504             expandCapacity(newCount);
   503             expandCapacity(newCount);
   505         System.arraycopy(str, 0, value, count, str.length);
   504         System.arraycopy(str, 0, value, count, str.length);
   506         count = newCount;
   505         count = newCount;
   507         return this;
   506         return this;
   508     }
   507     }
   509 
   508 
   510     /**
   509     /**
   511      * Appends the string representation of a subarray of the
   510      * Appends the string representation of a subarray of the
   512      * <code>char</code> array argument to this sequence.
   511      * {@code char} array argument to this sequence.
   513      * <p>
   512      * <p>
   514      * Characters of the <code>char</code> array <code>str</code>, starting at
   513      * Characters of the {@code char} array {@code str}, starting at
   515      * index <code>offset</code>, are appended, in order, to the contents
   514      * index {@code offset}, are appended, in order, to the contents
   516      * of this sequence. The length of this sequence increases
   515      * of this sequence. The length of this sequence increases
   517      * by the value of <code>len</code>.
   516      * by the value of {@code len}.
   518      * <p>
   517      * <p>
   519      * The overall effect is exactly as if the arguments were converted to
   518      * The overall effect is exactly as if the arguments were converted
   520      * a string by the method {@link String#valueOf(char[],int,int)} and the
   519      * to a string by the method {@link String#valueOf(char[],int,int)},
   521      * characters of that string were then {@link #append(String) appended}
   520      * and the characters of that string were then
   522      * to this character sequence.
   521      * {@link #append(String) appended} to this character sequence.
   523      *
   522      *
   524      * @param   str      the characters to be appended.
   523      * @param   str      the characters to be appended.
   525      * @param   offset   the index of the first <code>char</code> to append.
   524      * @param   offset   the index of the first {@code char} to append.
   526      * @param   len      the number of <code>char</code>s to append.
   525      * @param   len      the number of {@code char}s to append.
   527      * @return  a reference to this object.
   526      * @return  a reference to this object.
       
   527      * @throws IndexOutOfBoundsException
       
   528      *         if {@code offset < 0} or {@code len < 0}
       
   529      *         or {@code offset+len > str.length}
   528      */
   530      */
   529     public AbstractStringBuilder append(char str[], int offset, int len) {
   531     public AbstractStringBuilder append(char str[], int offset, int len) {
   530         int newCount = count + len;
   532         int newCount = count + len;
   531         if (newCount > value.length)
   533         if (newCount > value.length)
   532             expandCapacity(newCount);
   534             expandCapacity(newCount);
   534         count = newCount;
   536         count = newCount;
   535         return this;
   537         return this;
   536     }
   538     }
   537 
   539 
   538     /**
   540     /**
   539      * Appends the string representation of the <code>boolean</code>
   541      * Appends the string representation of the {@code boolean}
   540      * argument to the sequence.
   542      * argument to the sequence.
   541      * <p>
   543      * <p>
   542      * The argument is converted to a string as if by the method
   544      * The overall effect is exactly as if the argument were converted
   543      * <code>String.valueOf</code>, and the characters of that
   545      * to a string by the method {@link String#valueOf(boolean)},
   544      * string are then appended to this sequence.
   546      * and the characters of that string were then
   545      *
   547      * {@link #append(String) appended} to this character sequence.
   546      * @param   b   a <code>boolean</code>.
   548      *
       
   549      * @param   b   a {@code boolean}.
   547      * @return  a reference to this object.
   550      * @return  a reference to this object.
   548      */
   551      */
   549     public AbstractStringBuilder append(boolean b) {
   552     public AbstractStringBuilder append(boolean b) {
   550         if (b) {
   553         if (b) {
   551             int newCount = count + 4;
   554             int newCount = count + 4;
   567         }
   570         }
   568         return this;
   571         return this;
   569     }
   572     }
   570 
   573 
   571     /**
   574     /**
   572      * Appends the string representation of the <code>char</code>
   575      * Appends the string representation of the {@code char}
   573      * argument to this sequence.
   576      * argument to this sequence.
   574      * <p>
   577      * <p>
   575      * The argument is appended to the contents of this sequence.
   578      * The argument is appended to the contents of this sequence.
   576      * The length of this sequence increases by <code>1</code>.
   579      * The length of this sequence increases by {@code 1}.
   577      * <p>
   580      * <p>
   578      * The overall effect is exactly as if the argument were converted to
   581      * The overall effect is exactly as if the argument were converted
   579      * a string by the method {@link String#valueOf(char)} and the character
   582      * to a string by the method {@link String#valueOf(char)},
   580      * in that string were then {@link #append(String) appended} to this
   583      * and the character in that string were then
   581      * character sequence.
   584      * {@link #append(String) appended} to this character sequence.
   582      *
   585      *
   583      * @param   c   a <code>char</code>.
   586      * @param   c   a {@code char}.
   584      * @return  a reference to this object.
   587      * @return  a reference to this object.
   585      */
   588      */
   586     public AbstractStringBuilder append(char c) {
   589     public AbstractStringBuilder append(char c) {
   587         int newCount = count + 1;
   590         int newCount = count + 1;
   588         if (newCount > value.length)
   591         if (newCount > value.length)
   590         value[count++] = c;
   593         value[count++] = c;
   591         return this;
   594         return this;
   592     }
   595     }
   593 
   596 
   594     /**
   597     /**
   595      * Appends the string representation of the <code>int</code>
   598      * Appends the string representation of the {@code int}
   596      * argument to this sequence.
   599      * argument to this sequence.
   597      * <p>
   600      * <p>
   598      * The argument is converted to a string as if by the method
   601      * The overall effect is exactly as if the argument were converted
   599      * <code>String.valueOf</code>, and the characters of that
   602      * to a string by the method {@link String#valueOf(int)},
   600      * string are then appended to this sequence.
   603      * and the characters of that string were then
   601      *
   604      * {@link #append(String) appended} to this character sequence.
   602      * @param   i   an <code>int</code>.
   605      *
       
   606      * @param   i   an {@code int}.
   603      * @return  a reference to this object.
   607      * @return  a reference to this object.
   604      */
   608      */
   605     public AbstractStringBuilder append(int i) {
   609     public AbstractStringBuilder append(int i) {
   606         if (i == Integer.MIN_VALUE) {
   610         if (i == Integer.MIN_VALUE) {
   607             append("-2147483648");
   611             append("-2147483648");
   616         count = spaceNeeded;
   620         count = spaceNeeded;
   617         return this;
   621         return this;
   618     }
   622     }
   619 
   623 
   620     /**
   624     /**
   621      * Appends the string representation of the <code>long</code>
   625      * Appends the string representation of the {@code long}
   622      * argument to this sequence.
   626      * argument to this sequence.
   623      * <p>
   627      * <p>
   624      * The argument is converted to a string as if by the method
   628      * The overall effect is exactly as if the argument were converted
   625      * <code>String.valueOf</code>, and the characters of that
   629      * to a string by the method {@link String#valueOf(long)},
   626      * string are then appended to this sequence.
   630      * and the characters of that string were then
   627      *
   631      * {@link #append(String) appended} to this character sequence.
   628      * @param   l   a <code>long</code>.
   632      *
       
   633      * @param   l   a {@code long}.
   629      * @return  a reference to this object.
   634      * @return  a reference to this object.
   630      */
   635      */
   631     public AbstractStringBuilder append(long l) {
   636     public AbstractStringBuilder append(long l) {
   632         if (l == Long.MIN_VALUE) {
   637         if (l == Long.MIN_VALUE) {
   633             append("-9223372036854775808");
   638             append("-9223372036854775808");
   642         count = spaceNeeded;
   647         count = spaceNeeded;
   643         return this;
   648         return this;
   644     }
   649     }
   645 
   650 
   646     /**
   651     /**
   647      * Appends the string representation of the <code>float</code>
   652      * Appends the string representation of the {@code float}
   648      * argument to this sequence.
   653      * argument to this sequence.
   649      * <p>
   654      * <p>
   650      * The argument is converted to a string as if by the method
   655      * The overall effect is exactly as if the argument were converted
   651      * <code>String.valueOf</code>, and the characters of that
   656      * to a string by the method {@link String#valueOf(float)},
   652      * string are then appended to this string sequence.
   657      * and the characters of that string were then
   653      *
   658      * {@link #append(String) appended} to this character sequence.
   654      * @param   f   a <code>float</code>.
   659      *
       
   660      * @param   f   a {@code float}.
   655      * @return  a reference to this object.
   661      * @return  a reference to this object.
   656      */
   662      */
   657     public AbstractStringBuilder append(float f) {
   663     public AbstractStringBuilder append(float f) {
   658         new FloatingDecimal(f).appendTo(this);
   664         new FloatingDecimal(f).appendTo(this);
   659         return this;
   665         return this;
   660     }
   666     }
   661 
   667 
   662     /**
   668     /**
   663      * Appends the string representation of the <code>double</code>
   669      * Appends the string representation of the {@code double}
   664      * argument to this sequence.
   670      * argument to this sequence.
   665      * <p>
   671      * <p>
   666      * The argument is converted to a string as if by the method
   672      * The overall effect is exactly as if the argument were converted
   667      * <code>String.valueOf</code>, and the characters of that
   673      * to a string by the method {@link String#valueOf(double)},
   668      * string are then appended to this sequence.
   674      * and the characters of that string were then
   669      *
   675      * {@link #append(String) appended} to this character sequence.
   670      * @param   d   a <code>double</code>.
   676      *
       
   677      * @param   d   a {@code double}.
   671      * @return  a reference to this object.
   678      * @return  a reference to this object.
   672      */
   679      */
   673     public AbstractStringBuilder append(double d) {
   680     public AbstractStringBuilder append(double d) {
   674         new FloatingDecimal(d).appendTo(this);
   681         new FloatingDecimal(d).appendTo(this);
   675         return this;
   682         return this;
   676     }
   683     }
   677 
   684 
   678     /**
   685     /**
   679      * Removes the characters in a substring of this sequence.
   686      * Removes the characters in a substring of this sequence.
   680      * The substring begins at the specified <code>start</code> and extends to
   687      * The substring begins at the specified {@code start} and extends to
   681      * the character at index <code>end - 1</code> or to the end of the
   688      * the character at index {@code end - 1} or to the end of the
   682      * sequence if no such character exists. If
   689      * sequence if no such character exists. If
   683      * <code>start</code> is equal to <code>end</code>, no changes are made.
   690      * {@code start} is equal to {@code end}, no changes are made.
   684      *
   691      *
   685      * @param      start  The beginning index, inclusive.
   692      * @param      start  The beginning index, inclusive.
   686      * @param      end    The ending index, exclusive.
   693      * @param      end    The ending index, exclusive.
   687      * @return     This object.
   694      * @return     This object.
   688      * @throws     StringIndexOutOfBoundsException  if <code>start</code>
   695      * @throws     StringIndexOutOfBoundsException  if {@code start}
   689      *             is negative, greater than <code>length()</code>, or
   696      *             is negative, greater than {@code length()}, or
   690      *             greater than <code>end</code>.
   697      *             greater than {@code end}.
   691      */
   698      */
   692     public AbstractStringBuilder delete(int start, int end) {
   699     public AbstractStringBuilder delete(int start, int end) {
   693         if (start < 0)
   700         if (start < 0)
   694             throw new StringIndexOutOfBoundsException(start);
   701             throw new StringIndexOutOfBoundsException(start);
   695         if (end > count)
   702         if (end > count)
   703         }
   710         }
   704         return this;
   711         return this;
   705     }
   712     }
   706 
   713 
   707     /**
   714     /**
   708      * Appends the string representation of the <code>codePoint</code>
   715      * Appends the string representation of the {@code codePoint}
   709      * argument to this sequence.
   716      * argument to this sequence.
   710      *
   717      *
   711      * <p> The argument is appended to the contents of this sequence.
   718      * <p> The argument is appended to the contents of this sequence.
   712      * The length of this sequence increases by
   719      * The length of this sequence increases by
   713      * {@link Character#charCount(int) Character.charCount(codePoint)}.
   720      * {@link Character#charCount(int) Character.charCount(codePoint)}.
   714      *
   721      *
   715      * <p> The overall effect is exactly as if the argument were
   722      * <p> The overall effect is exactly as if the argument were
   716      * converted to a <code>char</code> array by the method {@link
   723      * converted to a {@code char} array by the method
   717      * Character#toChars(int)} and the character in that array were
   724      * {@link Character#toChars(int)} and the character in that array
   718      * then {@link #append(char[]) appended} to this character
   725      * were then {@link #append(char[]) appended} to this character
   719      * sequence.
   726      * sequence.
   720      *
   727      *
   721      * @param   codePoint   a Unicode code point
   728      * @param   codePoint   a Unicode code point
   722      * @return  a reference to this object.
   729      * @return  a reference to this object.
   723      * @exception IllegalArgumentException if the specified
   730      * @exception IllegalArgumentException if the specified
   724      * <code>codePoint</code> isn't a valid Unicode code point
   731      * {@code codePoint} isn't a valid Unicode code point
   725      */
   732      */
   726     public AbstractStringBuilder appendCodePoint(int codePoint) {
   733     public AbstractStringBuilder appendCodePoint(int codePoint) {
   727         if (!Character.isValidCodePoint(codePoint)) {
   734         if (!Character.isValidCodePoint(codePoint)) {
   728             throw new IllegalArgumentException();
   735             throw new IllegalArgumentException();
   729         }
   736         }
   877             throw new StringIndexOutOfBoundsException(end - start);
   884             throw new StringIndexOutOfBoundsException(end - start);
   878         return new String(value, start, end - start);
   885         return new String(value, start, end - start);
   879     }
   886     }
   880 
   887 
   881     /**
   888     /**
   882      * Inserts the string representation of a subarray of the <code>str</code>
   889      * Inserts the string representation of a subarray of the {@code str}
   883      * array argument into this sequence. The subarray begins at the
   890      * array argument into this sequence. The subarray begins at the
   884      * specified <code>offset</code> and extends <code>len</code> <code>char</code>s.
   891      * specified {@code offset} and extends {@code len} {@code char}s.
   885      * The characters of the subarray are inserted into this sequence at
   892      * The characters of the subarray are inserted into this sequence at
   886      * the position indicated by <code>index</code>. The length of this
   893      * the position indicated by {@code index}. The length of this
   887      * sequence increases by <code>len</code> <code>char</code>s.
   894      * sequence increases by {@code len} {@code char}s.
   888      *
   895      *
   889      * @param      index    position at which to insert subarray.
   896      * @param      index    position at which to insert subarray.
   890      * @param      str       A <code>char</code> array.
   897      * @param      str       A {@code char} array.
   891      * @param      offset   the index of the first <code>char</code> in subarray to
   898      * @param      offset   the index of the first {@code char} in subarray to
   892      *             be inserted.
   899      *             be inserted.
   893      * @param      len      the number of <code>char</code>s in the subarray to
   900      * @param      len      the number of {@code char}s in the subarray to
   894      *             be inserted.
   901      *             be inserted.
   895      * @return     This object
   902      * @return     This object
   896      * @throws     StringIndexOutOfBoundsException  if <code>index</code>
   903      * @throws     StringIndexOutOfBoundsException  if {@code index}
   897      *             is negative or greater than <code>length()</code>, or
   904      *             is negative or greater than {@code length()}, or
   898      *             <code>offset</code> or <code>len</code> are negative, or
   905      *             {@code offset} or {@code len} are negative, or
   899      *             <code>(offset+len)</code> is greater than
   906      *             {@code (offset+len)} is greater than
   900      *             <code>str.length</code>.
   907      *             {@code str.length}.
   901      */
   908      */
   902     public AbstractStringBuilder insert(int index, char str[], int offset,
   909     public AbstractStringBuilder insert(int index, char[] str, int offset,
   903                                         int len)
   910                                         int len)
   904     {
   911     {
   905         if ((index < 0) || (index > length()))
   912         if ((index < 0) || (index > length()))
   906             throw new StringIndexOutOfBoundsException(index);
   913             throw new StringIndexOutOfBoundsException(index);
   907         if ((offset < 0) || (len < 0) || (offset > str.length - len))
   914         if ((offset < 0) || (len < 0) || (offset > str.length - len))
   916         count = newCount;
   923         count = newCount;
   917         return this;
   924         return this;
   918     }
   925     }
   919 
   926 
   920     /**
   927     /**
   921      * Inserts the string representation of the <code>Object</code>
   928      * Inserts the string representation of the {@code Object}
   922      * argument into this character sequence.
   929      * argument into this character sequence.
   923      * <p>
   930      * <p>
   924      * The second argument is converted to a string as if by the method
   931      * The overall effect is exactly as if the second argument were
   925      * <code>String.valueOf</code>, and the characters of that
   932      * converted to a string by the method {@link String#valueOf(Object)},
   926      * string are then inserted into this sequence at the indicated
   933      * and the characters of that string were then
   927      * offset.
   934      * {@link #insert(int,String) inserted} into this character
   928      * <p>
   935      * sequence at the indicated offset.
   929      * The offset argument must be greater than or equal to
   936      * <p>
   930      * <code>0</code>, and less than or equal to the length of this
   937      * The {@code offset} argument must be greater than or equal to
   931      * sequence.
   938      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
   939      * of this sequence.
   932      *
   940      *
   933      * @param      offset   the offset.
   941      * @param      offset   the offset.
   934      * @param      obj      an <code>Object</code>.
   942      * @param      obj      an {@code Object}.
   935      * @return     a reference to this object.
   943      * @return     a reference to this object.
   936      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
   944      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
   937      */
   945      */
   938     public AbstractStringBuilder insert(int offset, Object obj) {
   946     public AbstractStringBuilder insert(int offset, Object obj) {
   939         return insert(offset, String.valueOf(obj));
   947         return insert(offset, String.valueOf(obj));
   940     }
   948     }
   941 
   949 
   942     /**
   950     /**
   943      * Inserts the string into this character sequence.
   951      * Inserts the string into this character sequence.
   944      * <p>
   952      * <p>
   945      * The characters of the <code>String</code> argument are inserted, in
   953      * The characters of the {@code String} argument are inserted, in
   946      * order, into this sequence at the indicated offset, moving up any
   954      * order, into this sequence at the indicated offset, moving up any
   947      * characters originally above that position and increasing the length
   955      * characters originally above that position and increasing the length
   948      * of this sequence by the length of the argument. If
   956      * of this sequence by the length of the argument. If
   949      * <code>str</code> is <code>null</code>, then the four characters
   957      * {@code str} is {@code null}, then the four characters
   950      * <code>"null"</code> are inserted into this sequence.
   958      * {@code "null"} are inserted into this sequence.
   951      * <p>
   959      * <p>
   952      * The character at index <i>k</i> in the new character sequence is
   960      * The character at index <i>k</i> in the new character sequence is
   953      * equal to:
   961      * equal to:
   954      * <ul>
   962      * <ul>
   955      * <li>the character at index <i>k</i> in the old character sequence, if
   963      * <li>the character at index <i>k</i> in the old character sequence, if
   956      * <i>k</i> is less than <code>offset</code>
   964      * <i>k</i> is less than {@code offset}
   957      * <li>the character at index <i>k</i><code>-offset</code> in the
   965      * <li>the character at index <i>k</i>{@code -offset} in the
   958      * argument <code>str</code>, if <i>k</i> is not less than
   966      * argument {@code str}, if <i>k</i> is not less than
   959      * <code>offset</code> but is less than <code>offset+str.length()</code>
   967      * {@code offset} but is less than {@code offset+str.length()}
   960      * <li>the character at index <i>k</i><code>-str.length()</code> in the
   968      * <li>the character at index <i>k</i>{@code -str.length()} in the
   961      * old character sequence, if <i>k</i> is not less than
   969      * old character sequence, if <i>k</i> is not less than
   962      * <code>offset+str.length()</code>
   970      * {@code offset+str.length()}
   963      * </ul><p>
   971      * </ul><p>
   964      * The offset argument must be greater than or equal to
   972      * The {@code offset} argument must be greater than or equal to
   965      * <code>0</code>, and less than or equal to the length of this
   973      * {@code 0}, and less than or equal to the {@linkplain #length() length}
   966      * sequence.
   974      * of this sequence.
   967      *
   975      *
   968      * @param      offset   the offset.
   976      * @param      offset   the offset.
   969      * @param      str      a string.
   977      * @param      str      a string.
   970      * @return     a reference to this object.
   978      * @return     a reference to this object.
   971      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
   979      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
   984         count = newCount;
   992         count = newCount;
   985         return this;
   993         return this;
   986     }
   994     }
   987 
   995 
   988     /**
   996     /**
   989      * Inserts the string representation of the <code>char</code> array
   997      * Inserts the string representation of the {@code char} array
   990      * argument into this sequence.
   998      * argument into this sequence.
   991      * <p>
   999      * <p>
   992      * The characters of the array argument are inserted into the
  1000      * The characters of the array argument are inserted into the
   993      * contents of this sequence at the position indicated by
  1001      * contents of this sequence at the position indicated by
   994      * <code>offset</code>. The length of this sequence increases by
  1002      * {@code offset}. The length of this sequence increases by
   995      * the length of the argument.
  1003      * the length of the argument.
   996      * <p>
  1004      * <p>
   997      * The overall effect is exactly as if the argument were converted to
  1005      * The overall effect is exactly as if the second argument were
   998      * a string by the method {@link String#valueOf(char[])} and the
  1006      * converted to a string by the method {@link String#valueOf(char[])},
   999      * characters of that string were then
  1007      * and the characters of that string were then
  1000      * {@link #insert(int,String) inserted} into this
  1008      * {@link #insert(int,String) inserted} into this character
  1001      * character sequence at the position indicated by
  1009      * sequence at the indicated offset.
  1002      * <code>offset</code>.
  1010      * <p>
       
  1011      * The {@code offset} argument must be greater than or equal to
       
  1012      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1013      * of this sequence.
  1003      *
  1014      *
  1004      * @param      offset   the offset.
  1015      * @param      offset   the offset.
  1005      * @param      str      a character array.
  1016      * @param      str      a character array.
  1006      * @return     a reference to this object.
  1017      * @return     a reference to this object.
  1007      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1018      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1008      */
  1019      */
  1009     public AbstractStringBuilder insert(int offset, char str[]) {
  1020     public AbstractStringBuilder insert(int offset, char[] str) {
  1010         if ((offset < 0) || (offset > length()))
  1021         if ((offset < 0) || (offset > length()))
  1011             throw new StringIndexOutOfBoundsException(offset);
  1022             throw new StringIndexOutOfBoundsException(offset);
  1012         int len = str.length;
  1023         int len = str.length;
  1013         int newCount = count + len;
  1024         int newCount = count + len;
  1014         if (newCount > value.length)
  1025         if (newCount > value.length)
  1018         count = newCount;
  1029         count = newCount;
  1019         return this;
  1030         return this;
  1020     }
  1031     }
  1021 
  1032 
  1022     /**
  1033     /**
  1023      * Inserts the specified <code>CharSequence</code> into this sequence.
  1034      * Inserts the specified {@code CharSequence} into this sequence.
  1024      * <p>
  1035      * <p>
  1025      * The characters of the <code>CharSequence</code> argument are inserted,
  1036      * The characters of the {@code CharSequence} argument are inserted,
  1026      * in order, into this sequence at the indicated offset, moving up
  1037      * in order, into this sequence at the indicated offset, moving up
  1027      * any characters originally above that position and increasing the length
  1038      * any characters originally above that position and increasing the length
  1028      * of this sequence by the length of the argument s.
  1039      * of this sequence by the length of the argument s.
  1029      * <p>
  1040      * <p>
  1030      * The result of this method is exactly the same as if it were an
  1041      * The result of this method is exactly the same as if it were an
  1031      * invocation of this object's insert(dstOffset, s, 0, s.length()) method.
  1042      * invocation of this object's
  1032      *
  1043      * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
  1033      * <p>If <code>s</code> is <code>null</code>, then the four characters
  1044      * method.
  1034      * <code>"null"</code> are inserted into this sequence.
  1045      *
       
  1046      * <p>If {@code s} is {@code null}, then the four characters
       
  1047      * {@code "null"} are inserted into this sequence.
  1035      *
  1048      *
  1036      * @param      dstOffset   the offset.
  1049      * @param      dstOffset   the offset.
  1037      * @param      s the sequence to be inserted
  1050      * @param      s the sequence to be inserted
  1038      * @return     a reference to this object.
  1051      * @return     a reference to this object.
  1039      * @throws     IndexOutOfBoundsException  if the offset is invalid.
  1052      * @throws     IndexOutOfBoundsException  if the offset is invalid.
  1045             return this.insert(dstOffset, (String)s);
  1058             return this.insert(dstOffset, (String)s);
  1046         return this.insert(dstOffset, s, 0, s.length());
  1059         return this.insert(dstOffset, s, 0, s.length());
  1047     }
  1060     }
  1048 
  1061 
  1049     /**
  1062     /**
  1050      * Inserts a subsequence of the specified <code>CharSequence</code> into
  1063      * Inserts a subsequence of the specified {@code CharSequence} into
  1051      * this sequence.
  1064      * this sequence.
  1052      * <p>
  1065      * <p>
  1053      * The subsequence of the argument <code>s</code> specified by
  1066      * The subsequence of the argument {@code s} specified by
  1054      * <code>start</code> and <code>end</code> are inserted,
  1067      * {@code start} and {@code end} are inserted,
  1055      * in order, into this sequence at the specified destination offset, moving
  1068      * in order, into this sequence at the specified destination offset, moving
  1056      * up any characters originally above that position. The length of this
  1069      * up any characters originally above that position. The length of this
  1057      * sequence is increased by <code>end - start</code>.
  1070      * sequence is increased by {@code end - start}.
  1058      * <p>
  1071      * <p>
  1059      * The character at index <i>k</i> in this sequence becomes equal to:
  1072      * The character at index <i>k</i> in this sequence becomes equal to:
  1060      * <ul>
  1073      * <ul>
  1061      * <li>the character at index <i>k</i> in this sequence, if
  1074      * <li>the character at index <i>k</i> in this sequence, if
  1062      * <i>k</i> is less than <code>dstOffset</code>
  1075      * <i>k</i> is less than {@code dstOffset}
  1063      * <li>the character at index <i>k</i><code>+start-dstOffset</code> in
  1076      * <li>the character at index <i>k</i>{@code +start-dstOffset} in
  1064      * the argument <code>s</code>, if <i>k</i> is greater than or equal to
  1077      * the argument {@code s}, if <i>k</i> is greater than or equal to
  1065      * <code>dstOffset</code> but is less than <code>dstOffset+end-start</code>
  1078      * {@code dstOffset} but is less than {@code dstOffset+end-start}
  1066      * <li>the character at index <i>k</i><code>-(end-start)</code> in this
  1079      * <li>the character at index <i>k</i>{@code -(end-start)} in this
  1067      * sequence, if <i>k</i> is greater than or equal to
  1080      * sequence, if <i>k</i> is greater than or equal to
  1068      * <code>dstOffset+end-start</code>
  1081      * {@code dstOffset+end-start}
  1069      * </ul><p>
  1082      * </ul><p>
  1070      * The dstOffset argument must be greater than or equal to
  1083      * The {@code dstOffset} argument must be greater than or equal to
  1071      * <code>0</code>, and less than or equal to the length of this
  1084      * {@code 0}, and less than or equal to the {@linkplain #length() length}
  1072      * sequence.
  1085      * of this sequence.
  1073      * <p>The start argument must be nonnegative, and not greater than
  1086      * <p>The start argument must be nonnegative, and not greater than
  1074      * <code>end</code>.
  1087      * {@code end}.
  1075      * <p>The end argument must be greater than or equal to
  1088      * <p>The end argument must be greater than or equal to
  1076      * <code>start</code>, and less than or equal to the length of s.
  1089      * {@code start}, and less than or equal to the length of s.
  1077      *
  1090      *
  1078      * <p>If <code>s</code> is <code>null</code>, then this method inserts
  1091      * <p>If {@code s} is {@code null}, then this method inserts
  1079      * characters as if the s parameter was a sequence containing the four
  1092      * characters as if the s parameter was a sequence containing the four
  1080      * characters <code>"null"</code>.
  1093      * characters {@code "null"}.
  1081      *
  1094      *
  1082      * @param      dstOffset   the offset in this sequence.
  1095      * @param      dstOffset   the offset in this sequence.
  1083      * @param      s       the sequence to be inserted.
  1096      * @param      s       the sequence to be inserted.
  1084      * @param      start   the starting index of the subsequence to be inserted.
  1097      * @param      start   the starting index of the subsequence to be inserted.
  1085      * @param      end     the end index of the subsequence to be inserted.
  1098      * @param      end     the end index of the subsequence to be inserted.
  1086      * @return     a reference to this object.
  1099      * @return     a reference to this object.
  1087      * @throws     IndexOutOfBoundsException  if <code>dstOffset</code>
  1100      * @throws     IndexOutOfBoundsException  if {@code dstOffset}
  1088      *             is negative or greater than <code>this.length()</code>, or
  1101      *             is negative or greater than {@code this.length()}, or
  1089      *              <code>start</code> or <code>end</code> are negative, or
  1102      *              {@code start} or {@code end} are negative, or
  1090      *              <code>start</code> is greater than <code>end</code> or
  1103      *              {@code start} is greater than {@code end} or
  1091      *              <code>end</code> is greater than <code>s.length()</code>
  1104      *              {@code end} is greater than {@code s.length()}
  1092      */
  1105      */
  1093      public AbstractStringBuilder insert(int dstOffset, CharSequence s,
  1106      public AbstractStringBuilder insert(int dstOffset, CharSequence s,
  1094                                            int start, int end) {
  1107                                          int start, int end) {
  1095         if (s == null)
  1108         if (s == null)
  1096             s = "null";
  1109             s = "null";
  1097         if ((dstOffset < 0) || (dstOffset > this.length()))
  1110         if ((dstOffset < 0) || (dstOffset > this.length()))
  1098             throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
  1111             throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
  1099         if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
  1112         if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
  1113         count = newCount;
  1126         count = newCount;
  1114         return this;
  1127         return this;
  1115     }
  1128     }
  1116 
  1129 
  1117     /**
  1130     /**
  1118      * Inserts the string representation of the <code>boolean</code>
  1131      * Inserts the string representation of the {@code boolean}
  1119      * argument into this sequence.
  1132      * argument into this sequence.
  1120      * <p>
  1133      * <p>
  1121      * The second argument is converted to a string as if by the method
  1134      * The overall effect is exactly as if the second argument were
  1122      * <code>String.valueOf</code>, and the characters of that
  1135      * converted to a string by the method {@link String#valueOf(boolean)},
  1123      * string are then inserted into this sequence at the indicated
  1136      * and the characters of that string were then
  1124      * offset.
  1137      * {@link #insert(int,String) inserted} into this character
  1125      * <p>
  1138      * sequence at the indicated offset.
  1126      * The offset argument must be greater than or equal to
  1139      * <p>
  1127      * <code>0</code>, and less than or equal to the length of this
  1140      * The {@code offset} argument must be greater than or equal to
  1128      * sequence.
  1141      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1142      * of this sequence.
  1129      *
  1143      *
  1130      * @param      offset   the offset.
  1144      * @param      offset   the offset.
  1131      * @param      b        a <code>boolean</code>.
  1145      * @param      b        a {@code boolean}.
  1132      * @return     a reference to this object.
  1146      * @return     a reference to this object.
  1133      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1147      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1134      */
  1148      */
  1135     public AbstractStringBuilder insert(int offset, boolean b) {
  1149     public AbstractStringBuilder insert(int offset, boolean b) {
  1136         return insert(offset, String.valueOf(b));
  1150         return insert(offset, String.valueOf(b));
  1137     }
  1151     }
  1138 
  1152 
  1139     /**
  1153     /**
  1140      * Inserts the string representation of the <code>char</code>
  1154      * Inserts the string representation of the {@code char}
  1141      * argument into this sequence.
  1155      * argument into this sequence.
  1142      * <p>
  1156      * <p>
  1143      * The second argument is inserted into the contents of this sequence
  1157      * The overall effect is exactly as if the second argument were
  1144      * at the position indicated by <code>offset</code>. The length
  1158      * converted to a string by the method {@link String#valueOf(char)},
  1145      * of this sequence increases by one.
  1159      * and the character in that string were then
  1146      * <p>
  1160      * {@link #insert(int,String) inserted} into this character
  1147      * The overall effect is exactly as if the argument were converted to
  1161      * sequence at the indicated offset.
  1148      * a string by the method {@link String#valueOf(char)} and the character
  1162      * <p>
  1149      * in that string were then {@link #insert(int, String) inserted} into
  1163      * The {@code offset} argument must be greater than or equal to
  1150      * this character sequence at the position indicated by
  1164      * {@code 0}, and less than or equal to the {@linkplain #length() length}
  1151      * <code>offset</code>.
  1165      * of this sequence.
  1152      * <p>
       
  1153      * The offset argument must be greater than or equal to
       
  1154      * <code>0</code>, and less than or equal to the length of this
       
  1155      * sequence.
       
  1156      *
  1166      *
  1157      * @param      offset   the offset.
  1167      * @param      offset   the offset.
  1158      * @param      c        a <code>char</code>.
  1168      * @param      c        a {@code char}.
  1159      * @return     a reference to this object.
  1169      * @return     a reference to this object.
  1160      * @throws     IndexOutOfBoundsException  if the offset is invalid.
  1170      * @throws     IndexOutOfBoundsException  if the offset is invalid.
  1161      */
  1171      */
  1162     public AbstractStringBuilder insert(int offset, char c) {
  1172     public AbstractStringBuilder insert(int offset, char c) {
  1163         int newCount = count + 1;
  1173         int newCount = count + 1;
  1168         count = newCount;
  1178         count = newCount;
  1169         return this;
  1179         return this;
  1170     }
  1180     }
  1171 
  1181 
  1172     /**
  1182     /**
  1173      * Inserts the string representation of the second <code>int</code>
  1183      * Inserts the string representation of the second {@code int}
  1174      * argument into this sequence.
  1184      * argument into this sequence.
  1175      * <p>
  1185      * <p>
  1176      * The second argument is converted to a string as if by the method
  1186      * The overall effect is exactly as if the second argument were
  1177      * <code>String.valueOf</code>, and the characters of that
  1187      * converted to a string by the method {@link String#valueOf(int)},
  1178      * string are then inserted into this sequence at the indicated
  1188      * and the characters of that string were then
  1179      * offset.
  1189      * {@link #insert(int,String) inserted} into this character
  1180      * <p>
  1190      * sequence at the indicated offset.
  1181      * The offset argument must be greater than or equal to
  1191      * <p>
  1182      * <code>0</code>, and less than or equal to the length of this
  1192      * The {@code offset} argument must be greater than or equal to
  1183      * sequence.
  1193      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1194      * of this sequence.
  1184      *
  1195      *
  1185      * @param      offset   the offset.
  1196      * @param      offset   the offset.
  1186      * @param      i        an <code>int</code>.
  1197      * @param      i        an {@code int}.
  1187      * @return     a reference to this object.
  1198      * @return     a reference to this object.
  1188      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1199      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1189      */
  1200      */
  1190     public AbstractStringBuilder insert(int offset, int i) {
  1201     public AbstractStringBuilder insert(int offset, int i) {
  1191         return insert(offset, String.valueOf(i));
  1202         return insert(offset, String.valueOf(i));
  1192     }
  1203     }
  1193 
  1204 
  1194     /**
  1205     /**
  1195      * Inserts the string representation of the <code>long</code>
  1206      * Inserts the string representation of the {@code long}
  1196      * argument into this sequence.
  1207      * argument into this sequence.
  1197      * <p>
  1208      * <p>
  1198      * The second argument is converted to a string as if by the method
  1209      * The overall effect is exactly as if the second argument were
  1199      * <code>String.valueOf</code>, and the characters of that
  1210      * converted to a string by the method {@link String#valueOf(long)},
  1200      * string are then inserted into this sequence at the position
  1211      * and the characters of that string were then
  1201      * indicated by <code>offset</code>.
  1212      * {@link #insert(int,String) inserted} into this character
  1202      * <p>
  1213      * sequence at the indicated offset.
  1203      * The offset argument must be greater than or equal to
  1214      * <p>
  1204      * <code>0</code>, and less than or equal to the length of this
  1215      * The {@code offset} argument must be greater than or equal to
  1205      * sequence.
  1216      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1217      * of this sequence.
  1206      *
  1218      *
  1207      * @param      offset   the offset.
  1219      * @param      offset   the offset.
  1208      * @param      l        a <code>long</code>.
  1220      * @param      l        a {@code long}.
  1209      * @return     a reference to this object.
  1221      * @return     a reference to this object.
  1210      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1222      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1211      */
  1223      */
  1212     public AbstractStringBuilder insert(int offset, long l) {
  1224     public AbstractStringBuilder insert(int offset, long l) {
  1213         return insert(offset, String.valueOf(l));
  1225         return insert(offset, String.valueOf(l));
  1214     }
  1226     }
  1215 
  1227 
  1216     /**
  1228     /**
  1217      * Inserts the string representation of the <code>float</code>
  1229      * Inserts the string representation of the {@code float}
  1218      * argument into this sequence.
  1230      * argument into this sequence.
  1219      * <p>
  1231      * <p>
  1220      * The second argument is converted to a string as if by the method
  1232      * The overall effect is exactly as if the second argument were
  1221      * <code>String.valueOf</code>, and the characters of that
  1233      * converted to a string by the method {@link String#valueOf(float)},
  1222      * string are then inserted into this sequence at the indicated
  1234      * and the characters of that string were then
  1223      * offset.
  1235      * {@link #insert(int,String) inserted} into this character
  1224      * <p>
  1236      * sequence at the indicated offset.
  1225      * The offset argument must be greater than or equal to
  1237      * <p>
  1226      * <code>0</code>, and less than or equal to the length of this
  1238      * The {@code offset} argument must be greater than or equal to
  1227      * sequence.
  1239      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1240      * of this sequence.
  1228      *
  1241      *
  1229      * @param      offset   the offset.
  1242      * @param      offset   the offset.
  1230      * @param      f        a <code>float</code>.
  1243      * @param      f        a {@code float}.
  1231      * @return     a reference to this object.
  1244      * @return     a reference to this object.
  1232      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1245      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1233      */
  1246      */
  1234     public AbstractStringBuilder insert(int offset, float f) {
  1247     public AbstractStringBuilder insert(int offset, float f) {
  1235         return insert(offset, String.valueOf(f));
  1248         return insert(offset, String.valueOf(f));
  1236     }
  1249     }
  1237 
  1250 
  1238     /**
  1251     /**
  1239      * Inserts the string representation of the <code>double</code>
  1252      * Inserts the string representation of the {@code double}
  1240      * argument into this sequence.
  1253      * argument into this sequence.
  1241      * <p>
  1254      * <p>
  1242      * The second argument is converted to a string as if by the method
  1255      * The overall effect is exactly as if the second argument were
  1243      * <code>String.valueOf</code>, and the characters of that
  1256      * converted to a string by the method {@link String#valueOf(double)},
  1244      * string are then inserted into this sequence at the indicated
  1257      * and the characters of that string were then
  1245      * offset.
  1258      * {@link #insert(int,String) inserted} into this character
  1246      * <p>
  1259      * sequence at the indicated offset.
  1247      * The offset argument must be greater than or equal to
  1260      * <p>
  1248      * <code>0</code>, and less than or equal to the length of this
  1261      * The {@code offset} argument must be greater than or equal to
  1249      * sequence.
  1262      * {@code 0}, and less than or equal to the {@linkplain #length() length}
       
  1263      * of this sequence.
  1250      *
  1264      *
  1251      * @param      offset   the offset.
  1265      * @param      offset   the offset.
  1252      * @param      d        a <code>double</code>.
  1266      * @param      d        a {@code double}.
  1253      * @return     a reference to this object.
  1267      * @return     a reference to this object.
  1254      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1268      * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
  1255      */
  1269      */
  1256     public AbstractStringBuilder insert(int offset, double d) {
  1270     public AbstractStringBuilder insert(int offset, double d) {
  1257         return insert(offset, String.valueOf(d));
  1271         return insert(offset, String.valueOf(d));