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

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

fix #7716 - History shows same version number, wrong date, user, and CT for modified objects

  • Property svn:eol-style set to native
File size: 4.8 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 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 changesetId the changeset id (> 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) throws IllegalArgumentException {
38 super(id, version, visible, user, changesetId, timestamp);
39 }
40
41 /**
42 * constructor
43 *
44 * @param id the id (>0 required)
45 * @param version the version (> 0 required)
46 * @param visible whether the primitive is still visible
47 * @param user the user (! null required)
48 * @param changesetId the changeset id (> 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) throws IllegalArgumentException {
56 super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
57 }
58
59 /**
60 * constructor
61 *
62 * @param id the id (>0 required)
63 * @param version the version (> 0 required)
64 * @param visible whether the primitive is still visible
65 * @param user the user (! null required)
66 * @param changesetId the changeset id (> 0 required)
67 * @param timestamp the timestamp (! null required)
68 * @param members list of members for this relation
69 *
70 * @throws IllegalArgumentException thrown if preconditions are violated
71 */
72 public HistoryRelation(long id, long version, boolean visible, User user, long changesetId,
73 Date timestamp, ArrayList<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 thrown, 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(MessageFormat.format("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", members.size(),idx));
116 return members.get(idx);
117 }
118
119 /**
120 * replies the type, i.e. {@link OsmPrimitiveType#RELATION}
121 *
122 */
123 @Override
124 public OsmPrimitiveType getType() {
125 return OsmPrimitiveType.RELATION;
126 }
127
128 /**
129 * adds a member to the list of members
130 *
131 * @param member the member (must not be null)
132 * @exception IllegalArgumentException thrown, if member is null
133 */
134 public void addMember(RelationMemberData member) throws IllegalArgumentException {
135 CheckParameterUtil.ensureParameterNotNull(member, "member");
136 members.add(member);
137 }
138
139 @Override
140 public String getDisplayName(HistoryNameFormatter formatter) {
141 return formatter.format(this);
142 }
143}
Note: See TracBrowser for help on using the repository browser.