package io.citrine.jpif.io;

import io.citrine.jpif.obj.system.System;

import java.io.IOException;
import java.util.Iterator;

/**
 * Iterator class for iterating over systems.
 *
 * @author Kyle Michel
 */
public class SystemIterator implements Iterator<System> {

    @Override
    public boolean hasNext() {
        if (this.nextSystem == null) {
            try {
                this.nextSystem = this.pifObjectStream.getNextSystem();
            }
            catch (IOException e) {
                return false;
            }
        }
        return this.nextSystem != null;
    }

    @Override
    public System next() {
        if (this.nextSystem != null) {
            System res = this.nextSystem;
            this.nextSystem = null;
            return res;
        }
        else {
            try {
                return this.pifObjectStream.getNextSystem();
            }
            catch (IOException e) {
                return null;
            }
        }
    }

    /**
     * Constructor.
     *
     * @param pifObjectStream {@link PifObjectStream} being read from.
     */
    public SystemIterator(final PifObjectStream pifObjectStream) {
        this.pifObjectStream = pifObjectStream;
    }

    /** Object stream to read from. */
    private final PifObjectStream pifObjectStream;

    /** Next system in the stream. */
    private System nextSystem;
}
@@ -260,16 +260,248 @@
 tem%3E %7B%0A%0A
+    /**%0A     * Return whether there is another item to iterate over.%0A     *%0A     * @return True if another item can be obtained.%0A     * @throws RuntimeException if an %7B@link IOException%7D is thrown from within this function.%0A     */%0A
     @Ove
@@ -498,32 +498,32 @@
 /%0A    @Override%0A
-
     public boole
@@ -736,20 +736,37 @@
     
-return false
+throw new RuntimeException(e)
 ;%0A  
@@ -830,24 +830,208 @@
 ull;%0A    %7D%0A%0A
+    /**%0A     * Get the next object.%0A     *%0A     * @return %7B@link System%7D object.%0A     * @throws RuntimeException if an %7B@link IOException%7D is thrown from within this function.%0A     */%0A
     @Overrid
@@ -1374,19 +1374,37 @@
     
-return null
+throw new RuntimeException(e)
 ;%0A  

throw runtime exception from system iterator