com.onthegomap.planetiler.util.CloseableIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of planetiler-core Show documentation
Show all versions of planetiler-core Show documentation
Planetiler is tool to build planet-scale vector tilesets from OpenStreetMap data fast.
The newest version!
package com.onthegomap.planetiler.util;
import java.io.Closeable;
import java.util.Iterator;
import java.util.Spliterators;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public interface CloseableIterator extends Closeable, Iterator {
static CloseableIterator of(Stream stream) {
return new CloseableIterator<>() {
private final Iterator iter = stream.iterator();
@Override
public boolean hasNext() {
return iter.hasNext();
}
@Override
public T next() {
return iter.next();
}
@Override
public void close() {
stream.close();
}
};
}
@Override
void close();
default Stream stream() {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, 0), false).onClose(this::close);
}
default CloseableIterator map(Function mapper) {
var parent = this;
return new CloseableIterator<>() {
@Override
public void close() {
parent.close();
}
@Override
public boolean hasNext() {
return parent.hasNext();
}
@Override
public O next() {
return mapper.apply(parent.next());
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy