MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / addAll

Method addAll

vm/JavaAPI/src/java/util/ArrayList.java:185–232  ·  view source on GitHub ↗

Inserts the objects in the specified collection at the specified location in this List. The objects are added in the order they are returned from the collection's iterator. @param location the index at which to insert. @param collection the collection of objects. @return {@cod

(int location, Collection<? extends E> collection)

Source from the content-addressed store, hash-verified

183 * when {@code location < 0 || > size()}
184 */
185 @Override
186 public boolean addAll(int location, Collection<? extends E> collection) {
187 if (location < 0 || location > size) {
188 throw new IndexOutOfBoundsException("Index out of bounds");
189 }
190
191 Object[] dumparray = toObjectArray(collection);
192 int growSize = dumparray.length;
193 // REVIEW: Why do this check here rather than check
194 // collection.size() earlier? RI behaviour?
195 if (growSize == 0) {
196 return false;
197 }
198
199 if (location == 0) {
200 growAtFront(growSize);
201 firstIndex -= growSize;
202 } else if (location == size) {
203 if (firstIndex + size > array.length - growSize) {
204 growAtEnd(growSize);
205 }
206 } else { // must be case: (0 < location && location < size)
207 if (array.length - size < growSize) {
208 growForInsert(location, growSize);
209 } else if (firstIndex + size > array.length - growSize
210 || (firstIndex > 0 && location < size / 2)) {
211 int newFirst = firstIndex - growSize;
212 if (newFirst < 0) {
213 int index = location + firstIndex;
214 System.arraycopy(array, index, array, index - newFirst,
215 size - location);
216 newFirst = 0;
217 }
218 System.arraycopy(array, firstIndex, array, newFirst, location);
219 firstIndex = newFirst;
220 } else {
221 int index = location + firstIndex;
222 System.arraycopy(array, index, array, index + growSize, size
223 - location);
224 }
225 }
226
227 System.arraycopy(dumparray, 0, this.array, location + firstIndex,
228 growSize);
229 size += growSize;
230 modCount++;
231 return true;
232 }
233
234 /**
235 * Adds the objects in the specified collection to this {@code ArrayList}.

Callers 15

paintMethod · 0.95
featuresMethod · 0.95
getTabIteratorMethod · 0.95
getChildrenAsListMethod · 0.95
asListMethod · 0.95
createListMethod · 0.95
getBackgroundTypesMethod · 0.95
drawSeriesMethod · 0.95
removeErrorListenerMethod · 0.95
discoverMethod · 0.95
writeRootClassIndexMethod · 0.95

Calls 5

toObjectArrayMethod · 0.95
growAtFrontMethod · 0.95
growAtEndMethod · 0.95
growForInsertMethod · 0.95
arraycopyMethod · 0.95

Tested by 15

failAsyncMethod · 0.76
flushMethod · 0.76
flushMethod · 0.76
compileMethod · 0.76
compileAndRunMethod · 0.76
compileJavaApiIntoMethod · 0.76
compileAgainstJavaApiMethod · 0.76