122 |
|
/** |
123 |
|
* Constructs a list containing the elements of the specified |
124 |
|
* collection, in the order they are returned by the collection's |
125 |
< |
* iterator. The <tt>ArrayList</tt> instance has an initial capacity of |
126 |
< |
* 110% the size of the specified collection. |
125 |
> |
* iterator. |
126 |
|
* |
127 |
|
* @param c the collection whose elements are to be placed into this list |
128 |
|
* @throws NullPointerException if the specified collection is null |
129 |
|
*/ |
130 |
|
public ArrayList(Collection<? extends E> c) { |
132 |
– |
int size = c.size(); |
133 |
– |
// 10% for growth |
134 |
– |
int cap = ((size/10)+1)*11; |
135 |
– |
if (cap > 0) { |
136 |
– |
Object[] a = new Object[cap]; |
137 |
– |
a[size] = a[size+1] = UNALLOCATED; |
138 |
– |
Object[] b = c.toArray(a); |
139 |
– |
if (b[size] == null && b[size+1] == UNALLOCATED) { |
140 |
– |
b[size+1] = null; |
141 |
– |
elementData = b; |
142 |
– |
this.size = size; |
143 |
– |
return; |
144 |
– |
} |
145 |
– |
} |
146 |
– |
initFromConcurrentlyMutating(c); |
147 |
– |
} |
148 |
– |
|
149 |
– |
private void initFromConcurrentlyMutating(Collection<? extends E> c) { |
131 |
|
elementData = c.toArray(); |
132 |
|
size = elementData.length; |
133 |
|
// c.toArray might (incorrectly) not return Object[] (see 6260652) |
135 |
|
elementData = Arrays.copyOf(elementData, size, Object[].class); |
136 |
|
} |
137 |
|
|
157 |
– |
private final static Object UNALLOCATED = new Object(); |
158 |
– |
|
138 |
|
/** |
139 |
|
* Trims the capacity of this <tt>ArrayList</tt> instance to be the |
140 |
|
* list's current size. An application can use this operation to minimize |