Подскажите че за ебала? Все работает, но валидатор таймаутит
package com.javarush.task.task37.task3701;
import java.lang.reflect.Field;
import java.util.*;
import java.util.function.Consumer;
/*
Круговой итератор
*/
public class Solution<T> extends ArrayList<T> {
@Override
public Iterator<T> iterator() {
return new RoundIterator();
}
public static void main(String[] args) {
Solution<Integer> list = new Solution<>();
list.add(1);
list.add(2);
list.add(3);
int count = 0;
for (Integer i : list) {
//1 2 3 1 2 3 1 2 3 1
System.out.print(i + " ");
count++;
if (count == 10) {
break;
}
}
}
public class RoundIterator implements Iterator<T> {
int cursor; // index of next element to return
int lastRet = -1; // index of last element returned; -1 if no such
int expectedModCount = modCount;
@Override
public boolean hasNext() {
return size() > 0;
}
@Override
public T next() {
checkForComodification();
int i = cursor;
if (i >= size())
i = 0;
Object[] elementData = toArray();
if (i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i + 1;
return (T) elementData[lastRet = i];
}
private void checkForComodification() {
if (modCount != expectedModCount)
throw new ConcurrentModificationException();
}
@Override
public void remove() {
Iterator.super.remove();
}
@Override
public void forEachRemaining(Consumer<? super T> action) {
Objects.requireNonNull(action);
final int size = toArray().length;
int i = cursor;
if (i >= size) {
return;
}
final Object[] elementData = toArray();
if (i >= elementData.length) {
throw new ConcurrentModificationException();
}
while (i != size && modCount == expectedModCount) {
action.accept((T) elementData[i++]);
}
// update once at end of iteration to reduce heap write traffic
cursor = i;
lastRet = i - 1;
checkForComodification();
}
}
}