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