source: josm/trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java@ 8291

Last change on this file since 8291 was 8291, checked in by Don-vip, 9 years ago

fix squid:RedundantThrowsDeclarationCheck + consistent Javadoc for exceptions

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.history;
3
4import java.text.MessageFormat;
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.Date;
8import java.util.List;
9
10import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.data.osm.RelationMemberData;
13import org.openstreetmap.josm.data.osm.User;
14import 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 */
21public class HistoryRelation extends HistoryOsmPrimitive{
22
23 private List<RelationMemberData> members = new ArrayList<>();
24
25 /**
26 * constructor
27 *
28 * @param id the id (&gt; 0 required)
29 * @param version the version (&gt; 0 required)
30 * @param visible whether the primitive is still visible
31 * @param user the user (!= null required)
32 * @param changesetId the changeset id (&gt; 0 required)
33 * @param timestamp the timestamp (!= null required)
34 *
35 * @throws IllegalArgumentException if preconditions are violated
36 */
37 public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
38 super(id, version, visible, user, changesetId, timestamp);
39 }
40
41 /**
42 * constructor
43 *
44 * @param id the id (&gt; 0 required)
45 * @param version the version (&gt; 0 required)
46 * @param visible whether the primitive is still visible
47 * @param user the user (!= null required)
48 * @param changesetId the changeset id (&gt; 0 required if {@code checkHistoricParams} is true)
49 * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
50 * @param checkHistoricParams If true, checks values of {@code changesetId} and {@code timestamp}
51 *
52 * @throws IllegalArgumentException if preconditions are violated
53 * @since 5440
54 */
55 public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) {
56 super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
57 }
58
59 /**
60 * constructor
61 *
62 * @param id the id (&gt; 0 required)
63 * @param version the version (&gt; 0 required)
64 * @param visible whether the primitive is still visible
65 * @param user the user (!= null required)
66 * @param changesetId the changeset id (&gt; 0 required)
67 * @param timestamp the timestamp (!= null required)
68 * @param members list of members for this relation
69 *
70 * @throws IllegalArgumentException if preconditions are violated
71 */
72 public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp, List<RelationMemberData> members) {
73 this(id, version, visible, user, changesetId, timestamp);
74 if (members != null) {
75 this.members.addAll(members);
76 }
77 }
78
79 /**
80 * Constructs a new {@code HistoryRelation} from an existing {@link Relation}.
81 * @param r the relation
82 */
83 public HistoryRelation(Relation r) {
84 super(r);
85 }
86
87 /**
88 * replies an immutable list of members of this relation
89 *
90 * @return an immutable list of members of this relation
91 */
92 public List<RelationMemberData> getMembers() {
93 return Collections.unmodifiableList(members);
94 }
95
96 /**
97 * replies the number of members
98 *
99 * @return the number of members
100 *
101 */
102 public int getNumMembers() {
103 return members.size();
104 }
105
106 /**
107 * replies the idx-th member
108 * @param idx the index
109 * @return the idx-th member
110 * @throws IndexOutOfBoundsException if idx is out of bounds
111 */
112 public RelationMemberData getRelationMember(int idx) throws IndexOutOfBoundsException {
113 if (idx < 0 || idx >= members.size())
114 throw new IndexOutOfBoundsException(MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(),idx));
115 return members.get(idx);
116 }
117
118 /**
119 * replies the type, i.e. {@link OsmPrimitiveType#RELATION}
120 *
121 */
122 @Override
123 public OsmPrimitiveType getType() {
124 return OsmPrimitiveType.RELATION;
125 }
126
127 /**
128 * adds a member to the list of members
129 *
130 * @param member the member (must not be null)
131 * @throws IllegalArgumentException if member is null
132 */
133 public void addMember(RelationMemberData member) {
134 CheckParameterUtil.ensureParameterNotNull(member, "member");
135 members.add(member);
136 }
137
138 @Override
139 public String getDisplayName(HistoryNameFormatter formatter) {
140 return formatter.format(this);
141 }
142}
Note: See TracBrowser for help on using the repository browser.