edu.stanford.nlp.util.ConcatenationIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-parser Show documentation
Show all versions of stanford-parser Show documentation
Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.
The newest version!
package edu.stanford.nlp.util;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
/**
* Iterator that represents the concatenation of two other iterators.
*
* User: Dan Klein ([email protected])
* Date: Oct 22, 2003
* Time: 7:27:39 PM
*/
public class ConcatenationIterator implements Iterator {
Iterator first = null;
Iterator second = null;
Iterator current() {
if (first.hasNext()) {
return first;
}
return second;
}
public boolean hasNext() {
return current().hasNext();
}
public T next() {
return current().next();
}
public void remove() {
current().remove();
}
public ConcatenationIterator(Iterator first, Iterator second) {
this.first = first;
this.second = second;
}
public static void main(String[] args) {
Collection c1 = Collections.singleton("a");
Collection c2 = Collections.singleton("b");
Iterator i = new ConcatenationIterator<>(c1.iterator(), c2.iterator());
while (i.hasNext()) {
System.out.println(i.next() + " ");
}
}
}