Skip to content

Commit 41980e7

Browse files
committed
ArrayList 범위 버그 수정
1 parent 87c6795 commit 41980e7

File tree

1 file changed

+7
-7
lines changed
  • data-structure/src/main/java/io/github/gunkim/datastructure/list

1 file changed

+7
-7
lines changed

data-structure/src/main/java/io/github/gunkim/datastructure/list/ArrayList.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public boolean addAll(int index, Collection<? extends T> collection) {
4949
expandArrayIfFull(requiredSize * DEFAULT_ARRAY_EXPANSION_FACTOR);
5050
}
5151

52-
System.arraycopy(array, index, array, index + collection.size(), collection.size());
52+
System.arraycopy(array, index, array, index + collection.size(), size - index);
5353
size += collection.size();
5454

5555
var i = index;
@@ -120,7 +120,7 @@ public T set(int index, T element) {
120120

121121
@Override
122122
public int indexOf(Object o) {
123-
for (int i = 0; i < array.length; i++) {
123+
for (int i = 0; i < size; i++) {
124124
var element = array[i];
125125

126126
if (element.equals(o)) {
@@ -132,7 +132,7 @@ public int indexOf(Object o) {
132132

133133
@Override
134134
public int lastIndexOf(Object o) {
135-
for (int i = array.length - 1; i >= 0; i--) {
135+
for (int i = size - 1; i >= 0; i--) {
136136
var element = array[i];
137137

138138
if (element.equals(o)) {
@@ -198,22 +198,22 @@ public String toString() {
198198

199199
@Override
200200
public ListIterator listIterator() {
201-
throw new RuntimeException("Not implemented");
201+
throw new UnsupportedOperationException("Not implemented");
202202
}
203203

204204
@Override
205205
public ListIterator listIterator(int index) {
206-
throw new RuntimeException("Not implemented");
206+
throw new UnsupportedOperationException("Not implemented");
207207
}
208208

209209
@Override
210210
public List<T> subList(int fromIndex, int toIndex) {
211-
throw new RuntimeException("Not implemented");
211+
throw new UnsupportedOperationException("Not implemented");
212212
}
213213

214214
@Override
215215
public boolean retainAll(Collection c) {
216-
throw new RuntimeException("Not implemented");
216+
throw new UnsupportedOperationException("Not implemented");
217217
}
218218

219219
private void addData(T data) {

0 commit comments

Comments
 (0)