8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang;
27
28 import jdk.internal.math.FloatingDecimal;
29 import java.util.Arrays;
30 import java.util.Spliterator;
31 import java.util.stream.IntStream;
32 import java.util.stream.StreamSupport;
33
34 import static java.lang.String.COMPACT_STRINGS;
35 import static java.lang.String.UTF16;
36 import static java.lang.String.LATIN1;
37 import static java.lang.String.checkIndex;
38 import static java.lang.String.checkOffset;
39
40 /**
41 * A mutable sequence of characters.
42 * <p>
43 * Implements a modifiable string. At any point in time it contains some
44 * particular sequence of characters, but the length and content of the
45 * sequence can be changed through certain method calls.
46 *
47 * <p>Unless otherwise noted, passing a {@code null} argument to a constructor
48 * or method in this class will cause a {@link NullPointerException} to be
857 } else {
858 StringUTF16.getChars(l, count, spaceNeeded, value);
859 }
860 this.count = spaceNeeded;
861 return this;
862 }
863
864 /**
865 * Appends the string representation of the {@code float}
866 * argument to this sequence.
867 * <p>
868 * The overall effect is exactly as if the argument were converted
869 * to a string by the method {@link String#valueOf(float)},
870 * and the characters of that string were then
871 * {@link #append(String) appended} to this character sequence.
872 *
873 * @param f a {@code float}.
874 * @return a reference to this object.
875 */
876 public AbstractStringBuilder append(float f) {
877 FloatingDecimal.appendTo(f,this);
878 return this;
879 }
880
881 /**
882 * Appends the string representation of the {@code double}
883 * argument to this sequence.
884 * <p>
885 * The overall effect is exactly as if the argument were converted
886 * to a string by the method {@link String#valueOf(double)},
887 * and the characters of that string were then
888 * {@link #append(String) appended} to this character sequence.
889 *
890 * @param d a {@code double}.
891 * @return a reference to this object.
892 */
893 public AbstractStringBuilder append(double d) {
894 FloatingDecimal.appendTo(d,this);
895 return this;
896 }
897
898 /**
899 * Removes the characters in a substring of this sequence.
900 * The substring begins at the specified {@code start} and extends to
901 * the character at index {@code end - 1} or to the end of the
902 * sequence if no such character exists. If
903 * {@code start} is equal to {@code end}, no changes are made.
904 *
905 * @param start The beginning index, inclusive.
906 * @param end The ending index, exclusive.
907 * @return This object.
908 * @throws StringIndexOutOfBoundsException if {@code start}
909 * is negative, greater than {@code length()}, or
910 * greater than {@code end}.
911 */
912 public AbstractStringBuilder delete(int start, int end) {
913 int count = this.count;
914 if (end > count) {
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.lang;
27
28 import jdk.internal.math.DoubleToDecimal;
29 import jdk.internal.math.FloatToDecimal;
30
31 import java.io.IOException;
32 import java.util.Arrays;
33 import java.util.Spliterator;
34 import java.util.stream.IntStream;
35 import java.util.stream.StreamSupport;
36
37 import static java.lang.String.COMPACT_STRINGS;
38 import static java.lang.String.UTF16;
39 import static java.lang.String.LATIN1;
40 import static java.lang.String.checkIndex;
41 import static java.lang.String.checkOffset;
42
43 /**
44 * A mutable sequence of characters.
45 * <p>
46 * Implements a modifiable string. At any point in time it contains some
47 * particular sequence of characters, but the length and content of the
48 * sequence can be changed through certain method calls.
49 *
50 * <p>Unless otherwise noted, passing a {@code null} argument to a constructor
51 * or method in this class will cause a {@link NullPointerException} to be
860 } else {
861 StringUTF16.getChars(l, count, spaceNeeded, value);
862 }
863 this.count = spaceNeeded;
864 return this;
865 }
866
867 /**
868 * Appends the string representation of the {@code float}
869 * argument to this sequence.
870 * <p>
871 * The overall effect is exactly as if the argument were converted
872 * to a string by the method {@link String#valueOf(float)},
873 * and the characters of that string were then
874 * {@link #append(String) appended} to this character sequence.
875 *
876 * @param f a {@code float}.
877 * @return a reference to this object.
878 */
879 public AbstractStringBuilder append(float f) {
880 try {
881 FloatToDecimal.appendTo(f, this);
882 } catch (IOException ignored) {
883 assert false;
884 }
885 return this;
886 }
887
888 /**
889 * Appends the string representation of the {@code double}
890 * argument to this sequence.
891 * <p>
892 * The overall effect is exactly as if the argument were converted
893 * to a string by the method {@link String#valueOf(double)},
894 * and the characters of that string were then
895 * {@link #append(String) appended} to this character sequence.
896 *
897 * @param d a {@code double}.
898 * @return a reference to this object.
899 */
900 public AbstractStringBuilder append(double d) {
901 try {
902 DoubleToDecimal.appendTo(d, this);
903 } catch (IOException ignored) {
904 assert false;
905 }
906 return this;
907 }
908
909 /**
910 * Removes the characters in a substring of this sequence.
911 * The substring begins at the specified {@code start} and extends to
912 * the character at index {@code end - 1} or to the end of the
913 * sequence if no such character exists. If
914 * {@code start} is equal to {@code end}, no changes are made.
915 *
916 * @param start The beginning index, inclusive.
917 * @param end The ending index, exclusive.
918 * @return This object.
919 * @throws StringIndexOutOfBoundsException if {@code start}
920 * is negative, greater than {@code length()}, or
921 * greater than {@code end}.
922 */
923 public AbstractStringBuilder delete(int start, int end) {
924 int count = this.count;
925 if (end > count) {
|