public static Command addPrimitivesToRelation(final Relation orig, Collection<? extends OsmPrimitive> primitivesToAdd) throws IllegalArgumentException {
CheckParameterUtil.ensureParameterNotNull(orig, "orig");
try {
final Collection<TaggingPreset> presets = TaggingPreset.getMatchingPresets(EnumSet.of(TaggingPresetType.RELATION), orig.getKeys(), false);
Relation relation = new Relation(orig);
boolean modified = false;
for (OsmPrimitive p : primitivesToAdd) {
if (p instanceof Relation && orig.equals(p)) {
warnOfCircularReferences(p);
continue;
} else if (MemberTableModel.hasMembersReferringTo(relation.getMembers(), Collections.singleton(p))
&& !confirmAddingPrimitive(p)) {
continue;
}
final String role = presets.isEmpty() ? null : presets.iterator().next().suggestRoleForOsmPrimitive(p);
relation.addMember(new RelationMember(role == null ? "" : role, p));
modified = true;
}
return modified ? new ChangeCommand(orig, relation) : null;
} catch (AddAbortException ign) {
return null;