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

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

see #8465 - use diamond operator where applicable

  • Property svn:eol-style set to native
File size: 7.2 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 map of tags */
38 private Map<String,String> tags;
39 /** indicates whether this changeset is incomplete. For an
40 * incomplete changeset we only know its id
41 */
42 private boolean incomplete;
43 /** the changeset content */
44 private ChangesetDataSet content = null;
45
46 /**
47 * Creates a new changeset with id 0.
48 */
49 public Changeset() {
50 this(0);
51 }
52
53 /**
54 * Creates a changeset with id <code>id</code>. If id &gt; 0, sets incomplete to true.
55 *
56 * @param id the id
57 */
58 public Changeset(int id) {
59 this.id = id;
60 this.incomplete = id > 0;
61 this.tags = new HashMap<>();
62 }
63
64 /**
65 * Creates a clone of <code>other</code>
66 *
67 * @param other the other changeset. If null, creates a new changeset with id 0.
68 */
69 public Changeset(Changeset other) {
70 if (other == null) {
71 this.id = 0;
72 this.tags = new HashMap<>();
73 } else if (other.isIncomplete()) {
74 setId(other.getId());
75 this.incomplete = true;
76 this.tags = new HashMap<>();
77 } else {
78 this.id = other.id;
79 mergeFrom(other);
80 this.incomplete = false;
81 }
82 }
83
84 public void visit(Visitor v) {
85 v.visit(this);
86 }
87
88 public int compareTo(Changeset other) {
89 return Integer.valueOf(getId()).compareTo(other.getId());
90 }
91
92 public String getName() {
93 // no translation
94 return "changeset " + getId();
95 }
96
97 public String getDisplayName(NameFormatter formatter) {
98 return formatter.format(this);
99 }
100
101 public int getId() {
102 return id;
103 }
104
105 public void setId(int id) {
106 this.id = id;
107 }
108
109 public User getUser() {
110 return user;
111 }
112
113 public void setUser(User user) {
114 this.user = user;
115 }
116
117 public Date getCreatedAt() {
118 return createdAt;
119 }
120
121 public void setCreatedAt(Date createdAt) {
122 this.createdAt = createdAt;
123 }
124
125 public Date getClosedAt() {
126 return closedAt;
127 }
128
129 public void setClosedAt(Date closedAt) {
130 this.closedAt = closedAt;
131 }
132
133 public boolean isOpen() {
134 return open;
135 }
136
137 public void setOpen(boolean open) {
138 this.open = open;
139 }
140
141 public LatLon getMin() {
142 return min;
143 }
144
145 public void setMin(LatLon min) {
146 this.min = min;
147 }
148
149 public LatLon getMax() {
150 return max;
151 }
152
153 public Bounds getBounds() {
154 if (min != null && max != null)
155 return new Bounds(min,max);
156 return null;
157 }
158
159 public void setMax(LatLon max) {
160 this.max = max;
161 }
162
163 @Override
164 public Map<String, String> getKeys() {
165 return tags;
166 }
167
168 @Override
169 public void setKeys(Map<String, String> keys) {
170 this.tags = keys;
171 }
172
173 public boolean isIncomplete() {
174 return incomplete;
175 }
176
177 public void setIncomplete(boolean incomplete) {
178 this.incomplete = incomplete;
179 }
180
181 @Override
182 public void put(String key, String value) {
183 this.tags.put(key, value);
184 }
185
186 @Override
187 public String get(String key) {
188 return this.tags.get(key);
189 }
190
191 @Override
192 public void remove(String key) {
193 this.tags.remove(key);
194 }
195
196 @Override
197 public void removeAll() {
198 this.tags.clear();
199 }
200
201 public boolean hasEqualSemanticAttributes(Changeset other) {
202 if (other == null)
203 return false;
204 if (closedAt == null) {
205 if (other.closedAt != null)
206 return false;
207 } else if (!closedAt.equals(other.closedAt))
208 return false;
209 if (createdAt == null) {
210 if (other.createdAt != null)
211 return false;
212 } else if (!createdAt.equals(other.createdAt))
213 return false;
214 if (id != other.id)
215 return false;
216 if (max == null) {
217 if (other.max != null)
218 return false;
219 } else if (!max.equals(other.max))
220 return false;
221 if (min == null) {
222 if (other.min != null)
223 return false;
224 } else if (!min.equals(other.min))
225 return false;
226 if (open != other.open)
227 return false;
228 if (tags == null) {
229 if (other.tags != null)
230 return false;
231 } else if (!tags.equals(other.tags))
232 return false;
233 if (user == null) {
234 if (other.user != null)
235 return false;
236 } else if (!user.equals(other.user))
237 return false;
238 return true;
239 }
240
241 @Override
242 public int hashCode() {
243 if (id > 0)
244 return id;
245 else
246 return super.hashCode();
247 }
248
249 @Override
250 public boolean equals(Object obj) {
251 if (this == obj)
252 return true;
253 if (obj == null)
254 return false;
255 if (getClass() != obj.getClass())
256 return false;
257 Changeset other = (Changeset) obj;
258 if (this.id > 0 && other.id == this.id)
259 return true;
260 return this == obj;
261 }
262
263 @Override
264 public boolean hasKeys() {
265 return !tags.keySet().isEmpty();
266 }
267
268 @Override
269 public Collection<String> keySet() {
270 return tags.keySet();
271 }
272
273 public boolean isNew() {
274 return id <= 0;
275 }
276
277 public void mergeFrom(Changeset other) {
278 if (other == null)
279 return;
280 if (id != other.id)
281 return;
282 this.user = other.user;
283 this.createdAt = other.createdAt;
284 this.closedAt = other.closedAt;
285 this.open = other.open;
286 this.min = other.min;
287 this.max = other.max;
288 this.tags = new HashMap<>(other.tags);
289 this.incomplete = other.incomplete;
290
291 // FIXME: merging of content required?
292 this.content = other.content;
293 }
294
295 public boolean hasContent() {
296 return content != null;
297 }
298
299 public ChangesetDataSet getContent() {
300 return content;
301 }
302
303 public void setContent(ChangesetDataSet content) {
304 this.content = content;
305 }
306}
Note: See TracBrowser for help on using the repository browser.