
package org.hapiserver.source.cdaweb;

import java.util.Iterator;
import org.hapiserver.HapiRecord;
import org.hapiserver.TimeString;

/**
 * convert AvailabilitySource iterator into a granule iterator
 * @author jbf
 */
public class AvailabilityIterator implements Iterator<TimeString[]> {

    private final Iterator<HapiRecord> it;
    private String file; // the current file

    public AvailabilityIterator( Iterator<HapiRecord> it ) {
        this.it= it;
    }
    
    @Override
    public boolean hasNext() {
        return it.hasNext();
    }

    @Override
    public TimeString[] next() {
        HapiRecord hr= it.next();
        String start= hr.getIsoTime(0);
        String stop= hr.getIsoTime(1);
        this.file= hr.getString(2);
        
        return new TimeString[] { new TimeString(start), new TimeString(stop) };
    }

    /**
     * return the file for the current interval.  This should be called after next().
     * @return the file associated with the time returned in next().
     */
    String getFile() {
        return this.file;
    }

    
}
