---
core-dave/src/org/openstreetmap/josm/data/osm/Relation.java | 33 ++++++++++++ 1 file changed, 33 insertions(+) diff -puN src/org/openstreetmap/josm/data/osm/Relation.java~relation-updateMembers-p1 src/org/openstreetmap/josm/data/osm/Relation.java --- core/src/org/openstreetmap/josm/data/osm/Relation.java~relation-updateMembers-p1 2008-04-28 18:59:32.000000000 -0700 +++ core-dave/src/org/openstreetmap/josm/data/osm/Relation.java 2008-04-28 18:59:32.000000000 -0700 @@ -1,9 +1,16 @@ package org.openstreetmap.josm.data.osm; +import static org.openstreetmap.josm.tools.I18n.tr; + import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; +import org.openstreetmap.josm.command.AddRelationMemberCommand; +import org.openstreetmap.josm.command.Command; +import org.openstreetmap.josm.command.RemoveRelationMemberCommand; +import org.openstreetmap.josm.command.SequenceCommand; import org.openstreetmap.josm.data.osm.visitor.Visitor; /** @@ -73,4 +80,30 @@ public final class Relation extends OsmP return true; return false; } + + /** + * @param from - the list of relation members that will get changed + * @param to - relation member that will be the new target + * + * If any RelationMember is in @from, it will get updated to point + * to @to. If any RelationMember is no + * + * @return set of commands to perform the update + */ + public Command updateMembers(List<OsmPrimitive> _from, OsmPrimitive to) { + List<OsmPrimitive> from = new LinkedList<OsmPrimitive>(_from); + List<Command> cmds = new LinkedList<Command>(); + if (from.contains(to)) + from.remove(to); + for (RelationMember rm : this.members) { + // Don't copy the member if it to one of our ways, just keep a + // note to re-add it later on. + if (from.contains(rm.member)) { + RelationMember newrm = new RelationMember(rm.role, to); + cmds.add(new RemoveRelationMemberCommand(this, rm)); + cmds.add(new AddRelationMemberCommand(this, newrm)); + } + } + return new SequenceCommand(tr("Update relation members"), cmds); + } } _ _______________________________________________ josm-dev mailing list josm-dev@openstreetmap.org http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/josm-dev