1 | package org.openstreetmap.josm.data.osm;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Arrays;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map.Entry;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.Visitor;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * An relation, having a set of tags and any number (0...n) of members.
|
---|
13 | *
|
---|
14 | * @author Frederik Ramm <frederik@remote.org>
|
---|
15 | */
|
---|
16 | public final class Relation extends OsmPrimitive {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * All members of this relation. Note that after changing this,
|
---|
20 | * makeBackReferences and/or removeBackReferences should be called.
|
---|
21 | */
|
---|
22 | public final List<RelationMember> members = new ArrayList<RelationMember>();
|
---|
23 |
|
---|
24 | @Override public void visit(Visitor visitor) {
|
---|
25 | visitor.visit(this);
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Create an identical clone of the argument (including the id)
|
---|
30 | */
|
---|
31 | public Relation(Relation clone) {
|
---|
32 | cloneFrom(clone);
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Create an incomplete Relation.
|
---|
37 | */
|
---|
38 | public Relation(long id) {
|
---|
39 | this.id = id;
|
---|
40 | incomplete = true;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Create an empty Relation. Use this only if you set meaningful values
|
---|
45 | * afterwards.
|
---|
46 | */
|
---|
47 | public Relation() {
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override public void cloneFrom(OsmPrimitive osm) {
|
---|
51 | super.cloneFrom(osm);
|
---|
52 | members.clear();
|
---|
53 | // we must not add the members themselves, but instead
|
---|
54 | // add clones of the members
|
---|
55 | for (RelationMember em : ((Relation)osm).members) {
|
---|
56 | members.add(new RelationMember(em));
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override public String toString() {
|
---|
61 | return "{Relation id="+id+" members="+Arrays.toString(members.toArray())+"}";
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
|
---|
65 | return osm instanceof Relation ? super.realEqual(osm, semanticOnly) && members.equals(((Relation)osm).members) : false;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public int compareTo(OsmPrimitive o) {
|
---|
69 | return o instanceof Relation ? Long.valueOf(id).compareTo(o.id) : -1;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public boolean isIncomplete() {
|
---|
73 | for (RelationMember m : members)
|
---|
74 | if (m.member == null)
|
---|
75 | return true;
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 | }
|
---|