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

Method add

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

Inserts the specified object into this ArrayList at the specified location. The object is inserted before any previous element at the specified location. If the location is equal to the size of this ArrayList, the object is added at the end. @param location the index at w

(int location, E object)

Source from the content-addressed store, hash-verified

117 * when {@code location < 0 || > size()}
118 */
119 @Override
120 public void add(int location, E object) {
121 if (location < 0 || location > size) {
122 throw new IndexOutOfBoundsException("Index out of bounds");
123 }
124 if (location == 0) {
125 if (firstIndex == 0) {
126 growAtFront(1);
127 }
128 array[--firstIndex] = object;
129 } else if (location == size) {
130 if (firstIndex + size == array.length) {
131 growAtEnd(1);
132 }
133 array[firstIndex + size] = object;
134 } else { // must be case: (0 < location && location < size)
135 if (size == array.length) {
136 growForInsert(location, 1);
137 } else if (firstIndex + size == array.length
138 || (firstIndex > 0 && location < size / 2)) {
139 System.arraycopy(array, firstIndex, array, --firstIndex,
140 location);
141 } else {
142 int index = location + firstIndex;
143 System.arraycopy(array, index, array, index + 1, size
144 - location);
145 }
146 array[location + firstIndex] = object;
147 }
148
149 size++;
150 modCount++;
151 }
152
153 /**
154 * Adds the specified object at the end of this {@code ArrayList}.

Callers 15

TranscriptionResultMethod · 0.95
textOnlyMethod · 0.95
extractFramesMethod · 0.95
getStickyHeadersMethod · 0.95
decodeMethod · 0.95
decodeLayerMethod · 0.95
decodeGeometryMethod · 0.95
extractLabelsMethod · 0.95
placeLayerMethod · 0.95
ringGeometryMethod · 0.95
pointGeometryMethod · 0.95
setProviderOrderMethod · 0.95

Calls 4

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

Tested by 15

mainMethod · 0.76
mainMethod · 0.76
mainMethod · 0.76
loadHistoryMethod · 0.76
pushHistoryMethod · 0.76
summarizeMethod · 0.76
runMavenCompileMethod · 0.76
findJavaHomeForMajorMethod · 0.76
differenceMethod · 0.76
handMethod · 0.76
flushMethod · 0.76
getAvailableCompilersMethod · 0.76