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

Last change on this file since 2615 was 2613, checked in by Gubaer, 14 years ago

new: global in-memory cache for downloaded changesets
new: toggle dialog for changesets
new: downloading of changesets (currently without changeset content, will follow later)

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