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

Method addAll

Ports/CLDC11/src/java/util/ArrayList.java:181–228  ·  view source on GitHub ↗
(int location, Collection<? extends E> collection)

Source from the content-addressed store, hash-verified

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

Callers 5

getHeaderFieldsMethod · 0.95
loadThemesMethod · 0.95
mainMethod · 0.95
getHeaderFieldsMethod · 0.95
restartJVMMethod · 0.95

Calls 5

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

Tested by

no test coverage detected