#13 EventStream should extend Iterator<Event>

open
nobody
None
5
2011-01-22
2011-01-22
Steven Bethard
No

Conceptually, EventStream is just an Iterator<Event>. You would get better interoperability with other Java libraries if EventStream were declared as such. If you didn't care about backwards compatibility, I'd say just get rid of EventStream entirely and use Iterator<Event> everywhere instead.

If you care about backwards compatibility, you could at least declare AbstractEventStream as implementing Iterator<Event> - it declares all of hasNext(), next() and remove(). I believe that shouldn't break anything, and should make all the current EventStream implementations into Iterator<Event>s.

Why do I want this? Because, when using OpenNLP maxent from Scala, if a RealValueFileEventStream were an Iterator<Event>, I could write:

for (event <- stream) {
...
}

But since it's not, I instead have to write:

val events = new Iterator[Event] {
def hasNext = stream.hasNext
def next = stream.next
}
for (event <- events) {
..
}

Discussion

  • Joern Kottmann
    Joern Kottmann
    2011-01-24

    The project moved to incubator.apache.org/opennlp please come over to our new bugtracker and mailing lists to discuss this.

    Jörn