src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Remove a node from all ways in storage, deleting ways with just one node in the process
     * 
     * If the first/last node of a closed way is deleted the way is re-closed
     * 
     * @param node Node to delete
     * @return count of how many ways node was deleted from
     */
Remove a node from all ways in storage, deleting ways with just one node in the process

If the first/last node of a closed way is deleted the way is re-closed

@param node Node to delete
@return count of how many ways node was deleted from
Remove a node from all ways in storage deleting ways with just one node in the process If the first / last node of a closed way is deleted the way is re - closed @param node Node to delete @return count of how many ways node was deleted from
private int removeWayNode(@NonNull final Node node) {
        dirty = true;
        int deleted = 0;
        try {
            List<Way> ways = currentStorage.getWays(node);
            ArrayList<OsmElement> changedElements = new ArrayList<>();
            for (Way way : ways) {
                undo.save(way);
                if (way.isClosed() && way.isEndNode(node) && way.getNodes().size() > 1) { 
                    way.removeNode(node);
                    if (way.getNodes().size() > 1 && !way.isClosed()) {
                        way.addNode(way.getFirstNode()); 
                    } else {
                        Log.e(DEBUG_TAG, "Way " + way.getOsmId() + " way already closed!");
                    }
                } else {
                    way.removeNode(node);
                }
                int size = way.getNodes().size();
                if (size < Way.MINIMUM_NODES_IN_WAY || (way.isClosed() && size < Way.MINIMUM_NODES_IN_CLOSED_WAY)) {
                    Log.w(DEBUG_TAG, "removeWayNode removing degenerate way " + way.getOsmId());
                    removeWay(way);
                } else {
                    way.updateState(OsmElement.STATE_MODIFIED);
                    apiStorage.insertElementSafe(way);
                    changedElements.add(way);
                }
                deleted++;
            }
            onElementChanged(null, changedElements);
        } catch (StorageException e) {
            Log.e(DEBUG_TAG, "removeWayNode got " + e.getMessage());
        }
        return deleted;
    }
private int removeWayNode ( @ NonNull final Node node ) { dirty = true ; int deleted = 0 ; try { List < Way > ways = currentStorage . getWays ( node ) ; ArrayList < OsmElement > changedElements = new ArrayList < > ( ) ; for ( Way way : ways ) { undo . save ( way ) ; if ( way . isClosed ( ) && way . isEndNode ( node ) && way . getNodes ( ) . size ( ) > 1 ) { way . removeNode ( node ) ; if ( way . getNodes ( ) . size ( ) > 1 && ! way . isClosed ( ) ) { way . addNode ( way . getFirstNode ( ) ) ; } else { Log . e ( DEBUG_TAG , "Way " + way . getOsmId ( ) + " way already closed!" ) ; } } else { way . removeNode ( node ) ; } int size = way . getNodes ( ) . size ( ) ; if ( size < Way . MINIMUM_NODES_IN_WAY || ( way . isClosed ( ) && size < Way . MINIMUM_NODES_IN_CLOSED_WAY ) ) { Log . w ( DEBUG_TAG , "removeWayNode removing degenerate way " + way . getOsmId ( ) ) ; removeWay ( way ) ; } else { way . updateState ( OsmElement . STATE_MODIFIED ) ; apiStorage . insertElementSafe ( way ) ; changedElements . add ( way ) ; } deleted ++ ; } onElementChanged ( null , changedElements ) ; } catch ( StorageException e ) { Log . e ( DEBUG_TAG , "removeWayNode got " + e . getMessage ( ) ) ; } return deleted ; }
Remove a node from all ways in storage, deleting ways with just one node in the process
Remove a node from all ways in storage deleting ways with just one node in the process
// undo - node is not changed, affected way(s) are stored below // note protection against // degenerate closed ways // re-close the way, except if it is already closed, which // means it is degenerate // remove way when less than two waynodes exist // or only the same node twice // NOTE this will not remove ways with three and more times the same node // TODO handle OOM