RoadPath extends GraphPath<RoadPath, RoadSegment, RoadConnection> { @Pure public CrossRoad getFirstJunctionPoint() { RoadConnection point = getFirstPoint(); double distance = 0; RoadSegment beforeSegment = null; RoadSegment afterSegment = null; int beforeSegmentIndex = -1; int afterSegmentIndex = -1; boolean found = false; if (point != null) { int index = 0; for (final RoadSegment sgmt : this) { if (found) { afterSegment = sgmt; afterSegmentIndex = index; break; } point = sgmt.getOtherSidePoint(point); beforeSegment = sgmt; beforeSegmentIndex = index; distance += sgmt.getLength(); final int count = point.getConnectedSegmentCount(); if (count != 2) { found = true; } ++index; } } if (found) { return new CrossRoad(point, beforeSegment, beforeSegmentIndex, afterSegment, afterSegmentIndex, distance, distance); } return null; } protected  RoadPath(List<RoadSegment> original);  RoadPath();  RoadPath(RoadSegment segment);  RoadPath(RoadSegment segment, RoadConnection starting_point);  RoadPath(RoadPath path); static boolean addPathToPath(RoadPath inside, RoadPath elements); static RoadPath of(List<RoadSegment> original); @Override @Pure Object[] toArray(); @Pure Direction1D getSegmentDirectionAt(int index); @Pure boolean isConnectableTo(RoadPath path); @Pure RoadSegment getConnectableSegmentToFirstPoint(RoadPath path); @Pure RoadSegment getConnectableSegmentToLastPoint(RoadPath path); @Pure boolean isFirstPointConnectableTo(RoadPath path); @Pure boolean isLastPointConnectableTo(RoadPath path); @Pure boolean isCulDeSacWay(); @Pure RoadConnection getFirstCrossRoad(); @Pure CrossRoad getFirstJunctionPoint(); @Pure Iterator<CrossRoad> crossRoads();  }
@Test public void testGetFirstJunctionPoint() { RoadPath path = new RoadPath(); path.add(this.segment3, this.segment3.getBeginPoint()); path.add(this.segment4); path.add(this.segment1); path.add(this.segment2); path.add(this.segment6, this.segment6.getEndPoint()); path.add(this.segment8); CrossRoad cross = path.getFirstJunctionPoint(); double distance = this.segment3.getLength() +this.segment4.getLength() +this.segment1.getLength() +this.segment2.getLength(); assertEquals(this.segment2.getBeginPoint(), cross.connectionPoint); assertEpsilonEquals(distance, cross.distance); assertEpsilonEquals(distance, cross.distanceFromPreviousCrossRoad); assertSame(this.segment2, cross.enteringSegment); assertSame(this.segment6, cross.exitingSegment); }