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