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

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

sonar - Immutable Field

  • 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 final 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,
73 List<RelationMemberData> members) {
74 this(id, version, visible, user, changesetId, timestamp);
75 if (members != null) {
76 this.members.addAll(members);
77 }
78 }
79
80 /**
81 * Constructs a new {@code HistoryRelation} from an existing {@link Relation}.
82 * @param r the relation
83 */
84 public HistoryRelation(Relation r) {
85 super(r);
86 }
87
88 /**
89 * replies an immutable list of members of this relation
90 *
91 * @return an immutable list of members of this relation
92 */
93 public List<RelationMemberData> getMembers() {
94 return Collections.unmodifiableList(members);
95 }
96
97 /**
98 * replies the number of members
99 *
100 * @return the number of members
101 *
102 */
103 public int getNumMembers() {
104 return members.size();
105 }
106
107 /**
108 * replies the idx-th member
109 * @param idx the index
110 * @return the idx-th member
111 * @throws IndexOutOfBoundsException if idx is out of bounds
112 */
113 public RelationMemberData getRelationMember(int idx) throws IndexOutOfBoundsException {
114 if (idx < 0 || idx >= members.size())
115 throw new IndexOutOfBoundsException(
116 MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(), idx));
117 return members.get(idx);
118 }
119
120 /**
121 * replies the type, i.e. {@link OsmPrimitiveType#RELATION}
122 *
123 */
124 @Override
125 public OsmPrimitiveType getType() {
126 return OsmPrimitiveType.RELATION;
127 }
128
129 /**
130 * adds a member to the list of members
131 *
132 * @param member the member (must not be null)
133 * @throws IllegalArgumentException if member is null
134 */
135 public void addMember(RelationMemberData member) {
136 CheckParameterUtil.ensureParameterNotNull(member, "member");
137 members.add(member);
138 }
139
140 @Override
141 public String getDisplayName(HistoryNameFormatter formatter) {
142 return formatter.format(this);
143 }
144}
Note: See TracBrowser for help on using the repository browser.