code: private double penalizedPathDistance(Path path,
                                           Set<EdgeIteratorState> penalizedVirtualEdges) {
          double totalPenalty = 0;
  
          // Unfavored edges in the middle of the path should not be penalized because we are
          // only concerned about the direction at the start/end.
          final List<EdgeIteratorState> edges = path.calcEdges();
          if (!edges.isEmpty()) {
              if (penalizedVirtualEdges.contains(edges.get(0))) {
                  totalPenalty += uTurnDistancePenalty;
              }
          }
          if (edges.size() > 1) {
              if (penalizedVirtualEdges.contains(edges.get(edges.size() - 1))) {
                  totalPenalty += uTurnDistancePenalty;
              }
          }
          return path.getDistance() + totalPenalty;
      }
docs: Returns the path length plus a penalty if the starting/ending edge is unfavored.