diff --git a/CHANGELOG.md b/CHANGELOG.md index 88e5211e1..6b0532f05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,10 @@ Changelog ## 0.8.0-SNAPSHOT (current master) * fix a bug where contribution-based filters are not applied when used in an and/or operation. ([#409]) +* fix a regression in `0.7.0` which prevents queries from being executed on an ignite cluster backend ([#417]) [#409]: https://github.com/GIScience/oshdb/issues/409 +[#417]: https://github.com/GIScience/oshdb/pull/417 ## 0.7.0 diff --git a/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBBoundingBox.java b/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBBoundingBox.java index 1c2cee7f7..2811f8803 100644 --- a/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBBoundingBox.java +++ b/oshdb/src/main/java/org/heigit/ohsome/oshdb/OSHDBBoundingBox.java @@ -25,7 +25,7 @@ public class OSHDBBoundingBox implements OSHDBBoundable, Serializable { /** * Creates an {@code OSHDBBoundingBox} instance from scaled coordinates. - * + * *

This method is mainly for internal usage.
* OSM stores coordinates with a fixed precision of * 7 decimal diff --git a/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/XYGridTree.java b/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/XYGridTree.java index bed0bcc22..394d6454a 100644 --- a/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/XYGridTree.java +++ b/oshdb/src/main/java/org/heigit/ohsome/oshdb/index/XYGridTree.java @@ -44,8 +44,12 @@ public XYGridTree() { * @param latitude Latitude for the given point * @return An iterator over the cellIds in all zoomlevel */ + @SuppressWarnings({"Convert2Lambda", "java:S1604"}) public Iterable getIds(long longitude, long latitude) { - return () -> new Iterator<>() { + return new Iterable<>() { + @Override + public Iterator iterator() { + return new Iterator<>() { private int level = -1; @Override @@ -62,6 +66,8 @@ public CellId next() { return new CellId(gridMap.get(level).getLevel(), gridMap.get(level).getId(longitude, latitude)); } + }; + } }; } @@ -110,51 +116,84 @@ public Iterable bbox2CellIds(final OSHDBBoundingBox bbox) { * @param enlarge {@code true} if the query should include enlarged bboxes */ public Iterable bbox2CellIds(final OSHDBBoundingBox bbox, final boolean enlarge) { - return () -> new Iterator<>() { - private int level = 0; - private Iterator rows = - gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator(); - private IdRange row = rows.next(); - private long maxId = row.getEnd(); - private long currId = row.getStart() - 1; + return new CellIdIterable(gridMap, bbox, enlarge, maxLevel); + } - @Override - public boolean hasNext() { - if (level < maxLevel) { - return true; - } - if (rows.hasNext()) { - return true; - } - return currId < maxId; - } + private static class CellIdIterable implements Iterable, Serializable { + private final Map gridMap; + private final OSHDBBoundingBox bbox; + private final boolean enlarge; + private final int maxLevel; - @Override - public CellId next() { - if (currId < maxId) { - currId++; - return new CellId(level, currId); - } - if (rows.hasNext()) { - row = rows.next(); - currId = row.getStart(); - maxId = row.getEnd(); - return new CellId(level, currId); - } - level++; - rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator(); - row = rows.next(); - currId = row.getStart(); - maxId = row.getEnd(); - return new CellId(level, currId); - } - }; - } + private CellIdIterable(Map gridMap, OSHDBBoundingBox bbox, boolean enlarge, + int maxLevel) { + this.gridMap = gridMap; + this.bbox = bbox; + this.enlarge = enlarge; + this.maxLevel = maxLevel; + } - public static class CellIdRange implements Serializable { + @Override + public Iterator iterator() { + return new CellIdIterator(); + } + + @SuppressWarnings("SE_INNER_CLASS") + private class CellIdIterator implements Iterator { + private Iterator rows; + private int level; + private IdRange row; + private long maxId; + private long currId; - private static final long serialVersionUID = -8704075537597232890L; + private CellIdIterator() { + this.level = 0; + this.rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator(); + this.row = rows.next(); + this.maxId = row.getEnd(); + this.currId = row.getStart() - 1; + } + + @Override + public boolean hasNext() { + if (level < maxLevel) { + return true; + } + if (rows.hasNext()) { + return true; + } + return currId < maxId; + } + + @Override + public CellId next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + + if (currId < maxId) { + currId++; + return new CellId(level, currId); + } + + if (rows.hasNext()) { + row = rows.next(); + currId = row.getStart(); + maxId = row.getEnd(); + return new CellId(level, currId); + } + level++; + rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator(); + row = rows.next(); + currId = row.getStart(); + maxId = row.getEnd(); + return new CellId(level, currId); + } + } + } + + public static class CellIdRange implements Serializable { private final CellId start; private final CellId end; @@ -203,9 +242,13 @@ public boolean equals(Object obj) { * @param enlarge {@code true} to include enlarged bboxes * @return List of {@code CellIdRanges} which are covered by the given bbox */ + @SuppressWarnings({"Convert2Lambda", "java:S1604"}) public Iterable bbox2CellIdRanges(final OSHDBBoundingBox bbox, final boolean enlarge) { - return () -> new Iterator<>() { + return new Iterable<>() { + @Override + public Iterator iterator() { + return new Iterator<>() { private int level = 0; private Iterator rows = gridMap.get(level).bbox2CellIdRanges(bbox, enlarge).iterator(); @@ -225,6 +268,8 @@ public CellIdRange next() { return CellIdRange.of(new CellId(level, row.getStart()), new CellId(level, row.getEnd())); } + }; + } }; }