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