Skip to content

Commit 657d038

Browse files
t-oberckittlsebastian-peter
authored
To/#529 get nearest coordinates (#530)
* look through all coordinates * adjust changelog * adapt documentation Co-authored-by: Thomas <[email protected]> Co-authored-by: Chris Kittl <[email protected]> Co-authored-by: Sebastian Peter <[email protected]>
1 parent 8707ef1 commit 657d038

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/edu/ie3/datamodel/io/source/IdCoordinateSource.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,24 @@ public interface IdCoordinateSource extends DataSource {
5757
* @return the n nearest coordinates to the given point
5858
*/
5959
default List<CoordinateDistance> getNearestCoordinates(Point coordinate, int n) {
60-
return getNearestCoordinates(coordinate, n, Collections.emptySet());
60+
return getNearestCoordinates(coordinate, n, getAllCoordinates());
6161
}
6262

6363
/**
6464
* Returns the nearest n coordinate points to the given coordinate from a given collection of
65-
* points
65+
* points. If the set is empty or null we look through all coordinates.
6666
*
6767
* @param coordinate the coordinate to look up the nearest neighbours for
6868
* @param n how many neighbours to look up
69-
* @param allCoordinates the collection of points, ideally containing all available coordinates
69+
* @param coordinates the collection of points
7070
* @return the n nearest coordinates to the given point
7171
*/
7272
default List<CoordinateDistance> getNearestCoordinates(
73-
Point coordinate, int n, Collection<Point> allCoordinates) {
73+
Point coordinate, int n, Collection<Point> coordinates) {
7474
SortedSet<CoordinateDistance> sortedDistances =
7575
GeoUtils.getCoordinateDistances(
7676
coordinate,
77-
(allCoordinates == null || allCoordinates.isEmpty())
78-
? getAllCoordinates()
79-
: allCoordinates);
77+
(coordinates != null && !coordinates.isEmpty()) ? coordinates : getAllCoordinates());
8078
return sortedDistances.stream().limit(n).toList();
8179
}
8280
}

0 commit comments

Comments
 (0)