src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Unjoin a way by replacing shared nodes with new ones
     * 
     * @param ctx Android Context
     * @param way the Way to unjoin
     * @param ignoreSimilar don't unjoin from ways with the same primary key if true, but replace the node in them too
     */
Unjoin a way by replacing shared nodes with new ones

@param ctx Android Context
@param way the Way to unjoin
@param ignoreSimilar don't unjoin from ways with the same primary key if true, but replace the node in them too
Unjoin a way by replacing shared nodes with new ones @param ctx Android Context @param way the Way to unjoin @param ignoreSimilar don ' t unjoin from ways with the same primary key if true but replace the node in them too
public void unjoinWay(@Nullable Context ctx, @NonNull final Way way, boolean ignoreSimilar) {
        Set<Node> wayNodes = new HashSet<>(way.getNodes()); 
        Map<Long, Boolean> keyMap = new HashMap<>();
        String primaryTag = way.getPrimaryTag(ctx);
        String primaryKey = null;
        if (primaryTag != null) {
            String[] t = primaryTag.split("=");
            if (t.length == 2) {
                primaryKey = t[0];
            }
        }
        for (Node nd : wayNodes) {
            List<Way> otherWays = getCurrentStorage().getWays(nd);
            List<Way> similarWays = new ArrayList<>();
            if (otherWays.size() > 1 && ignoreSimilar && primaryKey != null) {
                for (Way other : otherWays) {
                    if (!way.equals(other)) {
                        Long otherId = Long.valueOf(other.getOsmId());
                        Boolean isSimilar = keyMap.get(otherId);
                        if (isSimilar == null) {
                            isSimilar = other.hasTagKey(primaryKey);
                            keyMap.put(otherId, isSimilar);
                        }
                        if (isSimilar) {
                            similarWays.add(other);
                        }
                    }
                }
            }
            if (similarWays.size() < otherWays.size() - 1) { 
                Node newNode = replaceWayNode(nd, way);
                for (Way similar : similarWays) {
                    replaceNodeInWay(nd, newNode, similar);
                }
            }
        }
    }
public void unjoinWay ( @ Nullable Context ctx , @ NonNull final Way way , boolean ignoreSimilar ) { Set < Node > wayNodes = new HashSet < > ( way . getNodes ( ) ) ; Map < Long , Boolean > keyMap = new HashMap < > ( ) ; String primaryTag = way . getPrimaryTag ( ctx ) ; String primaryKey = null ; if ( primaryTag != null ) { String [ ] t = primaryTag . split ( "=" ) ; if ( t . length == 2 ) { primaryKey = t [ 0 ] ; } } for ( Node nd : wayNodes ) { List < Way > otherWays = getCurrentStorage ( ) . getWays ( nd ) ; List < Way > similarWays = new ArrayList < > ( ) ; if ( otherWays . size ( ) > 1 && ignoreSimilar && primaryKey != null ) { for ( Way other : otherWays ) { if ( ! way . equals ( other ) ) { Long otherId = Long . valueOf ( other . getOsmId ( ) ) ; Boolean isSimilar = keyMap . get ( otherId ) ; if ( isSimilar == null ) { isSimilar = other . hasTagKey ( primaryKey ) ; keyMap . put ( otherId , isSimilar ) ; } if ( isSimilar ) { similarWays . add ( other ) ; } } } } if ( similarWays . size ( ) < otherWays . size ( ) - 1 ) { Node newNode = replaceWayNode ( nd , way ) ; for ( Way similar : similarWays ) { replaceNodeInWay ( nd , newNode , similar ) ; } } } }
Unjoin a way by replacing shared nodes with new ones
Unjoin a way by replacing shared nodes with new ones
// only do every node once // if all are the same no need to replace