private Segment createSegmentFromEdges(long edgeId, long segmentId, boolean isEdgeOrigin) { double length = 0.0; Segment seg = null; try { List<Edge> subset = null; seg = db.ReadSegment(segmentId); ArrayList<Edge> edges = db.ReadEdges(segmentId); Edge edge = null; if (!edges.isEmpty()) { if (isEdgeOrigin) { edge = edges .stream() .filter( (Edge e) -> { return e.mOrigin == edgeId; }) .findFirst() .get(); } else { edge = edges .stream() .filter( (Edge e) -> { return e.mDestination == edgeId; }) .findFirst() .get(); } int index = edges.indexOf(edge); subset = edges.subList(index, edges.size()); for (Edge ed : subset) { length = +ed.mLength; } } long origin, destination; origin = (isEdgeOrigin ? edgeId : seg.mOrigin); destination = (isEdgeOrigin ? seg.mDestination : edgeId); Segment s = new Segment(nextSegId++, length, seg.mWayId, origin, destination); return s; } catch (SQLException e) { System.err.println("Error getting segmentid from method modelNodeToSegment"); e.printStackTrace(); } return null; }
private ArrayList<FakeNode> getNeighbours(long id) { ArrayList<FakeNode> retNodes = new ArrayList<>(); ArrayList<Segment> neighbours = this.segments .stream() .filter( (Segment s) -> { return s.mOrigin == id; }) .collect(Collectors.toCollection(ArrayList<Segment>::new)); neighbours.addAll( this.fakeSegments .stream() .filter( (Segment s) -> { return s.mOrigin == id; }) .collect(Collectors.toCollection(ArrayList<Segment>::new))); FakeNode node; for (Segment s : neighbours) { if (fakeNodes.containsKey(s.mDestination)) { node = fakeNodes.get(s.mDestination); } else { node = new FakeNode(nodes.get(s.mDestination)); fakeNodes.put(s.mDestination, node); } ArrayList<CostFunction> functions = costs .stream() .filter( (CostFunction c) -> { return c.getSegmentId() == s.mId; }) .collect(Collectors.toCollection(ArrayList<CostFunction>::new)); functions.addAll( fakeCosts .stream() .filter( (CostFunction c) -> { return c.getSegmentId() == s.mId; }) .collect(Collectors.toCollection(ArrayList<CostFunction>::new))); node.node.cost = functions.get(0); retNodes.add(fakeNodes.get(s.mDestination)); } return retNodes; }