chore/fix: update iterator

This commit is contained in:
Pierre Maurice Schwang 2025-02-22 21:45:09 +01:00
parent 36de196d3d
commit 30867354cc
No known key found for this signature in database
GPG Key ID: 37E613079F3E5BB9

View File

@ -35,16 +35,19 @@ interface PlotProvider {
Stream<Plot> streamPlots();
default Stream<Plot> streamPlotsInPlotAreas(PlotArea[] areas) {
if (areas == null || areas.length == 0) {
return Stream.of();
}
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(new Iterator<>() {
private int areaIndex = -1;
private Iterator<Plot> currentAreaPlots;
@Override
public boolean hasNext() {
if (currentAreaPlots == null) {
return areas.length > 0;
}
if (!currentAreaPlots.hasNext()) {
return ++areaIndex < areas.length - 1;
if (currentAreaPlots == null || !currentAreaPlots.hasNext()) {
if (areaIndex >= areas.length) {
return false;
}
currentAreaPlots = areas[++areaIndex].getPlots().iterator();
}
return true;
}