src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * compare current relations e is a member of to new state parents and make it so
     * 
     * @param e current OsmElement
     * @param parents new Map of parent Relations
     */
compare current relations e is a member of to new state parents and make it so

@param e current OsmElement
@param parents new Map of parent Relations
compare current relations e is a member of to new state parents and make it so @param e current OsmElement @param parents new Map of parent Relations
public void updateParentRelations(@NonNull final OsmElement e, @NonNull final MultiHashMap<Long, RelationMemberPosition> parents) {
        Log.d(DEBUG_TAG, "updateParentRelations new parents size " + parents.size());
        List<Relation> origParents = e.getParentRelations() != null ? new ArrayList<>(e.getParentRelations()) : new ArrayList<>();
        for (Relation o : origParents) { 
            if (!parents.containsKey(o.getOsmId())) {
                removeElementFromRelation(e, o); 
                continue;
            }
            if (parents.containsKey(o.getOsmId())) {
                List<RelationMemberPosition> newMembers = new ArrayList<>(parents.get(o.getOsmId()));
                List<RelationMemberPosition> members = o.getAllMembersWithPosition(e);
                List<RelationMemberPosition> leftOvers = new ArrayList<>(members);
                for (RelationMemberPosition existing : members) {
                    if (newMembers.contains(existing)) {
                        newMembers.remove(existing);
                        leftOvers.remove(existing);
                    }
                }
                if (!newMembers.isEmpty() || !leftOvers.isEmpty()) {
                    dirty = true;
                    undo.save(o);
                    for (RelationMemberPosition newMember : newMembers) {
                        if (!leftOvers.isEmpty()) {
                            RelationMemberPosition member = leftOvers.get(0);
                            member.setRole(newMember.getRole());
                            leftOvers.remove(member);
                        } else {
                            addElementToRelation(e, -1, newMember.getRole(), o);
                        }
                    }
                    for (RelationMemberPosition rmp : leftOvers) { 
                        o.removeMember(rmp.getRelationMember());
                    }
                }
            }
        }
        for (Long l : parents.getKeys()) {
            Log.d(DEBUG_TAG, "updateParentRelations new parent " + l);
            if (l != -1) { 
                Relation r = currentStorage.getRelation(l);
                if (!origParents.contains(r)) {
                    for (RelationMemberPosition rmp : parents.get(l)) {
                        Log.d(DEBUG_TAG, "updateParentRelations adding " + e.getDescription() + " to " + r.getDescription());
                        addElementToRelation(e, -1, rmp.getRole(), r);  append for now only
                    }
                }
            }
        }
    }
public void updateParentRelations ( @ NonNull final OsmElement e , @ NonNull final MultiHashMap < Long , RelationMemberPosition > parents ) { Log . d ( DEBUG_TAG , "updateParentRelations new parents size " + parents . size ( ) ) ; List < Relation > origParents = e . getParentRelations ( ) != null ? new ArrayList < > ( e . getParentRelations ( ) ) : new ArrayList < > ( ) ; for ( Relation o : origParents ) { if ( ! parents . containsKey ( o . getOsmId ( ) ) ) { removeElementFromRelation ( e , o ) ; continue ; } if ( parents . containsKey ( o . getOsmId ( ) ) ) { List < RelationMemberPosition > newMembers = new ArrayList < > ( parents . get ( o . getOsmId ( ) ) ) ; List < RelationMemberPosition > members = o . getAllMembersWithPosition ( e ) ; List < RelationMemberPosition > leftOvers = new ArrayList < > ( members ) ; for ( RelationMemberPosition existing : members ) { if ( newMembers . contains ( existing ) ) { newMembers . remove ( existing ) ; leftOvers . remove ( existing ) ; } } if ( ! newMembers . isEmpty ( ) || ! leftOvers . isEmpty ( ) ) { dirty = true ; undo . save ( o ) ; for ( RelationMemberPosition newMember : newMembers ) { if ( ! leftOvers . isEmpty ( ) ) { RelationMemberPosition member = leftOvers . get ( 0 ) ; member . setRole ( newMember . getRole ( ) ) ; leftOvers . remove ( member ) ; } else { addElementToRelation ( e , - 1 , newMember . getRole ( ) , o ) ; } } for ( RelationMemberPosition rmp : leftOvers ) { o . removeMember ( rmp . getRelationMember ( ) ) ; } } } } for ( Long l : parents . getKeys ( ) ) { Log . d ( DEBUG_TAG , "updateParentRelations new parent " + l ) ; if ( l != - 1 ) { Relation r = currentStorage . getRelation ( l ) ; if ( ! origParents . contains ( r ) ) { for ( RelationMemberPosition rmp : parents . get ( l ) ) { Log . d ( DEBUG_TAG , "updateParentRelations adding " + e . getDescription ( ) + " to " + r . getDescription ( ) ) ; addElementToRelation ( e , - 1 , rmp . getRole ( ) , r ) ; } } } } }
compare current relations e is a member of to new state parents and make it so
compare current relations e is a member of to new state parents and make it so
// find changes to existing memberships // saves undo state // leftOver contains any remaining existing members // newMembers members that we didn't find // these are no longer needed // add as new member to relation // // append for now only