218 modCount++;
219 grow(minCapacity);
220 }
221 }
222
223 /**
224 * Increases the capacity to ensure that it can hold at least the
225 * number of elements specified by the minimum capacity argument.
226 *
227 * @param minCapacity the desired minimum capacity
228 * @throws OutOfMemoryError if minCapacity is less than zero
229 */
230 private Object[] grow(int minCapacity) {
231 int oldCapacity = elementData.length;
232 if (oldCapacity > 0 || elementData != DEFAULTCAPACITY_EMPTY_ELEMENTDATA) {
233 int newCapacity = ArraysSupport.newLength(oldCapacity,
234 minCapacity - oldCapacity, /* minimum growth */
235 oldCapacity >> 1 /* preferred growth */);
236 return elementData = Arrays.copyOf(elementData, newCapacity);
237 } else {
238 return elementData = new Object[Math.max(DEFAULT_CAPACITY, minCapacity)];
239 }
240 }
241
242 private Object[] grow() {
243 return grow(size + 1);
244 }
245
246 /**
247 * Returns the number of elements in this list.
248 *
249 * @return the number of elements in this list
250 */
251 public int size() {
252 return size;
253 }
254
255 /**
256 * Returns {@code true} if this list contains no elements.
257 *
258 * @return {@code true} if this list contains no elements
259 */
|
218 modCount++;
219 grow(minCapacity);
220 }
221 }
222
223 /**
224 * Increases the capacity to ensure that it can hold at least the
225 * number of elements specified by the minimum capacity argument.
226 *
227 * @param minCapacity the desired minimum capacity
228 * @throws OutOfMemoryError if minCapacity is less than zero
229 */
230 private Object[] grow(int minCapacity) {
231 int oldCapacity = elementData.length;
232 if (oldCapacity > 0 || elementData != DEFAULTCAPACITY_EMPTY_ELEMENTDATA) {
233 int newCapacity = ArraysSupport.newLength(oldCapacity,
234 minCapacity - oldCapacity, /* minimum growth */
235 oldCapacity >> 1 /* preferred growth */);
236 return elementData = Arrays.copyOf(elementData, newCapacity);
237 } else {
238 if (DEFAULT_CAPACITY > minCapacity) {
239 return elementData = new Object[DEFAULT_CAPACITY];
240 }
241 return elementData = new Object[minCapacity];
242 }
243 }
244
245 private Object[] grow() {
246 return grow(size + 1);
247 }
248
249 /**
250 * Returns the number of elements in this list.
251 *
252 * @return the number of elements in this list
253 */
254 public int size() {
255 return size;
256 }
257
258 /**
259 * Returns {@code true} if this list contains no elements.
260 *
261 * @return {@code true} if this list contains no elements
262 */
|