Distance { public SortedSet<DistancePathResult> sortPaths(List<Path> paths) { SortedSet<DistancePathResult> result = new TreeSet<DistancePathResult>(); for (int i = 0; i <= paths.size()-1; ++i) { double d = getPathDistance(paths.get(i)); result.add(new DistancePathResult(paths.get(i), d)); } return result; }  @Procedure @Description("apoc.spatial.sortPathsByDistance(List<Path>) sort the given paths based on the geo informations (lat/long) in ascending order") Stream<DistancePathResult> sortByDistance(@Name("paths")List<Path> paths); SortedSet<DistancePathResult> sortPaths(List<Path> paths); double getPathDistance(Path path); double getDistance(double lat1, double lon1, double lat2, double lon2); @Context
    public GraphDatabaseService db; }
@Test public void testSortingPathsOnDistance() { Distance distanceProc = new Distance(); distanceProc.db = db; createPoints(); int i = 0; try (Transaction tx = db.beginTx()) { List<Path> paths = new ArrayList<>(); Result result = tx.execute("MATCH (a:Point {name:'bruges'}), (b:Point {name:'dresden'}) " + "MATCH p=(a)-[*]->(b) RETURN p"); while (result.hasNext()) { Map<String, Object> record = result.next(); ++i; paths.add((Path) record.get("p")); } int z = 0; SortedSet<DistancePathResult> sorted = distanceProc.sortPaths(paths); double lastDistance = 0.0; for (DistancePathResult distancePathResult : sorted) { ++z; assertTrue(distancePathResult.distance > lastDistance); lastDistance = distancePathResult.distance; } assertEquals(3, z); tx.commit(); } assertEquals(3, i); }