### Question:
InstructionList implements Iterable<Instruction> { public Instruction find( double lat, double lon, double maxDistance ) { if (getSize() == 0) { return null; } PointList points = get(0).getPoints(); double prevLat = points.getLatitude(0); double prevLon = points.getLongitude(0); DistanceCalc distCalc = Helper.DIST_EARTH; double foundMinDistance = distCalc.calcNormalizedDist(lat, lon, prevLat, prevLon); int foundInstruction = 0; if (getSize() > 1) { for (int instructionIndex = 0; instructionIndex < getSize(); instructionIndex++) { points = get(instructionIndex).getPoints(); for (int pointIndex = 0; pointIndex < points.size(); pointIndex++) { double currLat = points.getLatitude(pointIndex); double currLon = points.getLongitude(pointIndex); if (!(instructionIndex == 0 && pointIndex == 0)) { double distance; int index = instructionIndex; if (distCalc.validEdgeDistance(lat, lon, currLat, currLon, prevLat, prevLon)) { distance = distCalc.calcNormalizedEdgeDistance(lat, lon, currLat, currLon, prevLat, prevLon); if (pointIndex > 0) index++; } else { distance = distCalc.calcNormalizedDist(lat, lon, currLat, currLon); if (pointIndex > 0) index++; } if (distance < foundMinDistance) { foundMinDistance = distance; foundInstruction = index; } } prevLat = currLat; prevLon = currLon; } } } if (distCalc.calcDenormalizedDist(foundMinDistance) > maxDistance) return null; if (foundInstruction == getSize()) foundInstruction--; return get(foundInstruction); } private  InstructionList();  InstructionList( Translation tr );  InstructionList( int cap, Translation tr ); void replaceLast( Instruction instr ); void add( Instruction instr ); int getSize(); int size(); List<Map<String, Object>> createJson(); boolean isEmpty(); @Override Iterator<Instruction> iterator(); Instruction get( int index ); @Override String toString(); List<GPXEntry> createGPXList(); String createGPX(); String createGPX( String trackName, long startTimeMillis ); String createGPX( String trackName, long startTimeMillis, boolean includeElevation ); Instruction find( double lat, double lon, double maxDistance ); static final InstructionList EMPTY; }### Answer:
@Test public void testFind() { Graph g = new GraphBuilder(carManager).create(); NodeAccess na = g.getNodeAccess(); na.setNode(1, 15.0, 10); na.setNode(2, 15.1, 10); na.setNode(3, 15.1, 9.9); PointList waypoint = new PointList(); waypoint.add(15.2, 9.9); na.setNode(4, 15.2, 10); na.setNode(5, 15.2, 10.1); g.edge(1, 2, 10000, true).setName("1-2"); g.edge(2, 3, 10000, true).setName("2-3"); g.edge(3, 4, 10000, true).setName("3-4").setWayGeometry(waypoint); g.edge(4, 5, 10000, true).setName("4-5"); Path p = new Dijkstra(g, carEncoder, new ShortestWeighting(carEncoder), tMode).calcPath(1, 5); InstructionList wayList = p.calcInstructions(usTR); assertEquals("2-3", wayList.find(15.05, 10, 1000).getName()); assertEquals("2-3", wayList.find(15.05, 10.001, 1000).getName()); assertEquals("3-4", wayList.find(15.099, 9.9, 1000).getName()); assertEquals("4-5", wayList.find(15.21, 9.85, 100000).getName()); }