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 | /** the changeset id */
|
---|
20 | private int id;
|
---|
21 | /** the user who owns the changeset */
|
---|
22 | private User user;
|
---|
23 | /** date this changeset was created at */
|
---|
24 | private Date createdAt;
|
---|
25 | /** the date this changeset was closed at*/
|
---|
26 | private Date closedAt;
|
---|
27 | /** indicates whether this changeset is still open or not */
|
---|
28 | private boolean open;
|
---|
29 | /** the min. coordinates of the bounding box of this changeset */
|
---|
30 | private LatLon min;
|
---|
31 | /** the max. coordinates of the bounding box of this changeset */
|
---|
32 | private LatLon max;
|
---|
33 | /** the map of tags */
|
---|
34 | private Map<String,String> tags;
|
---|
35 | /** indicates whether this changeset is incomplete. For an
|
---|
36 | * incomplete changeset we only know its id
|
---|
37 | */
|
---|
38 | private boolean incomplete;
|
---|
39 | /** the changeset content */
|
---|
40 | private ChangesetDataSet content = null;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Creates a new changeset with id 0.
|
---|
44 | */
|
---|
45 | public Changeset() {
|
---|
46 | this.id = 0;
|
---|
47 | this.tags = new HashMap<String, String>();
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Creates a changeset with id <code>id</code>. If id > 0, sets incomplete to true.
|
---|
52 | *
|
---|
53 | * @param id the id
|
---|
54 | */
|
---|
55 | public Changeset(int id) {
|
---|
56 | this.id = id;
|
---|
57 | this.incomplete = id > 0;
|
---|
58 | this.tags = new HashMap<String, String>();
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Creates a clone of <code>other</code>
|
---|
63 | *
|
---|
64 | * @param other the other changeset. If null, creates a new changeset with id 0.
|
---|
65 | */
|
---|
66 | public Changeset(Changeset other) {
|
---|
67 | if (other == null) {
|
---|
68 | this.id = 0;
|
---|
69 | this.tags = new HashMap<String, String>();
|
---|
70 | } else if (other.isIncomplete()) {
|
---|
71 | setId(other.getId());
|
---|
72 | this.incomplete = true;
|
---|
73 | this.tags = new HashMap<String, String>();
|
---|
74 | } else {
|
---|
75 | this.id = other.id;
|
---|
76 | mergeFrom(other);
|
---|
77 | this.incomplete = false;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public void visit(Visitor v) {
|
---|
82 | v.visit(this);
|
---|
83 | }
|
---|
84 |
|
---|
85 | public int compareTo(Changeset other) {
|
---|
86 | return Integer.valueOf(getId()).compareTo(other.getId());
|
---|
87 | }
|
---|
88 |
|
---|
89 | public String getName() {
|
---|
90 | // no translation
|
---|
91 | return "changeset " + getId();
|
---|
92 | }
|
---|
93 |
|
---|
94 | public String getDisplayName(NameFormatter formatter) {
|
---|
95 | return formatter.format(this);
|
---|
96 | }
|
---|
97 |
|
---|
98 | public int getId() {
|
---|
99 | return id;
|
---|
100 | }
|
---|
101 |
|
---|
102 | public void setId(int id) {
|
---|
103 | this.id = id;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public User getUser() {
|
---|
107 | return user;
|
---|
108 | }
|
---|
109 |
|
---|
110 | public void setUser(User user) {
|
---|
111 | this.user = user;
|
---|
112 | }
|
---|
113 |
|
---|
114 | public Date getCreatedAt() {
|
---|
115 | return createdAt;
|
---|
116 | }
|
---|
117 |
|
---|
118 | public void setCreatedAt(Date createdAt) {
|
---|
119 | this.createdAt = createdAt;
|
---|
120 | }
|
---|
121 |
|
---|
122 | public Date getClosedAt() {
|
---|
123 | return closedAt;
|
---|
124 | }
|
---|
125 |
|
---|
126 | public void setClosedAt(Date closedAt) {
|
---|
127 | this.closedAt = closedAt;
|
---|
128 | }
|
---|
129 |
|
---|
130 | public boolean isOpen() {
|
---|
131 | return open;
|
---|
132 | }
|
---|
133 |
|
---|
134 | public void setOpen(boolean open) {
|
---|
135 | this.open = open;
|
---|
136 | }
|
---|
137 |
|
---|
138 | public LatLon getMin() {
|
---|
139 | return min;
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void setMin(LatLon min) {
|
---|
143 | this.min = min;
|
---|
144 | }
|
---|
145 |
|
---|
146 | public LatLon getMax() {
|
---|
147 | return max;
|
---|
148 | }
|
---|
149 |
|
---|
150 | public Bounds getBounds() {
|
---|
151 | if (min != null && max != null)
|
---|
152 | return new Bounds(min,max);
|
---|
153 | return null;
|
---|
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 | if (id > 0)
|
---|
235 | return id;
|
---|
236 | else
|
---|
237 | return super.hashCode();
|
---|
238 | }
|
---|
239 |
|
---|
240 | @Override
|
---|
241 | public boolean equals(Object obj) {
|
---|
242 | if (this == obj)
|
---|
243 | return true;
|
---|
244 | if (obj == null)
|
---|
245 | return false;
|
---|
246 | if (getClass() != obj.getClass())
|
---|
247 | return false;
|
---|
248 | Changeset other = (Changeset) obj;
|
---|
249 | if (this.id > 0 && other.id == this.id)
|
---|
250 | return true;
|
---|
251 | return this == obj;
|
---|
252 | }
|
---|
253 |
|
---|
254 | public boolean hasKeys() {
|
---|
255 | return !tags.keySet().isEmpty();
|
---|
256 | }
|
---|
257 |
|
---|
258 | public Collection<String> keySet() {
|
---|
259 | return tags.keySet();
|
---|
260 | }
|
---|
261 |
|
---|
262 | public boolean isNew() {
|
---|
263 | return id <= 0;
|
---|
264 | }
|
---|
265 |
|
---|
266 | public void mergeFrom(Changeset other) {
|
---|
267 | if (other == null)
|
---|
268 | return;
|
---|
269 | if (id != other.id)
|
---|
270 | return;
|
---|
271 | this.user = other.user;
|
---|
272 | this.createdAt = other.createdAt;
|
---|
273 | this.closedAt = other.closedAt;
|
---|
274 | this.open = other.open;
|
---|
275 | this.min = other.min;
|
---|
276 | this.max = other.max;
|
---|
277 | this.tags = new HashMap<String, String>(other.tags);
|
---|
278 | this.incomplete = other.incomplete;
|
---|
279 |
|
---|
280 | // FIXME: merging of content required?
|
---|
281 | this.content = other.content;
|
---|
282 | }
|
---|
283 |
|
---|
284 | public boolean hasContent() {
|
---|
285 | return content != null;
|
---|
286 | }
|
---|
287 |
|
---|
288 | public ChangesetDataSet getContent() {
|
---|
289 | return content;
|
---|
290 | }
|
---|
291 |
|
---|
292 | public void setContent(ChangesetDataSet content) {
|
---|
293 | this.content = content;
|
---|
294 | }
|
---|
295 | }
|
---|