org.gridkit.jvmtool.event.SingleEventReader Maven / Gradle / Ivy
package org.gridkit.jvmtool.event;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class SingleEventReader implements EventReader {
private final T event;
private boolean done;
public SingleEventReader(T event) {
this.event = event;
}
@Override
public EventReader morph(EventMorpher morpher) {
return MorphingEventReader.morph(this, morpher);
}
@Override
public Iterator iterator() {
return this;
}
@Override
public boolean hasNext() {
return !done;
}
@Override
public T next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
done = true;
return event;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
@Override
public T peekNext() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return event;
}
@Override
public void dispose() {
// do nothing
}
}