Skip to content

Commit c55b013

Browse files
committed
Fix stream methods for null arr index
1 parent 5c9522f commit c55b013

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/Lists/ArrayListCustom.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public <R> ArrayListCustom<R> map(Function<T, R> o) {
172172

173173
public T findFirst(Predicate<T> o) {
174174
Objects.requireNonNull(o);
175-
for (Object item : this.arr) {
175+
for (Object item : this.toArray()) {
176176
T t = (T) item;
177177
if (o.test(t)) return t;
178178
}
@@ -181,7 +181,7 @@ public T findFirst(Predicate<T> o) {
181181

182182
public boolean allMatch(Predicate<T> o) {
183183
Objects.requireNonNull(o);
184-
for (Object item : this.arr) {
184+
for (Object item : this.toArray()) {
185185
T t = (T) item;
186186
if (!o.test(t)) return false;
187187
}
@@ -190,7 +190,7 @@ public boolean allMatch(Predicate<T> o) {
190190

191191
public boolean anyMatch(Predicate<T> o) {
192192
Objects.requireNonNull(o);
193-
for (Object item : this.arr) {
193+
for (Object item : this.toArray()) {
194194
T t = (T) item;
195195
if (o.test(t)) return true;
196196
}
@@ -200,7 +200,7 @@ public boolean anyMatch(Predicate<T> o) {
200200
public int findFirstIndex(Predicate<T> o) {
201201
Objects.requireNonNull(o);
202202
int i = 0;
203-
for (Object item : this.arr) {
203+
for (Object item : this.toArray()) {
204204
T t = (T) item;
205205
if (o.test(t)) return i;
206206
i++;
@@ -216,7 +216,7 @@ public T max(Comparator<? super T> comparator) {
216216
Objects.requireNonNull(comparator);
217217
if (arr.length == 0) return null;
218218
T maxValue = (T) arr[0];
219-
for (Object val : arr) {
219+
for (Object val : toArray()) {
220220
T item = (T) val;
221221
int compareValue = comparator.compare(item, maxValue);
222222
if (compareValue > 0) maxValue = item;
@@ -228,7 +228,7 @@ public T min(Comparator<? super T> comparator) {
228228
Objects.requireNonNull(comparator);
229229
if (arr.length == 0) return null;
230230
T minValue = (T) arr[0];
231-
for (Object val : arr) {
231+
for (Object val : toArray()) {
232232
T item = (T) val;
233233
int compareValue = comparator.compare(item, minValue);
234234
if (compareValue < 0) minValue = item;
@@ -238,7 +238,7 @@ public T min(Comparator<? super T> comparator) {
238238

239239
public boolean noneMatch(Predicate<T> p) {
240240
Objects.requireNonNull(p);
241-
for (Object val : arr) {
241+
for (Object val : toArray()) {
242242
T item = (T) val;
243243
if (p.test(item)) return false;
244244
}

0 commit comments

Comments
 (0)