monniasza.collects.Iterator2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
package monniasza.collects;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.google.common.collect.Iterators;
/**
* @author oskar
* An iterator which iterates over all of its collections
* @param type of iterator
*/
public class Iterator2 implements Iterator {
public static Iterator2 iterIterCol(Iterator extends Collection extends U>> ic) {
return iterIterIter(Iterators.transform(ic, Collection::iterator));
}
public static Iterator2 iterIterIter(Iterator extends Iterator extends U>> ii) {
return new Iterator2<>(ii);
}
public static Iterator2 iterColCol(Collection extends Collection extends U>> cc) {
return iterIterCol(cc.iterator());
}
public static Iterator2 iterColIter(Collection extends Iterator extends U>> ci) {
return iterIterIter(ci.iterator());
}
private Iterator2(Iterator extends Iterator extends T>> iter) {
this.iter = iter;
}
private final Iterator extends Iterator extends T>> iter;
private Iterator extends T> subiter;
private boolean state;
@Override
public void remove() {
if(!state) throw new IllegalStateException("Item not selected");
if(subiter.hasNext()) subiter.remove();
if(iter.hasNext()) {
subiter = iter.next();
remove();
}
state = false;
}
@Override
public boolean hasNext() {
if(subiter.hasNext()) return true;
if(iter.hasNext()) {
subiter = iter.next();
return hasNext();
}
return false;
}
@Override
public T next() {
state = true;
if(subiter.hasNext()) subiter.next();
if(iter.hasNext()) {
subiter = iter.next();
return next();
}
state = false;
throw new NoSuchElementException("No more iterators");
}}