author | psandoz |
Mon, 26 Jan 2015 17:26:49 +0000 | |
changeset 28667 | 2245cc40bf5d |
parent 25859 | 3317bb8137f4 |
child 31471 | ae27c6f1d8bf |
permissions | -rw-r--r-- |
2 | 1 |
/* |
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import sun.misc.FloatingDecimal; |
|
29 |
import java.util.Arrays; |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
30 |
import java.util.Spliterator; |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
31 |
import java.util.stream.IntStream; |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
32 |
import java.util.stream.StreamSupport; |
2 | 33 |
|
34 |
/** |
|
35 |
* A mutable sequence of characters. |
|
36 |
* <p> |
|
37 |
* Implements a modifiable string. At any point in time it contains some |
|
38 |
* particular sequence of characters, but the length and content of the |
|
39 |
* sequence can be changed through certain method calls. |
|
40 |
* |
|
15312
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
41 |
* <p>Unless otherwise noted, passing a {@code null} argument to a constructor |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
42 |
* or method in this class will cause a {@link NullPointerException} to be |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
43 |
* thrown. |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
44 |
* |
2 | 45 |
* @author Michael McCloskey |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
46 |
* @author Martin Buchholz |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
47 |
* @author Ulf Zibis |
2 | 48 |
* @since 1.5 |
49 |
*/ |
|
50 |
abstract class AbstractStringBuilder implements Appendable, CharSequence { |
|
51 |
/** |
|
52 |
* The value is used for character storage. |
|
53 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
54 |
char[] value; |
2 | 55 |
|
56 |
/** |
|
57 |
* The count is the number of characters used. |
|
58 |
*/ |
|
59 |
int count; |
|
60 |
||
61 |
/** |
|
62 |
* This no-arg constructor is necessary for serialization of subclasses. |
|
63 |
*/ |
|
64 |
AbstractStringBuilder() { |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Creates an AbstractStringBuilder of the specified capacity. |
|
69 |
*/ |
|
70 |
AbstractStringBuilder(int capacity) { |
|
71 |
value = new char[capacity]; |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Returns the length (character count). |
|
76 |
* |
|
77 |
* @return the length of the sequence of characters currently |
|
78 |
* represented by this object |
|
79 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
80 |
@Override |
2 | 81 |
public int length() { |
82 |
return count; |
|
83 |
} |
|
84 |
||
85 |
/** |
|
86 |
* Returns the current capacity. The capacity is the amount of storage |
|
87 |
* available for newly inserted characters, beyond which an allocation |
|
88 |
* will occur. |
|
89 |
* |
|
90 |
* @return the current capacity |
|
91 |
*/ |
|
92 |
public int capacity() { |
|
93 |
return value.length; |
|
94 |
} |
|
95 |
||
96 |
/** |
|
97 |
* Ensures that the capacity is at least equal to the specified minimum. |
|
98 |
* If the current capacity is less than the argument, then a new internal |
|
99 |
* array is allocated with greater capacity. The new capacity is the |
|
100 |
* larger of: |
|
101 |
* <ul> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
102 |
* <li>The {@code minimumCapacity} argument. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
103 |
* <li>Twice the old capacity, plus {@code 2}. |
2 | 104 |
* </ul> |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
105 |
* If the {@code minimumCapacity} argument is nonpositive, this |
2 | 106 |
* method takes no action and simply returns. |
13821
02266c2bf3a8
4722265: (spec str) StringBuffer.ensureCapacity() should mention that capacity is mutable
jgish
parents:
11676
diff
changeset
|
107 |
* Note that subsequent operations on this object can reduce the |
02266c2bf3a8
4722265: (spec str) StringBuffer.ensureCapacity() should mention that capacity is mutable
jgish
parents:
11676
diff
changeset
|
108 |
* actual capacity below that requested here. |
2 | 109 |
* |
110 |
* @param minimumCapacity the minimum desired capacity. |
|
111 |
*/ |
|
112 |
public void ensureCapacity(int minimumCapacity) { |
|
7020
25638687fe82
6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError with minCap=Integer.MIN_VALUE
mchung
parents:
6295
diff
changeset
|
113 |
if (minimumCapacity > 0) |
25638687fe82
6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError with minCap=Integer.MIN_VALUE
mchung
parents:
6295
diff
changeset
|
114 |
ensureCapacityInternal(minimumCapacity); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
115 |
} |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
116 |
|
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
117 |
/** |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
118 |
* This method has the same contract as ensureCapacity, but is |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
119 |
* never synchronized. |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
120 |
*/ |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
121 |
private void ensureCapacityInternal(int minimumCapacity) { |
7020
25638687fe82
6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError with minCap=Integer.MIN_VALUE
mchung
parents:
6295
diff
changeset
|
122 |
// overflow-conscious code |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
123 |
if (minimumCapacity - value.length > 0) |
2 | 124 |
expandCapacity(minimumCapacity); |
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* This implements the expansion semantics of ensureCapacity with no |
|
129 |
* size check or synchronization. |
|
130 |
*/ |
|
131 |
void expandCapacity(int minimumCapacity) { |
|
5603
682e3deac7ce
6952330: Fix for 6933217 broke contract of StringBuffer.ensureCapacity
martin
parents:
5466
diff
changeset
|
132 |
int newCapacity = value.length * 2 + 2; |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
133 |
if (newCapacity - minimumCapacity < 0) |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
134 |
newCapacity = minimumCapacity; |
2 | 135 |
if (newCapacity < 0) { |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
136 |
if (minimumCapacity < 0) // overflow |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
137 |
throw new OutOfMemoryError(); |
2 | 138 |
newCapacity = Integer.MAX_VALUE; |
139 |
} |
|
140 |
value = Arrays.copyOf(value, newCapacity); |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Attempts to reduce storage used for the character sequence. |
|
145 |
* If the buffer is larger than necessary to hold its current sequence of |
|
146 |
* characters, then it may be resized to become more space efficient. |
|
147 |
* Calling this method may, but is not required to, affect the value |
|
148 |
* returned by a subsequent call to the {@link #capacity()} method. |
|
149 |
*/ |
|
150 |
public void trimToSize() { |
|
151 |
if (count < value.length) { |
|
152 |
value = Arrays.copyOf(value, count); |
|
153 |
} |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* Sets the length of the character sequence. |
|
158 |
* The sequence is changed to a new character sequence |
|
159 |
* whose length is specified by the argument. For every nonnegative |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
160 |
* index <i>k</i> less than {@code newLength}, the character at |
2 | 161 |
* index <i>k</i> in the new character sequence is the same as the |
162 |
* character at index <i>k</i> in the old sequence if <i>k</i> is less |
|
163 |
* than the length of the old character sequence; otherwise, it is the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
164 |
* null character {@code '\u005Cu0000'}. |
2 | 165 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
166 |
* In other words, if the {@code newLength} argument is less than |
2 | 167 |
* the current length, the length is changed to the specified length. |
168 |
* <p> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
169 |
* If the {@code newLength} argument is greater than or equal |
2 | 170 |
* to the current length, sufficient null characters |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
171 |
* ({@code '\u005Cu0000'}) are appended so that |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
172 |
* length becomes the {@code newLength} argument. |
2 | 173 |
* <p> |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
174 |
* The {@code newLength} argument must be greater than or equal |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
175 |
* to {@code 0}. |
2 | 176 |
* |
177 |
* @param newLength the new length |
|
178 |
* @throws IndexOutOfBoundsException if the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
179 |
* {@code newLength} argument is negative. |
2 | 180 |
*/ |
181 |
public void setLength(int newLength) { |
|
182 |
if (newLength < 0) |
|
183 |
throw new StringIndexOutOfBoundsException(newLength); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
184 |
ensureCapacityInternal(newLength); |
2 | 185 |
|
186 |
if (count < newLength) { |
|
14686
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
187 |
Arrays.fill(value, count, newLength, '\0'); |
2 | 188 |
} |
14686
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
189 |
|
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
190 |
count = newLength; |
2 | 191 |
} |
192 |
||
193 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
194 |
* Returns the {@code char} value in this sequence at the specified index. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
195 |
* The first {@code char} value is at index {@code 0}, the next at index |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
196 |
* {@code 1}, and so on, as in array indexing. |
2 | 197 |
* <p> |
198 |
* The index argument must be greater than or equal to |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
199 |
* {@code 0}, and less than the length of this sequence. |
2 | 200 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
201 |
* <p>If the {@code char} value specified by the index is a |
2 | 202 |
* <a href="Character.html#unicode">surrogate</a>, the surrogate |
203 |
* value is returned. |
|
204 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
205 |
* @param index the index of the desired {@code char} value. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
206 |
* @return the {@code char} value at the specified index. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
207 |
* @throws IndexOutOfBoundsException if {@code index} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
208 |
* negative or greater than or equal to {@code length()}. |
2 | 209 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
210 |
@Override |
2 | 211 |
public char charAt(int index) { |
212 |
if ((index < 0) || (index >= count)) |
|
213 |
throw new StringIndexOutOfBoundsException(index); |
|
214 |
return value[index]; |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
* Returns the character (Unicode code point) at the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
219 |
* index. The index refers to {@code char} values |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
220 |
* (Unicode code units) and ranges from {@code 0} to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
221 |
* {@link #length()}{@code - 1}. |
2 | 222 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
223 |
* <p> If the {@code char} value specified at the given index |
2 | 224 |
* is in the high-surrogate range, the following index is less |
225 |
* than the length of this sequence, and the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
226 |
* {@code char} value at the following index is in the |
2 | 227 |
* low-surrogate range, then the supplementary code point |
228 |
* corresponding to this surrogate pair is returned. Otherwise, |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
229 |
* the {@code char} value at the given index is returned. |
2 | 230 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
231 |
* @param index the index to the {@code char} values |
2 | 232 |
* @return the code point value of the character at the |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
233 |
* {@code index} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
234 |
* @exception IndexOutOfBoundsException if the {@code index} |
2 | 235 |
* argument is negative or not less than the length of this |
236 |
* sequence. |
|
237 |
*/ |
|
238 |
public int codePointAt(int index) { |
|
239 |
if ((index < 0) || (index >= count)) { |
|
240 |
throw new StringIndexOutOfBoundsException(index); |
|
241 |
} |
|
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
242 |
return Character.codePointAtImpl(value, index, count); |
2 | 243 |
} |
244 |
||
245 |
/** |
|
246 |
* Returns the character (Unicode code point) before the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
247 |
* index. The index refers to {@code char} values |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
248 |
* (Unicode code units) and ranges from {@code 1} to {@link |
2 | 249 |
* #length()}. |
250 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
251 |
* <p> If the {@code char} value at {@code (index - 1)} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
252 |
* is in the low-surrogate range, {@code (index - 2)} is not |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
253 |
* negative, and the {@code char} value at {@code (index - |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
254 |
* 2)} is in the high-surrogate range, then the |
2 | 255 |
* supplementary code point value of the surrogate pair is |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
256 |
* returned. If the {@code char} value at {@code index - |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
257 |
* 1} is an unpaired low-surrogate or a high-surrogate, the |
2 | 258 |
* surrogate value is returned. |
259 |
* |
|
260 |
* @param index the index following the code point that should be returned |
|
261 |
* @return the Unicode code point value before the given index. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
262 |
* @exception IndexOutOfBoundsException if the {@code index} |
2 | 263 |
* argument is less than 1 or greater than the length |
264 |
* of this sequence. |
|
265 |
*/ |
|
266 |
public int codePointBefore(int index) { |
|
267 |
int i = index - 1; |
|
268 |
if ((i < 0) || (i >= count)) { |
|
269 |
throw new StringIndexOutOfBoundsException(index); |
|
270 |
} |
|
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
271 |
return Character.codePointBeforeImpl(value, index, 0); |
2 | 272 |
} |
273 |
||
274 |
/** |
|
275 |
* Returns the number of Unicode code points in the specified text |
|
276 |
* range of this sequence. The text range begins at the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
277 |
* {@code beginIndex} and extends to the {@code char} at |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
278 |
* index {@code endIndex - 1}. Thus the length (in |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
279 |
* {@code char}s) of the text range is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
280 |
* {@code endIndex-beginIndex}. Unpaired surrogates within |
2 | 281 |
* this sequence count as one code point each. |
282 |
* |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
283 |
* @param beginIndex the index to the first {@code char} of |
2 | 284 |
* the text range. |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
285 |
* @param endIndex the index after the last {@code char} of |
2 | 286 |
* the text range. |
287 |
* @return the number of Unicode code points in the specified text |
|
288 |
* range |
|
289 |
* @exception IndexOutOfBoundsException if the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
290 |
* {@code beginIndex} is negative, or {@code endIndex} |
2 | 291 |
* is larger than the length of this sequence, or |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
292 |
* {@code beginIndex} is larger than {@code endIndex}. |
2 | 293 |
*/ |
294 |
public int codePointCount(int beginIndex, int endIndex) { |
|
295 |
if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) { |
|
296 |
throw new IndexOutOfBoundsException(); |
|
297 |
} |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
298 |
return Character.codePointCountImpl(value, beginIndex, endIndex - beginIndex); |
2 | 299 |
} |
300 |
||
301 |
/** |
|
302 |
* Returns the index within this sequence that is offset from the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
303 |
* given {@code index} by {@code codePointOffset} code |
2 | 304 |
* points. Unpaired surrogates within the text range given by |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
305 |
* {@code index} and {@code codePointOffset} count as |
2 | 306 |
* one code point each. |
307 |
* |
|
308 |
* @param index the index to be offset |
|
309 |
* @param codePointOffset the offset in code points |
|
310 |
* @return the index within this sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
311 |
* @exception IndexOutOfBoundsException if {@code index} |
2 | 312 |
* is negative or larger then the length of this sequence, |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
313 |
* or if {@code codePointOffset} is positive and the subsequence |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
314 |
* starting with {@code index} has fewer than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
315 |
* {@code codePointOffset} code points, |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
316 |
* or if {@code codePointOffset} is negative and the subsequence |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
317 |
* before {@code index} has fewer than the absolute value of |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
318 |
* {@code codePointOffset} code points. |
2 | 319 |
*/ |
320 |
public int offsetByCodePoints(int index, int codePointOffset) { |
|
321 |
if (index < 0 || index > count) { |
|
322 |
throw new IndexOutOfBoundsException(); |
|
323 |
} |
|
324 |
return Character.offsetByCodePointsImpl(value, 0, count, |
|
325 |
index, codePointOffset); |
|
326 |
} |
|
327 |
||
328 |
/** |
|
329 |
* Characters are copied from this sequence into the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
330 |
* destination character array {@code dst}. The first character to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
331 |
* be copied is at index {@code srcBegin}; the last character to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
332 |
* be copied is at index {@code srcEnd-1}. The total number of |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
333 |
* characters to be copied is {@code srcEnd-srcBegin}. The |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
334 |
* characters are copied into the subarray of {@code dst} starting |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
335 |
* at index {@code dstBegin} and ending at index: |
21334 | 336 |
* <pre>{@code |
2 | 337 |
* dstbegin + (srcEnd-srcBegin) - 1 |
21334 | 338 |
* }</pre> |
2 | 339 |
* |
340 |
* @param srcBegin start copying at this offset. |
|
341 |
* @param srcEnd stop copying at this offset. |
|
342 |
* @param dst the array to copy the data into. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
343 |
* @param dstBegin offset into {@code dst}. |
2 | 344 |
* @throws IndexOutOfBoundsException if any of the following is true: |
345 |
* <ul> |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
346 |
* <li>{@code srcBegin} is negative |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
347 |
* <li>{@code dstBegin} is negative |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
348 |
* <li>the {@code srcBegin} argument is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
349 |
* the {@code srcEnd} argument. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
350 |
* <li>{@code srcEnd} is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
351 |
* {@code this.length()}. |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
352 |
* <li>{@code dstBegin+srcEnd-srcBegin} is greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
353 |
* {@code dst.length} |
2 | 354 |
* </ul> |
355 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
356 |
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) |
2 | 357 |
{ |
358 |
if (srcBegin < 0) |
|
359 |
throw new StringIndexOutOfBoundsException(srcBegin); |
|
360 |
if ((srcEnd < 0) || (srcEnd > count)) |
|
361 |
throw new StringIndexOutOfBoundsException(srcEnd); |
|
362 |
if (srcBegin > srcEnd) |
|
363 |
throw new StringIndexOutOfBoundsException("srcBegin > srcEnd"); |
|
364 |
System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); |
|
365 |
} |
|
366 |
||
367 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
368 |
* The character at the specified index is set to {@code ch}. This |
2 | 369 |
* sequence is altered to represent a new character sequence that is |
370 |
* identical to the old character sequence, except that it contains the |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
371 |
* character {@code ch} at position {@code index}. |
2 | 372 |
* <p> |
373 |
* The index argument must be greater than or equal to |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
374 |
* {@code 0}, and less than the length of this sequence. |
2 | 375 |
* |
376 |
* @param index the index of the character to modify. |
|
377 |
* @param ch the new character. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
378 |
* @throws IndexOutOfBoundsException if {@code index} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
379 |
* negative or greater than or equal to {@code length()}. |
2 | 380 |
*/ |
381 |
public void setCharAt(int index, char ch) { |
|
382 |
if ((index < 0) || (index >= count)) |
|
383 |
throw new StringIndexOutOfBoundsException(index); |
|
384 |
value[index] = ch; |
|
385 |
} |
|
386 |
||
387 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
388 |
* Appends the string representation of the {@code Object} argument. |
2 | 389 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
390 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
391 |
* to a string by the method {@link String#valueOf(Object)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
392 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
393 |
* {@link #append(String) appended} to this character sequence. |
2 | 394 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
395 |
* @param obj an {@code Object}. |
2 | 396 |
* @return a reference to this object. |
397 |
*/ |
|
398 |
public AbstractStringBuilder append(Object obj) { |
|
399 |
return append(String.valueOf(obj)); |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Appends the specified string to this character sequence. |
|
404 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
405 |
* The characters of the {@code String} argument are appended, in |
2 | 406 |
* order, increasing the length of this sequence by the length of the |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
407 |
* argument. If {@code str} is {@code null}, then the four |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
408 |
* characters {@code "null"} are appended. |
2 | 409 |
* <p> |
410 |
* Let <i>n</i> be the length of this character sequence just prior to |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
411 |
* execution of the {@code append} method. Then the character at |
2 | 412 |
* index <i>k</i> in the new character sequence is equal to the character |
413 |
* at index <i>k</i> in the old character sequence, if <i>k</i> is less |
|
414 |
* than <i>n</i>; otherwise, it is equal to the character at index |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
415 |
* <i>k-n</i> in the argument {@code str}. |
2 | 416 |
* |
417 |
* @param str a string. |
|
418 |
* @return a reference to this object. |
|
419 |
*/ |
|
420 |
public AbstractStringBuilder append(String str) { |
|
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
421 |
if (str == null) |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
422 |
return appendNull(); |
2 | 423 |
int len = str.length(); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
424 |
ensureCapacityInternal(count + len); |
2 | 425 |
str.getChars(0, len, value, count); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
426 |
count += len; |
2 | 427 |
return this; |
428 |
} |
|
429 |
||
430 |
// Documentation in subclasses because of synchro difference |
|
431 |
public AbstractStringBuilder append(StringBuffer sb) { |
|
432 |
if (sb == null) |
|
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
433 |
return appendNull(); |
2 | 434 |
int len = sb.length(); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
435 |
ensureCapacityInternal(count + len); |
2 | 436 |
sb.getChars(0, len, value, count); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
437 |
count += len; |
2 | 438 |
return this; |
439 |
} |
|
440 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
441 |
/** |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
442 |
* @since 1.8 |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
443 |
*/ |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
444 |
AbstractStringBuilder append(AbstractStringBuilder asb) { |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
445 |
if (asb == null) |
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
446 |
return appendNull(); |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
447 |
int len = asb.length(); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
448 |
ensureCapacityInternal(count + len); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
449 |
asb.getChars(0, len, value, count); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
450 |
count += len; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
451 |
return this; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
452 |
} |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
453 |
|
2 | 454 |
// Documentation in subclasses because of synchro difference |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
455 |
@Override |
2 | 456 |
public AbstractStringBuilder append(CharSequence s) { |
457 |
if (s == null) |
|
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
458 |
return appendNull(); |
2 | 459 |
if (s instanceof String) |
460 |
return this.append((String)s); |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
461 |
if (s instanceof AbstractStringBuilder) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
462 |
return this.append((AbstractStringBuilder)s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
463 |
|
2 | 464 |
return this.append(s, 0, s.length()); |
465 |
} |
|
466 |
||
16742
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
467 |
private AbstractStringBuilder appendNull() { |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
468 |
int c = count; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
469 |
ensureCapacityInternal(c + 4); |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
470 |
final char[] value = this.value; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
471 |
value[c++] = 'n'; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
472 |
value[c++] = 'u'; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
473 |
value[c++] = 'l'; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
474 |
value[c++] = 'l'; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
475 |
count = c; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
476 |
return this; |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
477 |
} |
e6b0ac6581f1
8010849: (str) Optimize StringBuilder.append(null)
martin
parents:
16714
diff
changeset
|
478 |
|
2 | 479 |
/** |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
480 |
* Appends a subsequence of the specified {@code CharSequence} to this |
2 | 481 |
* sequence. |
482 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
483 |
* Characters of the argument {@code s}, starting at |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
484 |
* index {@code start}, are appended, in order, to the contents of |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
485 |
* this sequence up to the (exclusive) index {@code end}. The length |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
486 |
* of this sequence is increased by the value of {@code end - start}. |
2 | 487 |
* <p> |
488 |
* Let <i>n</i> be the length of this character sequence just prior to |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
489 |
* execution of the {@code append} method. Then the character at |
2 | 490 |
* index <i>k</i> in this character sequence becomes equal to the |
491 |
* character at index <i>k</i> in this sequence, if <i>k</i> is less than |
|
492 |
* <i>n</i>; otherwise, it is equal to the character at index |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
493 |
* <i>k+start-n</i> in the argument {@code s}. |
2 | 494 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
495 |
* If {@code s} is {@code null}, then this method appends |
2 | 496 |
* characters as if the s parameter was a sequence containing the four |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
497 |
* characters {@code "null"}. |
2 | 498 |
* |
499 |
* @param s the sequence to append. |
|
500 |
* @param start the starting index of the subsequence to be appended. |
|
501 |
* @param end the end index of the subsequence to be appended. |
|
502 |
* @return a reference to this object. |
|
503 |
* @throws IndexOutOfBoundsException if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
504 |
* {@code start} is negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
505 |
* {@code start} is greater than {@code end} or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
506 |
* {@code end} is greater than {@code s.length()} |
2 | 507 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
508 |
@Override |
2 | 509 |
public AbstractStringBuilder append(CharSequence s, int start, int end) { |
510 |
if (s == null) |
|
511 |
s = "null"; |
|
6295
91f1c55cf47e
6955504: (str) String[Builder/Buffer].append(char[],int,int) throws OutOfMemoryError in b94
martin
parents:
5986
diff
changeset
|
512 |
if ((start < 0) || (start > end) || (end > s.length())) |
2 | 513 |
throw new IndexOutOfBoundsException( |
514 |
"start " + start + ", end " + end + ", s.length() " |
|
515 |
+ s.length()); |
|
516 |
int len = end - start; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
517 |
ensureCapacityInternal(count + len); |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
518 |
for (int i = start, j = count; i < end; i++, j++) |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
519 |
value[j] = s.charAt(i); |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
520 |
count += len; |
2 | 521 |
return this; |
522 |
} |
|
523 |
||
524 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
525 |
* Appends the string representation of the {@code char} array |
2 | 526 |
* argument to this sequence. |
527 |
* <p> |
|
528 |
* The characters of the array argument are appended, in order, to |
|
529 |
* the contents of this sequence. The length of this sequence |
|
530 |
* increases by the length of the argument. |
|
531 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
532 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
533 |
* to a string by the method {@link String#valueOf(char[])}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
534 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
535 |
* {@link #append(String) appended} to this character sequence. |
2 | 536 |
* |
537 |
* @param str the characters to be appended. |
|
538 |
* @return a reference to this object. |
|
539 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
540 |
public AbstractStringBuilder append(char[] str) { |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
541 |
int len = str.length; |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
542 |
ensureCapacityInternal(count + len); |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
543 |
System.arraycopy(str, 0, value, count, len); |
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
544 |
count += len; |
2 | 545 |
return this; |
546 |
} |
|
547 |
||
548 |
/** |
|
549 |
* Appends the string representation of a subarray of the |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
550 |
* {@code char} array argument to this sequence. |
2 | 551 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
552 |
* Characters of the {@code char} array {@code str}, starting at |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
553 |
* index {@code offset}, are appended, in order, to the contents |
2 | 554 |
* of this sequence. The length of this sequence increases |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
555 |
* by the value of {@code len}. |
2 | 556 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
557 |
* The overall effect is exactly as if the arguments were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
558 |
* to a string by the method {@link String#valueOf(char[],int,int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
559 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
560 |
* {@link #append(String) appended} to this character sequence. |
2 | 561 |
* |
562 |
* @param str the characters to be appended. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
563 |
* @param offset the index of the first {@code char} to append. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
564 |
* @param len the number of {@code char}s to append. |
2 | 565 |
* @return a reference to this object. |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
566 |
* @throws IndexOutOfBoundsException |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
567 |
* if {@code offset < 0} or {@code len < 0} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
568 |
* or {@code offset+len > str.length} |
2 | 569 |
*/ |
570 |
public AbstractStringBuilder append(char str[], int offset, int len) { |
|
6295
91f1c55cf47e
6955504: (str) String[Builder/Buffer].append(char[],int,int) throws OutOfMemoryError in b94
martin
parents:
5986
diff
changeset
|
571 |
if (len > 0) // let arraycopy report AIOOBE for len < 0 |
91f1c55cf47e
6955504: (str) String[Builder/Buffer].append(char[],int,int) throws OutOfMemoryError in b94
martin
parents:
5986
diff
changeset
|
572 |
ensureCapacityInternal(count + len); |
2 | 573 |
System.arraycopy(str, offset, value, count, len); |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
574 |
count += len; |
2 | 575 |
return this; |
576 |
} |
|
577 |
||
578 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
579 |
* Appends the string representation of the {@code boolean} |
2 | 580 |
* argument to the sequence. |
581 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
582 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
583 |
* to a string by the method {@link String#valueOf(boolean)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
584 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
585 |
* {@link #append(String) appended} to this character sequence. |
2 | 586 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
587 |
* @param b a {@code boolean}. |
2 | 588 |
* @return a reference to this object. |
589 |
*/ |
|
590 |
public AbstractStringBuilder append(boolean b) { |
|
591 |
if (b) { |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
592 |
ensureCapacityInternal(count + 4); |
2 | 593 |
value[count++] = 't'; |
594 |
value[count++] = 'r'; |
|
595 |
value[count++] = 'u'; |
|
596 |
value[count++] = 'e'; |
|
597 |
} else { |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
598 |
ensureCapacityInternal(count + 5); |
2 | 599 |
value[count++] = 'f'; |
600 |
value[count++] = 'a'; |
|
601 |
value[count++] = 'l'; |
|
602 |
value[count++] = 's'; |
|
603 |
value[count++] = 'e'; |
|
604 |
} |
|
605 |
return this; |
|
606 |
} |
|
607 |
||
608 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
609 |
* Appends the string representation of the {@code char} |
2 | 610 |
* argument to this sequence. |
611 |
* <p> |
|
612 |
* The argument is appended to the contents of this sequence. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
613 |
* The length of this sequence increases by {@code 1}. |
2 | 614 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
615 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
616 |
* to a string by the method {@link String#valueOf(char)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
617 |
* and the character in that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
618 |
* {@link #append(String) appended} to this character sequence. |
2 | 619 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
620 |
* @param c a {@code char}. |
2 | 621 |
* @return a reference to this object. |
622 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
623 |
@Override |
2 | 624 |
public AbstractStringBuilder append(char c) { |
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
625 |
ensureCapacityInternal(count + 1); |
2 | 626 |
value[count++] = c; |
627 |
return this; |
|
628 |
} |
|
629 |
||
630 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
631 |
* Appends the string representation of the {@code int} |
2 | 632 |
* argument to this sequence. |
633 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
634 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
635 |
* to a string by the method {@link String#valueOf(int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
636 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
637 |
* {@link #append(String) appended} to this character sequence. |
2 | 638 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
639 |
* @param i an {@code int}. |
2 | 640 |
* @return a reference to this object. |
641 |
*/ |
|
642 |
public AbstractStringBuilder append(int i) { |
|
643 |
if (i == Integer.MIN_VALUE) { |
|
644 |
append("-2147483648"); |
|
645 |
return this; |
|
646 |
} |
|
647 |
int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1 |
|
648 |
: Integer.stringSize(i); |
|
649 |
int spaceNeeded = count + appendedLength; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
650 |
ensureCapacityInternal(spaceNeeded); |
2 | 651 |
Integer.getChars(i, spaceNeeded, value); |
652 |
count = spaceNeeded; |
|
653 |
return this; |
|
654 |
} |
|
655 |
||
656 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
657 |
* Appends the string representation of the {@code long} |
2 | 658 |
* argument to this sequence. |
659 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
660 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
661 |
* to a string by the method {@link String#valueOf(long)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
662 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
663 |
* {@link #append(String) appended} to this character sequence. |
2 | 664 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
665 |
* @param l a {@code long}. |
2 | 666 |
* @return a reference to this object. |
667 |
*/ |
|
668 |
public AbstractStringBuilder append(long l) { |
|
669 |
if (l == Long.MIN_VALUE) { |
|
670 |
append("-9223372036854775808"); |
|
671 |
return this; |
|
672 |
} |
|
673 |
int appendedLength = (l < 0) ? Long.stringSize(-l) + 1 |
|
674 |
: Long.stringSize(l); |
|
675 |
int spaceNeeded = count + appendedLength; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
676 |
ensureCapacityInternal(spaceNeeded); |
2 | 677 |
Long.getChars(l, spaceNeeded, value); |
678 |
count = spaceNeeded; |
|
679 |
return this; |
|
680 |
} |
|
681 |
||
682 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
683 |
* Appends the string representation of the {@code float} |
2 | 684 |
* argument to this sequence. |
685 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
686 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
687 |
* to a string by the method {@link String#valueOf(float)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
688 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
689 |
* {@link #append(String) appended} to this character sequence. |
2 | 690 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
691 |
* @param f a {@code float}. |
2 | 692 |
* @return a reference to this object. |
693 |
*/ |
|
694 |
public AbstractStringBuilder append(float f) { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
16742
diff
changeset
|
695 |
FloatingDecimal.appendTo(f,this); |
2 | 696 |
return this; |
697 |
} |
|
698 |
||
699 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
700 |
* Appends the string representation of the {@code double} |
2 | 701 |
* argument to this sequence. |
702 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
703 |
* The overall effect is exactly as if the argument were converted |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
704 |
* to a string by the method {@link String#valueOf(double)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
705 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
706 |
* {@link #append(String) appended} to this character sequence. |
2 | 707 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
708 |
* @param d a {@code double}. |
2 | 709 |
* @return a reference to this object. |
710 |
*/ |
|
711 |
public AbstractStringBuilder append(double d) { |
|
18143
b6ef7bd945ce
7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents:
16742
diff
changeset
|
712 |
FloatingDecimal.appendTo(d,this); |
2 | 713 |
return this; |
714 |
} |
|
715 |
||
716 |
/** |
|
717 |
* Removes the characters in a substring of this sequence. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
718 |
* The substring begins at the specified {@code start} and extends to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
719 |
* the character at index {@code end - 1} or to the end of the |
2 | 720 |
* sequence if no such character exists. If |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
721 |
* {@code start} is equal to {@code end}, no changes are made. |
2 | 722 |
* |
723 |
* @param start The beginning index, inclusive. |
|
724 |
* @param end The ending index, exclusive. |
|
725 |
* @return This object. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
726 |
* @throws StringIndexOutOfBoundsException if {@code start} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
727 |
* is negative, greater than {@code length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
728 |
* greater than {@code end}. |
2 | 729 |
*/ |
730 |
public AbstractStringBuilder delete(int start, int end) { |
|
731 |
if (start < 0) |
|
732 |
throw new StringIndexOutOfBoundsException(start); |
|
733 |
if (end > count) |
|
734 |
end = count; |
|
735 |
if (start > end) |
|
736 |
throw new StringIndexOutOfBoundsException(); |
|
737 |
int len = end - start; |
|
738 |
if (len > 0) { |
|
739 |
System.arraycopy(value, start+len, value, start, count-end); |
|
740 |
count -= len; |
|
741 |
} |
|
742 |
return this; |
|
743 |
} |
|
744 |
||
745 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
746 |
* Appends the string representation of the {@code codePoint} |
2 | 747 |
* argument to this sequence. |
748 |
* |
|
749 |
* <p> The argument is appended to the contents of this sequence. |
|
750 |
* The length of this sequence increases by |
|
751 |
* {@link Character#charCount(int) Character.charCount(codePoint)}. |
|
752 |
* |
|
753 |
* <p> The overall effect is exactly as if the argument were |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
754 |
* converted to a {@code char} array by the method |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
755 |
* {@link Character#toChars(int)} and the character in that array |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
756 |
* were then {@link #append(char[]) appended} to this character |
2 | 757 |
* sequence. |
758 |
* |
|
759 |
* @param codePoint a Unicode code point |
|
760 |
* @return a reference to this object. |
|
761 |
* @exception IllegalArgumentException if the specified |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
762 |
* {@code codePoint} isn't a valid Unicode code point |
2 | 763 |
*/ |
764 |
public AbstractStringBuilder appendCodePoint(int codePoint) { |
|
5986
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
765 |
final int count = this.count; |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
766 |
|
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
767 |
if (Character.isBmpCodePoint(codePoint)) { |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
768 |
ensureCapacityInternal(count + 1); |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
769 |
value[count] = (char) codePoint; |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
770 |
this.count = count + 1; |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
771 |
} else if (Character.isValidCodePoint(codePoint)) { |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
772 |
ensureCapacityInternal(count + 2); |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
773 |
Character.toSurrogates(codePoint, value, count); |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
774 |
this.count = count + 2; |
04eb44085c00
6934265: Add public method Character.isBmpCodePoint
martin
parents:
5627
diff
changeset
|
775 |
} else { |
2 | 776 |
throw new IllegalArgumentException(); |
777 |
} |
|
778 |
return this; |
|
779 |
} |
|
780 |
||
781 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
782 |
* Removes the {@code char} at the specified position in this |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
783 |
* sequence. This sequence is shortened by one {@code char}. |
2 | 784 |
* |
785 |
* <p>Note: If the character at the given index is a supplementary |
|
786 |
* character, this method does not remove the entire character. If |
|
787 |
* correct handling of supplementary characters is required, |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
788 |
* determine the number of {@code char}s to remove by calling |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
789 |
* {@code Character.charCount(thisSequence.codePointAt(index))}, |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
790 |
* where {@code thisSequence} is this sequence. |
2 | 791 |
* |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
792 |
* @param index Index of {@code char} to remove |
2 | 793 |
* @return This object. |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
794 |
* @throws StringIndexOutOfBoundsException if the {@code index} |
2 | 795 |
* is negative or greater than or equal to |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
796 |
* {@code length()}. |
2 | 797 |
*/ |
798 |
public AbstractStringBuilder deleteCharAt(int index) { |
|
799 |
if ((index < 0) || (index >= count)) |
|
800 |
throw new StringIndexOutOfBoundsException(index); |
|
801 |
System.arraycopy(value, index+1, value, index, count-index-1); |
|
802 |
count--; |
|
803 |
return this; |
|
804 |
} |
|
805 |
||
806 |
/** |
|
807 |
* Replaces the characters in a substring of this sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
808 |
* with characters in the specified {@code String}. The substring |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
809 |
* begins at the specified {@code start} and extends to the character |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
810 |
* at index {@code end - 1} or to the end of the |
2 | 811 |
* sequence if no such character exists. First the |
812 |
* characters in the substring are removed and then the specified |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
813 |
* {@code String} is inserted at {@code start}. (This |
2 | 814 |
* sequence will be lengthened to accommodate the |
815 |
* specified String if necessary.) |
|
816 |
* |
|
817 |
* @param start The beginning index, inclusive. |
|
818 |
* @param end The ending index, exclusive. |
|
819 |
* @param str String that will replace previous contents. |
|
820 |
* @return This object. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
821 |
* @throws StringIndexOutOfBoundsException if {@code start} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
822 |
* is negative, greater than {@code length()}, or |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
823 |
* greater than {@code end}. |
2 | 824 |
*/ |
825 |
public AbstractStringBuilder replace(int start, int end, String str) { |
|
826 |
if (start < 0) |
|
827 |
throw new StringIndexOutOfBoundsException(start); |
|
828 |
if (start > count) |
|
829 |
throw new StringIndexOutOfBoundsException("start > length()"); |
|
830 |
if (start > end) |
|
831 |
throw new StringIndexOutOfBoundsException("start > end"); |
|
832 |
||
833 |
if (end > count) |
|
834 |
end = count; |
|
835 |
int len = str.length(); |
|
836 |
int newCount = count + len - (end - start); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
837 |
ensureCapacityInternal(newCount); |
2 | 838 |
|
839 |
System.arraycopy(value, end, value, start + len, count - end); |
|
840 |
str.getChars(value, start); |
|
841 |
count = newCount; |
|
842 |
return this; |
|
843 |
} |
|
844 |
||
845 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
846 |
* Returns a new {@code String} that contains a subsequence of |
2 | 847 |
* characters currently contained in this character sequence. The |
848 |
* substring begins at the specified index and extends to the end of |
|
849 |
* this sequence. |
|
850 |
* |
|
851 |
* @param start The beginning index, inclusive. |
|
852 |
* @return The new string. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
853 |
* @throws StringIndexOutOfBoundsException if {@code start} is |
2 | 854 |
* less than zero, or greater than the length of this object. |
855 |
*/ |
|
856 |
public String substring(int start) { |
|
857 |
return substring(start, count); |
|
858 |
} |
|
859 |
||
860 |
/** |
|
861 |
* Returns a new character sequence that is a subsequence of this sequence. |
|
862 |
* |
|
863 |
* <p> An invocation of this method of the form |
|
864 |
* |
|
21334 | 865 |
* <pre>{@code |
866 |
* sb.subSequence(begin, end)}</pre> |
|
2 | 867 |
* |
868 |
* behaves in exactly the same way as the invocation |
|
869 |
* |
|
21334 | 870 |
* <pre>{@code |
871 |
* sb.substring(begin, end)}</pre> |
|
2 | 872 |
* |
873 |
* This method is provided so that this class can |
|
21334 | 874 |
* implement the {@link CharSequence} interface. |
2 | 875 |
* |
876 |
* @param start the start index, inclusive. |
|
877 |
* @param end the end index, exclusive. |
|
878 |
* @return the specified subsequence. |
|
879 |
* |
|
880 |
* @throws IndexOutOfBoundsException |
|
14997 | 881 |
* if {@code start} or {@code end} are negative, |
882 |
* if {@code end} is greater than {@code length()}, |
|
883 |
* or if {@code start} is greater than {@code end} |
|
2 | 884 |
* @spec JSR-51 |
885 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
886 |
@Override |
2 | 887 |
public CharSequence subSequence(int start, int end) { |
888 |
return substring(start, end); |
|
889 |
} |
|
890 |
||
891 |
/** |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
892 |
* Returns a new {@code String} that contains a subsequence of |
2 | 893 |
* characters currently contained in this sequence. The |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
894 |
* substring begins at the specified {@code start} and |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
895 |
* extends to the character at index {@code end - 1}. |
2 | 896 |
* |
897 |
* @param start The beginning index, inclusive. |
|
898 |
* @param end The ending index, exclusive. |
|
899 |
* @return The new string. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
900 |
* @throws StringIndexOutOfBoundsException if {@code start} |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
901 |
* or {@code end} are negative or greater than |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
902 |
* {@code length()}, or {@code start} is |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
903 |
* greater than {@code end}. |
2 | 904 |
*/ |
905 |
public String substring(int start, int end) { |
|
906 |
if (start < 0) |
|
907 |
throw new StringIndexOutOfBoundsException(start); |
|
908 |
if (end > count) |
|
909 |
throw new StringIndexOutOfBoundsException(end); |
|
910 |
if (start > end) |
|
911 |
throw new StringIndexOutOfBoundsException(end - start); |
|
912 |
return new String(value, start, end - start); |
|
913 |
} |
|
914 |
||
915 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
916 |
* Inserts the string representation of a subarray of the {@code str} |
2 | 917 |
* array argument into this sequence. The subarray begins at the |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
918 |
* specified {@code offset} and extends {@code len} {@code char}s. |
2 | 919 |
* The characters of the subarray are inserted into this sequence at |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
920 |
* the position indicated by {@code index}. The length of this |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
921 |
* sequence increases by {@code len} {@code char}s. |
2 | 922 |
* |
923 |
* @param index position at which to insert subarray. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
924 |
* @param str A {@code char} array. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
925 |
* @param offset the index of the first {@code char} in subarray to |
2 | 926 |
* be inserted. |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
927 |
* @param len the number of {@code char}s in the subarray to |
2 | 928 |
* be inserted. |
929 |
* @return This object |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
930 |
* @throws StringIndexOutOfBoundsException if {@code index} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
931 |
* is negative or greater than {@code length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
932 |
* {@code offset} or {@code len} are negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
933 |
* {@code (offset+len)} is greater than |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
934 |
* {@code str.length}. |
2 | 935 |
*/ |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
936 |
public AbstractStringBuilder insert(int index, char[] str, int offset, |
2 | 937 |
int len) |
938 |
{ |
|
939 |
if ((index < 0) || (index > length())) |
|
940 |
throw new StringIndexOutOfBoundsException(index); |
|
941 |
if ((offset < 0) || (len < 0) || (offset > str.length - len)) |
|
942 |
throw new StringIndexOutOfBoundsException( |
|
943 |
"offset " + offset + ", len " + len + ", str.length " |
|
944 |
+ str.length); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
945 |
ensureCapacityInternal(count + len); |
2 | 946 |
System.arraycopy(value, index, value, index + len, count - index); |
947 |
System.arraycopy(str, offset, value, index, len); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
948 |
count += len; |
2 | 949 |
return this; |
950 |
} |
|
951 |
||
952 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
953 |
* Inserts the string representation of the {@code Object} |
2 | 954 |
* argument into this character sequence. |
955 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
956 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
957 |
* converted to a string by the method {@link String#valueOf(Object)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
958 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
959 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
960 |
* sequence at the indicated offset. |
2 | 961 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
962 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
963 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
964 |
* of this sequence. |
2 | 965 |
* |
966 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
967 |
* @param obj an {@code Object}. |
2 | 968 |
* @return a reference to this object. |
969 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
970 |
*/ |
|
971 |
public AbstractStringBuilder insert(int offset, Object obj) { |
|
972 |
return insert(offset, String.valueOf(obj)); |
|
973 |
} |
|
974 |
||
975 |
/** |
|
976 |
* Inserts the string into this character sequence. |
|
977 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
978 |
* The characters of the {@code String} argument are inserted, in |
2 | 979 |
* order, into this sequence at the indicated offset, moving up any |
980 |
* characters originally above that position and increasing the length |
|
981 |
* of this sequence by the length of the argument. If |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
982 |
* {@code str} is {@code null}, then the four characters |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
983 |
* {@code "null"} are inserted into this sequence. |
2 | 984 |
* <p> |
985 |
* The character at index <i>k</i> in the new character sequence is |
|
986 |
* equal to: |
|
987 |
* <ul> |
|
988 |
* <li>the character at index <i>k</i> in the old character sequence, if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
989 |
* <i>k</i> is less than {@code offset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
990 |
* <li>the character at index <i>k</i>{@code -offset} in the |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
991 |
* argument {@code str}, if <i>k</i> is not less than |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
992 |
* {@code offset} but is less than {@code offset+str.length()} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
993 |
* <li>the character at index <i>k</i>{@code -str.length()} in the |
2 | 994 |
* old character sequence, if <i>k</i> is not less than |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
995 |
* {@code offset+str.length()} |
2 | 996 |
* </ul><p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
997 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
998 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
999 |
* of this sequence. |
2 | 1000 |
* |
1001 |
* @param offset the offset. |
|
1002 |
* @param str a string. |
|
1003 |
* @return a reference to this object. |
|
1004 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1005 |
*/ |
|
1006 |
public AbstractStringBuilder insert(int offset, String str) { |
|
1007 |
if ((offset < 0) || (offset > length())) |
|
1008 |
throw new StringIndexOutOfBoundsException(offset); |
|
1009 |
if (str == null) |
|
1010 |
str = "null"; |
|
1011 |
int len = str.length(); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1012 |
ensureCapacityInternal(count + len); |
2 | 1013 |
System.arraycopy(value, offset, value, offset + len, count - offset); |
1014 |
str.getChars(value, offset); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1015 |
count += len; |
2 | 1016 |
return this; |
1017 |
} |
|
1018 |
||
1019 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1020 |
* Inserts the string representation of the {@code char} array |
2 | 1021 |
* argument into this sequence. |
1022 |
* <p> |
|
1023 |
* The characters of the array argument are inserted into the |
|
1024 |
* contents of this sequence at the position indicated by |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1025 |
* {@code offset}. The length of this sequence increases by |
2 | 1026 |
* the length of the argument. |
1027 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1028 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1029 |
* converted to a string by the method {@link String#valueOf(char[])}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1030 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1031 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1032 |
* sequence at the indicated offset. |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1033 |
* <p> |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1034 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1035 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1036 |
* of this sequence. |
2 | 1037 |
* |
1038 |
* @param offset the offset. |
|
1039 |
* @param str a character array. |
|
1040 |
* @return a reference to this object. |
|
1041 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1042 |
*/ |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1043 |
public AbstractStringBuilder insert(int offset, char[] str) { |
2 | 1044 |
if ((offset < 0) || (offset > length())) |
1045 |
throw new StringIndexOutOfBoundsException(offset); |
|
1046 |
int len = str.length; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1047 |
ensureCapacityInternal(count + len); |
2 | 1048 |
System.arraycopy(value, offset, value, offset + len, count - offset); |
1049 |
System.arraycopy(str, 0, value, offset, len); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1050 |
count += len; |
2 | 1051 |
return this; |
1052 |
} |
|
1053 |
||
1054 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1055 |
* Inserts the specified {@code CharSequence} into this sequence. |
2 | 1056 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1057 |
* The characters of the {@code CharSequence} argument are inserted, |
2 | 1058 |
* in order, into this sequence at the indicated offset, moving up |
1059 |
* any characters originally above that position and increasing the length |
|
1060 |
* of this sequence by the length of the argument s. |
|
1061 |
* <p> |
|
1062 |
* The result of this method is exactly the same as if it were an |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1063 |
* invocation of this object's |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1064 |
* {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length()) |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1065 |
* method. |
2 | 1066 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1067 |
* <p>If {@code s} is {@code null}, then the four characters |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1068 |
* {@code "null"} are inserted into this sequence. |
2 | 1069 |
* |
1070 |
* @param dstOffset the offset. |
|
1071 |
* @param s the sequence to be inserted |
|
1072 |
* @return a reference to this object. |
|
1073 |
* @throws IndexOutOfBoundsException if the offset is invalid. |
|
1074 |
*/ |
|
1075 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s) { |
|
1076 |
if (s == null) |
|
1077 |
s = "null"; |
|
1078 |
if (s instanceof String) |
|
1079 |
return this.insert(dstOffset, (String)s); |
|
1080 |
return this.insert(dstOffset, s, 0, s.length()); |
|
1081 |
} |
|
1082 |
||
1083 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1084 |
* Inserts a subsequence of the specified {@code CharSequence} into |
2 | 1085 |
* this sequence. |
1086 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1087 |
* The subsequence of the argument {@code s} specified by |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1088 |
* {@code start} and {@code end} are inserted, |
2 | 1089 |
* in order, into this sequence at the specified destination offset, moving |
1090 |
* up any characters originally above that position. The length of this |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1091 |
* sequence is increased by {@code end - start}. |
2 | 1092 |
* <p> |
1093 |
* The character at index <i>k</i> in this sequence becomes equal to: |
|
1094 |
* <ul> |
|
1095 |
* <li>the character at index <i>k</i> in this sequence, if |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1096 |
* <i>k</i> is less than {@code dstOffset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1097 |
* <li>the character at index <i>k</i>{@code +start-dstOffset} in |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1098 |
* the argument {@code s}, if <i>k</i> is greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1099 |
* {@code dstOffset} but is less than {@code dstOffset+end-start} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1100 |
* <li>the character at index <i>k</i>{@code -(end-start)} in this |
2 | 1101 |
* sequence, if <i>k</i> is greater than or equal to |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1102 |
* {@code dstOffset+end-start} |
2 | 1103 |
* </ul><p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1104 |
* The {@code dstOffset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1105 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1106 |
* of this sequence. |
2 | 1107 |
* <p>The start argument must be nonnegative, and not greater than |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1108 |
* {@code end}. |
2 | 1109 |
* <p>The end argument must be greater than or equal to |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1110 |
* {@code start}, and less than or equal to the length of s. |
2 | 1111 |
* |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1112 |
* <p>If {@code s} is {@code null}, then this method inserts |
2 | 1113 |
* characters as if the s parameter was a sequence containing the four |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1114 |
* characters {@code "null"}. |
2 | 1115 |
* |
1116 |
* @param dstOffset the offset in this sequence. |
|
1117 |
* @param s the sequence to be inserted. |
|
1118 |
* @param start the starting index of the subsequence to be inserted. |
|
1119 |
* @param end the end index of the subsequence to be inserted. |
|
1120 |
* @return a reference to this object. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1121 |
* @throws IndexOutOfBoundsException if {@code dstOffset} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1122 |
* is negative or greater than {@code this.length()}, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1123 |
* {@code start} or {@code end} are negative, or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1124 |
* {@code start} is greater than {@code end} or |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1125 |
* {@code end} is greater than {@code s.length()} |
2 | 1126 |
*/ |
1127 |
public AbstractStringBuilder insert(int dstOffset, CharSequence s, |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1128 |
int start, int end) { |
2 | 1129 |
if (s == null) |
1130 |
s = "null"; |
|
1131 |
if ((dstOffset < 0) || (dstOffset > this.length())) |
|
1132 |
throw new IndexOutOfBoundsException("dstOffset "+dstOffset); |
|
1133 |
if ((start < 0) || (end < 0) || (start > end) || (end > s.length())) |
|
1134 |
throw new IndexOutOfBoundsException( |
|
1135 |
"start " + start + ", end " + end + ", s.length() " |
|
1136 |
+ s.length()); |
|
1137 |
int len = end - start; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1138 |
ensureCapacityInternal(count + len); |
2 | 1139 |
System.arraycopy(value, dstOffset, value, dstOffset + len, |
1140 |
count - dstOffset); |
|
1141 |
for (int i=start; i<end; i++) |
|
1142 |
value[dstOffset++] = s.charAt(i); |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1143 |
count += len; |
2 | 1144 |
return this; |
1145 |
} |
|
1146 |
||
1147 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1148 |
* Inserts the string representation of the {@code boolean} |
2 | 1149 |
* argument into this sequence. |
1150 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1151 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1152 |
* converted to a string by the method {@link String#valueOf(boolean)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1153 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1154 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1155 |
* sequence at the indicated offset. |
2 | 1156 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1157 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1158 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1159 |
* of this sequence. |
2 | 1160 |
* |
1161 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1162 |
* @param b a {@code boolean}. |
2 | 1163 |
* @return a reference to this object. |
1164 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1165 |
*/ |
|
1166 |
public AbstractStringBuilder insert(int offset, boolean b) { |
|
1167 |
return insert(offset, String.valueOf(b)); |
|
1168 |
} |
|
1169 |
||
1170 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1171 |
* Inserts the string representation of the {@code char} |
2 | 1172 |
* argument into this sequence. |
1173 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1174 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1175 |
* converted to a string by the method {@link String#valueOf(char)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1176 |
* and the character in that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1177 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1178 |
* sequence at the indicated offset. |
2 | 1179 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1180 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1181 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1182 |
* of this sequence. |
2 | 1183 |
* |
1184 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1185 |
* @param c a {@code char}. |
2 | 1186 |
* @return a reference to this object. |
1187 |
* @throws IndexOutOfBoundsException if the offset is invalid. |
|
1188 |
*/ |
|
1189 |
public AbstractStringBuilder insert(int offset, char c) { |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1190 |
ensureCapacityInternal(count + 1); |
2 | 1191 |
System.arraycopy(value, offset, value, offset + 1, count - offset); |
1192 |
value[offset] = c; |
|
5466
f130bb07764b
6933217: Huge arrays handled poorly in core libraries
martin
parents:
1247
diff
changeset
|
1193 |
count += 1; |
2 | 1194 |
return this; |
1195 |
} |
|
1196 |
||
1197 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1198 |
* Inserts the string representation of the second {@code int} |
2 | 1199 |
* argument into this sequence. |
1200 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1201 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1202 |
* converted to a string by the method {@link String#valueOf(int)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1203 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1204 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1205 |
* sequence at the indicated offset. |
2 | 1206 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1207 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1208 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1209 |
* of this sequence. |
2 | 1210 |
* |
1211 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1212 |
* @param i an {@code int}. |
2 | 1213 |
* @return a reference to this object. |
1214 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1215 |
*/ |
|
1216 |
public AbstractStringBuilder insert(int offset, int i) { |
|
1217 |
return insert(offset, String.valueOf(i)); |
|
1218 |
} |
|
1219 |
||
1220 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1221 |
* Inserts the string representation of the {@code long} |
2 | 1222 |
* argument into this sequence. |
1223 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1224 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1225 |
* converted to a string by the method {@link String#valueOf(long)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1226 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1227 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1228 |
* sequence at the indicated offset. |
2 | 1229 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1230 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1231 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1232 |
* of this sequence. |
2 | 1233 |
* |
1234 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1235 |
* @param l a {@code long}. |
2 | 1236 |
* @return a reference to this object. |
1237 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1238 |
*/ |
|
1239 |
public AbstractStringBuilder insert(int offset, long l) { |
|
1240 |
return insert(offset, String.valueOf(l)); |
|
1241 |
} |
|
1242 |
||
1243 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1244 |
* Inserts the string representation of the {@code float} |
2 | 1245 |
* argument into this sequence. |
1246 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1247 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1248 |
* converted to a string by the method {@link String#valueOf(float)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1249 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1250 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1251 |
* sequence at the indicated offset. |
2 | 1252 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1253 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1254 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1255 |
* of this sequence. |
2 | 1256 |
* |
1257 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1258 |
* @param f a {@code float}. |
2 | 1259 |
* @return a reference to this object. |
1260 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1261 |
*/ |
|
1262 |
public AbstractStringBuilder insert(int offset, float f) { |
|
1263 |
return insert(offset, String.valueOf(f)); |
|
1264 |
} |
|
1265 |
||
1266 |
/** |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1267 |
* Inserts the string representation of the {@code double} |
2 | 1268 |
* argument into this sequence. |
1269 |
* <p> |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1270 |
* The overall effect is exactly as if the second argument were |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1271 |
* converted to a string by the method {@link String#valueOf(double)}, |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1272 |
* and the characters of that string were then |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1273 |
* {@link #insert(int,String) inserted} into this character |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1274 |
* sequence at the indicated offset. |
2 | 1275 |
* <p> |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1276 |
* The {@code offset} argument must be greater than or equal to |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1277 |
* {@code 0}, and less than or equal to the {@linkplain #length() length} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1278 |
* of this sequence. |
2 | 1279 |
* |
1280 |
* @param offset the offset. |
|
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
1281 |
* @param d a {@code double}. |
2 | 1282 |
* @return a reference to this object. |
1283 |
* @throws StringIndexOutOfBoundsException if the offset is invalid. |
|
1284 |
*/ |
|
1285 |
public AbstractStringBuilder insert(int offset, double d) { |
|
1286 |
return insert(offset, String.valueOf(d)); |
|
1287 |
} |
|
1288 |
||
1289 |
/** |
|
1290 |
* Returns the index within this string of the first occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1291 |
* specified substring. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1292 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1293 |
* <p>The returned index is the smallest value {@code k} for which: |
21334 | 1294 |
* <pre>{@code |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1295 |
* this.toString().startsWith(str, k) |
21334 | 1296 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1297 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1298 |
* |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1299 |
* @param str the substring to search for. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1300 |
* @return the index of the first occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1301 |
* or {@code -1} if there is no such occurrence. |
2 | 1302 |
*/ |
1303 |
public int indexOf(String str) { |
|
1304 |
return indexOf(str, 0); |
|
1305 |
} |
|
1306 |
||
1307 |
/** |
|
1308 |
* Returns the index within this string of the first occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1309 |
* specified substring, starting at the specified index. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1310 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1311 |
* <p>The returned index is the smallest value {@code k} for which: |
21334 | 1312 |
* <pre>{@code |
19591
80e86f94c0e9
8016018: Typo in AbstractStringBuilder#indexOf and #lastIndexOf descriptions
igerasim
parents:
18143
diff
changeset
|
1313 |
* k >= Math.min(fromIndex, this.length()) && |
2 | 1314 |
* this.toString().startsWith(str, k) |
21334 | 1315 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1316 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1317 |
* |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1318 |
* @param str the substring to search for. |
2 | 1319 |
* @param fromIndex the index from which to start the search. |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1320 |
* @return the index of the first occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1321 |
* starting at the specified index, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1322 |
* or {@code -1} if there is no such occurrence. |
2 | 1323 |
*/ |
1324 |
public int indexOf(String str, int fromIndex) { |
|
14686
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
1325 |
return String.indexOf(value, 0, count, str, fromIndex); |
2 | 1326 |
} |
1327 |
||
1328 |
/** |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1329 |
* Returns the index within this string of the last occurrence of the |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1330 |
* specified substring. The last occurrence of the empty string "" is |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1331 |
* considered to occur at the index value {@code this.length()}. |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1332 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1333 |
* <p>The returned index is the largest value {@code k} for which: |
21334 | 1334 |
* <pre>{@code |
2 | 1335 |
* this.toString().startsWith(str, k) |
21334 | 1336 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1337 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1338 |
* |
1339 |
* @param str the substring to search for. |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1340 |
* @return the index of the last occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1341 |
* or {@code -1} if there is no such occurrence. |
2 | 1342 |
*/ |
1343 |
public int lastIndexOf(String str) { |
|
1344 |
return lastIndexOf(str, count); |
|
1345 |
} |
|
1346 |
||
1347 |
/** |
|
1348 |
* Returns the index within this string of the last occurrence of the |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1349 |
* specified substring, searching backward starting at the specified index. |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1350 |
* |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1351 |
* <p>The returned index is the largest value {@code k} for which: |
21334 | 1352 |
* <pre>{@code |
19591
80e86f94c0e9
8016018: Typo in AbstractStringBuilder#indexOf and #lastIndexOf descriptions
igerasim
parents:
18143
diff
changeset
|
1353 |
* k <= Math.min(fromIndex, this.length()) && |
2 | 1354 |
* this.toString().startsWith(str, k) |
21334 | 1355 |
* }</pre> |
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1356 |
* If no such value of {@code k} exists, then {@code -1} is returned. |
2 | 1357 |
* |
1358 |
* @param str the substring to search for. |
|
1359 |
* @param fromIndex the index to start the search from. |
|
23024
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1360 |
* @return the index of the last occurrence of the specified substring, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1361 |
* searching backward from the specified index, |
7d5ecb31115f
8027640: String.indexOf(String,int) for the empty string case not specified
bchristi
parents:
21334
diff
changeset
|
1362 |
* or {@code -1} if there is no such occurrence. |
2 | 1363 |
*/ |
1364 |
public int lastIndexOf(String str, int fromIndex) { |
|
14686
fb59583d33b2
6553074: String{Buffer,Builder}.indexOf(Str, int) contains unnecessary allocation
mduigou
parents:
14332
diff
changeset
|
1365 |
return String.lastIndexOf(value, 0, count, str, fromIndex); |
2 | 1366 |
} |
1367 |
||
1368 |
/** |
|
1369 |
* Causes this character sequence to be replaced by the reverse of |
|
1370 |
* the sequence. If there are any surrogate pairs included in the |
|
1371 |
* sequence, these are treated as single characters for the |
|
1372 |
* reverse operation. Thus, the order of the high-low surrogates |
|
1373 |
* is never reversed. |
|
1374 |
* |
|
1375 |
* Let <i>n</i> be the character length of this character sequence |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1376 |
* (not the length in {@code char} values) just prior to |
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1377 |
* execution of the {@code reverse} method. Then the |
2 | 1378 |
* character at index <i>k</i> in the new character sequence is |
1379 |
* equal to the character at index <i>n-k-1</i> in the old |
|
1380 |
* character sequence. |
|
1381 |
* |
|
1382 |
* <p>Note that the reverse operation may result in producing |
|
1383 |
* surrogate pairs that were unpaired low-surrogates and |
|
1384 |
* high-surrogates before the operation. For example, reversing |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1385 |
* "\u005CuDC00\u005CuD800" produces "\u005CuD800\u005CuDC00" which is |
2 | 1386 |
* a valid surrogate pair. |
1387 |
* |
|
1388 |
* @return a reference to this object. |
|
1389 |
*/ |
|
1390 |
public AbstractStringBuilder reverse() { |
|
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1391 |
boolean hasSurrogates = false; |
2 | 1392 |
int n = count - 1; |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1393 |
for (int j = (n-1) >> 1; j >= 0; j--) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1394 |
int k = n - j; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1395 |
char cj = value[j]; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1396 |
char ck = value[k]; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1397 |
value[j] = ck; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1398 |
value[k] = cj; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1399 |
if (Character.isSurrogate(cj) || |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1400 |
Character.isSurrogate(ck)) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1401 |
hasSurrogates = true; |
2 | 1402 |
} |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1403 |
} |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1404 |
if (hasSurrogates) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1405 |
reverseAllValidSurrogatePairs(); |
2 | 1406 |
} |
16714
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1407 |
return this; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1408 |
} |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1409 |
|
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1410 |
/** Outlined helper method for reverse() */ |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1411 |
private void reverseAllValidSurrogatePairs() { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1412 |
for (int i = 0; i < count - 1; i++) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1413 |
char c2 = value[i]; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1414 |
if (Character.isLowSurrogate(c2)) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1415 |
char c1 = value[i + 1]; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1416 |
if (Character.isHighSurrogate(c1)) { |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1417 |
value[i++] = c1; |
cb235d5f8bd4
8010316: Improve handling of char sequences containing surrogates
martin
parents:
15312
diff
changeset
|
1418 |
value[i] = c2; |
2 | 1419 |
} |
1420 |
} |
|
1421 |
} |
|
1422 |
} |
|
1423 |
||
1424 |
/** |
|
1425 |
* Returns a string representing the data in this sequence. |
|
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1426 |
* A new {@code String} object is allocated and initialized to |
2 | 1427 |
* contain the character sequence currently represented by this |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1428 |
* object. This {@code String} is then returned. Subsequent |
2 | 1429 |
* changes to this sequence do not affect the contents of the |
11676
7e75ec031b97
7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents:
7668
diff
changeset
|
1430 |
* {@code String}. |
2 | 1431 |
* |
1432 |
* @return a string representation of this sequence of characters. |
|
1433 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13822
diff
changeset
|
1434 |
@Override |
2 | 1435 |
public abstract String toString(); |
1436 |
||
1437 |
/** |
|
28667
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1438 |
* {@inheritDoc} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1439 |
* @since 1.9 |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1440 |
*/ |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1441 |
@Override |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1442 |
public IntStream chars() { |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1443 |
// Reuse String-based spliterator. This requires a supplier to |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1444 |
// capture the value and count when the terminal operation is executed |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1445 |
return StreamSupport.intStream( |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1446 |
() -> new String.IntCharArraySpliterator(value, 0, count, 0), |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1447 |
Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED, |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1448 |
false); |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1449 |
} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1450 |
|
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1451 |
/** |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1452 |
* {@inheritDoc} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1453 |
* @since 1.9 |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1454 |
*/ |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1455 |
@Override |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1456 |
public IntStream codePoints() { |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1457 |
// Reuse String-based spliterator. This requires a supplier to |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1458 |
// capture the value and count when the terminal operation is executed |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1459 |
return StreamSupport.intStream( |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1460 |
() -> new String.CodePointsSpliterator(value, 0, count, 0), |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1461 |
Spliterator.ORDERED, |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1462 |
false); |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1463 |
} |
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1464 |
|
2245cc40bf5d
8071477: Better Spliterator implementations for String.chars() and String.codePoints()
psandoz
parents:
25859
diff
changeset
|
1465 |
/** |
14997 | 1466 |
* Needed by {@code String} for the contentEquals method. |
2 | 1467 |
*/ |
1468 |
final char[] getValue() { |
|
1469 |
return value; |
|
1470 |
} |
|
1471 |
||
1472 |
} |