org.gridkit.jvmtool.event.SingleEventReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sjk-stacktrace Show documentation
Show all versions of sjk-stacktrace Show documentation
Thread dumps: capture and encoding
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
}
}