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
30 import java.util.Arrays;
31 import java.util.Spliterator;
32 import java.util.stream.IntStream;
33 import java.util.stream.StreamSupport;
34
35 import static java.lang.String.COMPACT_STRINGS;
36 import static java.lang.String.UTF16;
37 import static java.lang.String.LATIN1;
38 import static java.lang.String.checkIndex;
39 import static java.lang.String.checkOffset;
40
41 /**
42 * A mutable sequence of characters.
43 * <p>
44 * Implements a modifiable string. At any point in time it contains some
45 * particular sequence of characters, but the length and content of the
46 * sequence can be changed through certain method calls.
47 *
48 * <p>Unless otherwise noted, passing a {@code null} argument to a constructor
49 * or method in this class will cause a {@link NullPointerException} to be
863 } else {
864 StringUTF16.getChars(l, count, spaceNeeded, value);
865 }
866 this.count = spaceNeeded;
867 return this;
868 }
869
870 /**
871 * Appends the string representation of the {@code float}
872 * argument to this sequence.
873 * <p>
874 * The overall effect is exactly as if the argument were converted
875 * to a string by the method {@link String#valueOf(float)},
876 * and the characters of that string were then
877 * {@link #append(String) appended} to this character sequence.
878 *
879 * @param f a {@code float}.
880 * @return a reference to this object.
881 */
882 public AbstractStringBuilder append(float f) {
883 FloatingDecimal.appendTo(f,this);
884 return this;
885 }
886
887 /**
888 * Appends the string representation of the {@code double}
889 * argument to this sequence.
890 * <p>
891 * The overall effect is exactly as if the argument were converted
892 * to a string by the method {@link String#valueOf(double)},
893 * and the characters of that string were then
894 * {@link #append(String) appended} to this character sequence.
895 *
896 * @param d a {@code double}.
897 * @return a reference to this object.
898 */
899 public AbstractStringBuilder append(double d) {
900 FloatingDecimal.appendTo(d,this);
901 return this;
902 }
903
904 /**
905 * Removes the characters in a substring of this sequence.
906 * The substring begins at the specified {@code start} and extends to
907 * the character at index {@code end - 1} or to the end of the
908 * sequence if no such character exists. If
909 * {@code start} is equal to {@code end}, no changes are made.
910 *
911 * @param start The beginning index, inclusive.
912 * @param end The ending index, exclusive.
913 * @return This object.
914 * @throws StringIndexOutOfBoundsException if {@code start}
915 * is negative, greater than {@code length()}, or
916 * greater than {@code end}.
917 */
918 public AbstractStringBuilder delete(int start, int end) {
919 int count = this.count;
920 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
865 } else {
866 StringUTF16.getChars(l, count, spaceNeeded, value);
867 }
868 this.count = spaceNeeded;
869 return this;
870 }
871
872 /**
873 * Appends the string representation of the {@code float}
874 * argument to this sequence.
875 * <p>
876 * The overall effect is exactly as if the argument were converted
877 * to a string by the method {@link String#valueOf(float)},
878 * and the characters of that string were then
879 * {@link #append(String) appended} to this character sequence.
880 *
881 * @param f a {@code float}.
882 * @return a reference to this object.
883 */
884 public AbstractStringBuilder append(float f) {
885 try {
886 FloatToDecimal.appendTo(f, this);
887 } catch (IOException ignored) {
888 assert false;
889 }
890 return this;
891 }
892
893 /**
894 * Appends the string representation of the {@code double}
895 * argument to this sequence.
896 * <p>
897 * The overall effect is exactly as if the argument were converted
898 * to a string by the method {@link String#valueOf(double)},
899 * and the characters of that string were then
900 * {@link #append(String) appended} to this character sequence.
901 *
902 * @param d a {@code double}.
903 * @return a reference to this object.
904 */
905 public AbstractStringBuilder append(double d) {
906 try {
907 DoubleToDecimal.appendTo(d, this);
908 } catch (IOException ignored) {
909 assert false;
910 }
911 return this;
912 }
913
914 /**
915 * Removes the characters in a substring of this sequence.
916 * The substring begins at the specified {@code start} and extends to
917 * the character at index {@code end - 1} or to the end of the
918 * sequence if no such character exists. If
919 * {@code start} is equal to {@code end}, no changes are made.
920 *
921 * @param start The beginning index, inclusive.
922 * @param end The ending index, exclusive.
923 * @return This object.
924 * @throws StringIndexOutOfBoundsException if {@code start}
925 * is negative, greater than {@code length()}, or
926 * greater than {@code end}.
927 */
928 public AbstractStringBuilder delete(int start, int end) {
929 int count = this.count;
930 if (end > count) {
|