source: josm/trunk/src/org/openstreetmap/josm/data/osm/Changeset.java@ 7700

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

see #10701 - show changeset comments count in changeset dialog

  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Collection;
5import java.util.Date;
6import java.util.HashMap;
7import java.util.Map;
8
9import org.openstreetmap.josm.data.Bounds;
10import org.openstreetmap.josm.data.coor.LatLon;
11import org.openstreetmap.josm.data.osm.visitor.Visitor;
12
13/**
14 * Represents a single changeset in JOSM. For now its only used during
15 * upload but in the future we may do more.
16 *
17 */
18public final class Changeset implements Tagged {
19
20 /** The maximum changeset comment text length allowed by API 0.6 **/
21 public static final int MAX_COMMENT_LENGTH = 255;
22
23 /** the changeset id */
24 private int id;
25 /** the user who owns the changeset */
26 private User user;
27 /** date this changeset was created at */
28 private Date createdAt;
29 /** the date this changeset was closed at*/
30 private Date closedAt;
31 /** indicates whether this changeset is still open or not */
32 private boolean open;
33 /** the min. coordinates of the bounding box of this changeset */
34 private LatLon min;
35 /** the max. coordinates of the bounding box of this changeset */
36 private LatLon max;
37 /** the number of comments for this changeset */
38 private int commentsCount;
39 /** the map of tags */
40 private Map<String,String> tags;
41 /** indicates whether this changeset is incomplete. For an
42 * incomplete changeset we only know its id
43 */
44 private boolean incomplete;
45 /** the changeset content */
46 private ChangesetDataSet content = null;
47
48 /**
49 * Creates a new changeset with id 0.
50 */
51 public Changeset() {
52 this(0);
53 }
54
55 /**
56 * Creates a changeset with id <code>id</code>. If id &gt; 0, sets incomplete to true.
57 *
58 * @param id the id
59 */
60 public Changeset(int id) {
61 this.id = id;
62 this.incomplete = id > 0;
63 this.tags = new HashMap<>();
64 }
65
66 /**
67 * Creates a clone of <code>other</code>
68 *
69 * @param other the other changeset. If null, creates a new changeset with id 0.
70 */
71 public Changeset(Changeset other) {
72 if (other == null) {
73 this.id = 0;
74 this.tags = new HashMap<>();
75 } else if (other.isIncomplete()) {
76 setId(other.getId());
77 this.incomplete = true;
78 this.tags = new HashMap<>();
79 } else {
80 this.id = other.id;
81 mergeFrom(other);
82 this.incomplete = false;
83 }
84 }
85
86 public void visit(Visitor v) {
87 v.visit(this);
88 }
89
90 public int compareTo(Changeset other) {
91 return Integer.valueOf(getId()).compareTo(other.getId());
92 }
93
94 public String getName() {
95 // no translation
96 return "changeset " + getId();
97 }
98
99 public String getDisplayName(NameFormatter formatter) {
100 return formatter.format(this);
101 }
102
103 public int getId() {
104 return id;
105 }
106
107 public void setId(int id) {
108 this.id = id;
109 }
110
111 public User getUser() {
112 return user;
113 }
114
115 public void setUser(User user) {
116 this.user = user;
117 }
118
119 public Date getCreatedAt() {
120 return createdAt;
121 }
122
123 public void setCreatedAt(Date createdAt) {
124 this.createdAt = createdAt;
125 }
126
127 public Date getClosedAt() {
128 return closedAt;
129 }
130
131 public void setClosedAt(Date closedAt) {
132 this.closedAt = closedAt;
133 }
134
135 public boolean isOpen() {
136 return open;
137 }
138
139 public void setOpen(boolean open) {
140 this.open = open;
141 }
142
143 public LatLon getMin() {
144 return min;
145 }
146
147 public void setMin(LatLon min) {
148 this.min = min;
149 }
150
151 public LatLon getMax() {
152 return max;
153 }
154
155 public Bounds getBounds() {
156 if (min != null && max != null)
157 return new Bounds(min,max);
158 return null;
159 }
160
161 public void setMax(LatLon max) {
162 this.max = max;
163 }
164
165 /**
166 * Replies the number of comments for this changeset.
167 * @return the number of comments for this changeset
168 * @since 7700
169 */
170 public final int getCommentsCount() {
171 return commentsCount;
172 }
173
174 /**
175 * Sets the number of comments for this changeset.
176 * @param commentsCount the number of comments for this changeset
177 * @since 7700
178 */
179 public final void setCommentsCount(int commentsCount) {
180 this.commentsCount = commentsCount;
181 }
182
183 @Override
184 public Map<String, String> getKeys() {
185 return tags;
186 }
187
188 @Override
189 public void setKeys(Map<String, String> keys) {
190 this.tags = keys;
191 }
192
193 public boolean isIncomplete() {
194 return incomplete;
195 }
196
197 public void setIncomplete(boolean incomplete) {
198 this.incomplete = incomplete;
199 }
200
201 @Override
202 public void put(String key, String value) {
203 this.tags.put(key, value);
204 }
205
206 @Override
207 public String get(String key) {
208 return this.tags.get(key);
209 }
210
211 @Override
212 public void remove(String key) {
213 this.tags.remove(key);
214 }
215
216 @Override
217 public void removeAll() {
218 this.tags.clear();
219 }
220
221 public boolean hasEqualSemanticAttributes(Changeset other) {
222 if (other == null)
223 return false;
224 if (closedAt == null) {
225 if (other.closedAt != null)
226 return false;
227 } else if (!closedAt.equals(other.closedAt))
228 return false;
229 if (createdAt == null) {
230 if (other.createdAt != null)
231 return false;
232 } else if (!createdAt.equals(other.createdAt))
233 return false;
234 if (id != other.id)
235 return false;
236 if (max == null) {
237 if (other.max != null)
238 return false;
239 } else if (!max.equals(other.max))
240 return false;
241 if (min == null) {
242 if (other.min != null)
243 return false;
244 } else if (!min.equals(other.min))
245 return false;
246 if (open != other.open)
247 return false;
248 if (tags == null) {
249 if (other.tags != null)
250 return false;
251 } else if (!tags.equals(other.tags))
252 return false;
253 if (user == null) {
254 if (other.user != null)
255 return false;
256 } else if (!user.equals(other.user))
257 return false;
258 if (commentsCount != other.commentsCount) {
259 return false;
260 }
261 return true;
262 }
263
264 @Override
265 public int hashCode() {
266 if (id > 0)
267 return id;
268 else
269 return super.hashCode();
270 }
271
272 @Override
273 public boolean equals(Object obj) {
274 if (this == obj)
275 return true;
276 if (obj == null)
277 return false;
278 if (getClass() != obj.getClass())
279 return false;
280 Changeset other = (Changeset) obj;
281 if (this.id > 0 && other.id == this.id)
282 return true;
283 return this == obj;
284 }
285
286 @Override
287 public boolean hasKeys() {
288 return !tags.keySet().isEmpty();
289 }
290
291 @Override
292 public Collection<String> keySet() {
293 return tags.keySet();
294 }
295
296 public boolean isNew() {
297 return id <= 0;
298 }
299
300 public void mergeFrom(Changeset other) {
301 if (other == null)
302 return;
303 if (id != other.id)
304 return;
305 this.user = other.user;
306 this.createdAt = other.createdAt;
307 this.closedAt = other.closedAt;
308 this.open = other.open;
309 this.min = other.min;
310 this.max = other.max;
311 this.commentsCount = other.commentsCount;
312 this.tags = new HashMap<>(other.tags);
313 this.incomplete = other.incomplete;
314
315 // FIXME: merging of content required?
316 this.content = other.content;
317 }
318
319 public boolean hasContent() {
320 return content != null;
321 }
322
323 public ChangesetDataSet getContent() {
324 return content;
325 }
326
327 public void setContent(ChangesetDataSet content) {
328 this.content = content;
329 }
330}
Note: See TracBrowser for help on using the repository browser.