1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm.history;
|
---|
3 |
|
---|
4 | import java.text.MessageFormat;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collections;
|
---|
7 | import java.util.Date;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
11 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
12 | import org.openstreetmap.josm.data.osm.RelationMemberData;
|
---|
13 | import org.openstreetmap.josm.data.osm.User;
|
---|
14 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Represents an immutable OSM relation in the context of a historical view on
|
---|
18 | * OSM data.
|
---|
19 | *
|
---|
20 | */
|
---|
21 | public class HistoryRelation extends HistoryOsmPrimitive{
|
---|
22 |
|
---|
23 | private ArrayList<RelationMemberData> members = new ArrayList<RelationMemberData>();
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * constructor
|
---|
27 | *
|
---|
28 | * @param id the id (>0 required)
|
---|
29 | * @param version the version (> 0 required)
|
---|
30 | * @param visible whether the primitive is still visible
|
---|
31 | * @param user the user (! null required)
|
---|
32 | * @param uid the user id (> 0 required)
|
---|
33 | * @param changesetId the changeset id (> 0 required)
|
---|
34 | * @param timestamp the timestamp (! null required)
|
---|
35 | *
|
---|
36 | * @throws IllegalArgumentException thrown if preconditions are violated
|
---|
37 | */
|
---|
38 | public HistoryRelation(long id, long version, boolean visible, User user, long changesetId,
|
---|
39 | Date timestamp) throws IllegalArgumentException {
|
---|
40 | super(id, version, visible, user, changesetId, timestamp);
|
---|
41 | }
|
---|
42 | /**
|
---|
43 | * constructor
|
---|
44 | *
|
---|
45 | * @param id the id (>0 required)
|
---|
46 | * @param version the version (> 0 required)
|
---|
47 | * @param visible whether the primitive is still visible
|
---|
48 | * @param user the user (! null required)
|
---|
49 | * @param uid the user id (> 0 required)
|
---|
50 | * @param changesetId the changeset id (> 0 required)
|
---|
51 | * @param timestamp the timestamp (! null required)
|
---|
52 | * @param members list of members for this relation
|
---|
53 | *
|
---|
54 | * @throws IllegalArgumentException thrown if preconditions are violated
|
---|
55 | */
|
---|
56 | public HistoryRelation(long id, long version, boolean visible, User user, long changesetId,
|
---|
57 | Date timestamp, ArrayList<RelationMemberData> members) {
|
---|
58 | this(id, version, visible, user, changesetId, timestamp);
|
---|
59 | if (members != null) {
|
---|
60 | this.members.addAll(members);
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public HistoryRelation(Relation p) {
|
---|
65 | super(p);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * replies an immutable list of members of this relation
|
---|
70 | *
|
---|
71 | * @return an immutable list of members of this relation
|
---|
72 | */
|
---|
73 | public List<RelationMemberData> getMembers() {
|
---|
74 | return Collections.unmodifiableList(members);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * replies the number of members
|
---|
79 | *
|
---|
80 | * @return the number of members
|
---|
81 | *
|
---|
82 | */
|
---|
83 | public int getNumMembers() {
|
---|
84 | return members.size();
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * replies the idx-th member
|
---|
89 | * @param idx the index
|
---|
90 | * @return the idx-th member
|
---|
91 | * @throws IndexOutOfBoundsException thrown, if idx is out of bounds
|
---|
92 | */
|
---|
93 | public RelationMemberData getRelationMember(int idx) throws IndexOutOfBoundsException {
|
---|
94 | if (idx < 0 || idx >= members.size())
|
---|
95 | throw new IndexOutOfBoundsException(MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(),idx));
|
---|
96 | return members.get(idx);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * replies the type, i.e. {@see OsmPrimitiveType#RELATION}
|
---|
101 | *
|
---|
102 | */
|
---|
103 | @Override
|
---|
104 | public OsmPrimitiveType getType() {
|
---|
105 | return OsmPrimitiveType.RELATION;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * adds a member to the list of members
|
---|
110 | *
|
---|
111 | * @param member the member (must not be null)
|
---|
112 | * @exception IllegalArgumentException thrown, if member is null
|
---|
113 | */
|
---|
114 | public void addMember(RelationMemberData member) throws IllegalArgumentException {
|
---|
115 | CheckParameterUtil.ensureParameterNotNull(member, "member");
|
---|
116 | members.add(member);
|
---|
117 | }
|
---|
118 |
|
---|
119 | @Override
|
---|
120 | public String getDisplayName(HistoryNameFormatter formatter) {
|
---|
121 | return formatter.format(this);
|
---|
122 | }
|
---|
123 | }
|
---|