@SuppressWarnings("PMD.NPathComplexity") // split up would not help readability
    public static void addCacheWaypointLongClickPopupMenu(final SimplePopupMenu menu, final Activity activity, final RouteItem routeItem, final IndividualRoute individualRoute, final IndividualRoute.UpdateIndividualRoute routeUpdater, final Runnable updateRouteTrackButtonVisibility) {

        final RouteSegment[] segments = (individualRoute != null ? individualRoute.getSegments() : null);
        final boolean routeIsNotEmpty = segments != null && segments.length > 0;
        final int baseId = (segments != null ? segments.length : 0) + 100;

        boolean isEnd = false;

        if (routeIsNotEmpty) {
            final String routeItemIdentifier = routeItem.getIdentifier();
            final boolean isStart = StringUtils.equals(routeItemIdentifier, segments[0].getItem().getIdentifier());
            if (isStart) {
                addMenuHelper(activity, menu, 0, activity.getString(R.string.context_map_remove_from_route_start), individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
            }
            for (int i = 1; i < segments.length - 1; i++) {
                if (StringUtils.equals(routeItemIdentifier, segments[i].getItem().getIdentifier())) {
                    addMenuHelper(activity, menu, i, String.format(Locale.getDefault(), activity.getString(R.string.context_map_remove_from_route_pos), i + 1), individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
                }
            }
            isEnd = (segments.length > 1) && StringUtils.equals(routeItemIdentifier, segments[segments.length - 1].getItem().getIdentifier());
            if (isEnd) {
                addMenuHelper(activity, menu, segments.length - 1, activity.getString(R.string.context_map_remove_from_route_end), individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
            } else {
                addMenuHelper(activity, menu, baseId + 1, activity.getString(R.string.context_map_add_to_route), routeItem, false, individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
            }
            if (!isStart) {
                addMenuHelper(activity, menu, baseId, activity.getString(R.string.context_map_add_to_route_start), routeItem, true, individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
            }
        } else {
            addMenuHelper(activity, menu, baseId + 1, activity.getString(R.string.context_map_add_to_route), routeItem, false, individualRoute, routeUpdater, updateRouteTrackButtonVisibility);
        }

        final float elevation = Routing.getElevation(routeItem.getPoint());
        if (!Float.isNaN(elevation)) {
            menu.addMenuItem(baseId + 100, activity.getString(R.string.menu_elevation_info) + " " + Units.formatElevation(elevation), R.drawable.elevation);
        }
    }
@return the complete popup builder without dismiss listener specified
main/src/main/java/cgeo/geocaching/maps/MapUtils.java