thredds.inventory.MFileIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cdm Show documentation
Show all versions of cdm Show documentation
The NetCDF-Java Library is a Java interface to NetCDF files,
as well as to many other types of scientific data formats.
The newest version!
package thredds.inventory;
import ucar.nc2.util.CloseableIterator;
import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* An iterator over MFiles, closeable so its a target for try-with-resource
*
* @author caron
* @since 11/20/13
*/
public class MFileIterator implements CloseableIterator {
private Iterator iter;
private MFileFilter filter;
private MFile nextMfile;
/**
* Constructor
* @param iter iterator over MFiles
* @param filter optional filter, may be null
*/
public MFileIterator(Iterator iter, MFileFilter filter) {
this.iter = iter;
this.filter = filter;
}
public void close() throws IOException {
}
public boolean hasNext() {
while (true) {
if (!iter.hasNext()) {
nextMfile = null;
return false;
}
nextMfile = iter.next();
if (filter == null || filter.accept(nextMfile)) return true;
}
}
public MFile next() {
if (nextMfile == null) throw new NoSuchElementException();
return nextMfile;
}
public void remove() {
throw new UnsupportedOperationException();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy