134 |
|
* to ensure that it can hold at least the given number of elements. |
135 |
|
* |
136 |
|
* @param minCapacity the desired minimum capacity |
137 |
– |
* @since 9 |
137 |
|
*/ |
138 |
< |
public void ensureCapacity(int minCapacity) { |
138 |
> |
/* TODO: public */ private void ensureCapacity(int minCapacity) { |
139 |
|
if (minCapacity > elements.length) |
140 |
|
grow(minCapacity - elements.length); |
141 |
|
// checkInvariants(); |
143 |
|
|
144 |
|
/** |
145 |
|
* Minimizes the internal storage of this collection. |
147 |
– |
* |
148 |
– |
* @since 9 |
146 |
|
*/ |
147 |
< |
public void trimToSize() { |
147 |
> |
/* TODO: public */ private void trimToSize() { |
148 |
|
if (size < elements.length) { |
149 |
|
elements = toArray(); |
150 |
|
head = 0; |
193 |
|
} |
194 |
|
|
195 |
|
/** |
199 |
– |
* Returns the array index of the last element. |
200 |
– |
* May return invalid index -1 if there are no elements. |
201 |
– |
*/ |
202 |
– |
final int tail() { |
203 |
– |
return add(head, size - 1, elements.length); |
204 |
– |
} |
205 |
– |
|
206 |
– |
/** |
207 |
– |
* Adds i and j, mod modulus. |
208 |
– |
* Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus. |
209 |
– |
*/ |
210 |
– |
static final int add(int i, int j, int modulus) { |
211 |
– |
if ((i += j) - modulus >= 0) i -= modulus; |
212 |
– |
return i; |
213 |
– |
} |
214 |
– |
|
215 |
– |
/** |
196 |
|
* Increments i, mod modulus. |
197 |
|
* Precondition and postcondition: 0 <= i < modulus. |
198 |
|
*/ |
211 |
|
} |
212 |
|
|
213 |
|
/** |
214 |
+ |
* Adds i and j, mod modulus. |
215 |
+ |
* Precondition and postcondition: 0 <= i < modulus, 0 <= j <= modulus. |
216 |
+ |
*/ |
217 |
+ |
static final int add(int i, int j, int modulus) { |
218 |
+ |
if ((i += j) - modulus >= 0) i -= modulus; |
219 |
+ |
return i; |
220 |
+ |
} |
221 |
+ |
|
222 |
+ |
/** |
223 |
+ |
* Returns the array index of the last element. |
224 |
+ |
* May return invalid index -1 if there are no elements. |
225 |
+ |
*/ |
226 |
+ |
final int tail() { |
227 |
+ |
return add(head, size - 1, elements.length); |
228 |
+ |
} |
229 |
+ |
|
230 |
+ |
/** |
231 |
|
* Returns element at array index i. |
232 |
|
*/ |
233 |
|
@SuppressWarnings("unchecked") |
302 |
|
public boolean addAll(Collection<? extends E> c) { |
303 |
|
// checkInvariants(); |
304 |
|
Object[] a, elements; |
305 |
< |
int len, capacity, s = size; |
306 |
< |
if ((len = (a = c.toArray()).length) == 0) |
305 |
> |
int newcomers, capacity, s = size; |
306 |
> |
if ((newcomers = (a = c.toArray()).length) == 0) |
307 |
|
return false; |
308 |
< |
while ((capacity = (elements = this.elements).length) - s < len) |
309 |
< |
grow(len - (capacity - s)); |
308 |
> |
while ((capacity = (elements = this.elements).length) - s < newcomers) |
309 |
> |
grow(newcomers - (capacity - s)); |
310 |
|
int i = add(head, s, capacity); |
311 |
|
for (Object x : a) { |
312 |
|
Objects.requireNonNull(x); |
842 |
|
* operator to that element, as specified by {@link List#replaceAll}. |
843 |
|
* |
844 |
|
* @param operator the operator to apply to each element |
848 |
– |
* @since 9 |
845 |
|
*/ |
846 |
< |
public void replaceAll(UnaryOperator<E> operator) { |
846 |
> |
/* TODO: public */ private void replaceAll(UnaryOperator<E> operator) { |
847 |
|
Objects.requireNonNull(operator); |
848 |
|
final Object[] elements = this.elements; |
849 |
|
final int capacity = elements.length; |
898 |
|
} |
899 |
|
return deleted > 0; |
900 |
|
} catch (Throwable ex) { |
901 |
< |
for (; remaining > 0; |
902 |
< |
remaining--, i = inc(i, capacity), j = inc(j, capacity)) |
903 |
< |
elements[j] = elements[i]; |
901 |
> |
if (deleted > 0) |
902 |
> |
for (; remaining > 0; |
903 |
> |
remaining--, i = inc(i, capacity), j = inc(j, capacity)) |
904 |
> |
elements[j] = elements[i]; |
905 |
|
throw ex; |
906 |
|
} finally { |
907 |
|
size -= deleted; |