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

Last change on this file since 625 was 625, checked in by framm, 16 years ago
  • forgot to add new classes from kleptog's 0.6 patch.
File size: 3.3 KB
Line 
1// License: GPL. Copyright 2007 by Martijn van Oosterhout and others
2package org.openstreetmap.josm.data.osm;
3
4import org.openstreetmap.josm.Main;
5import org.openstreetmap.josm.io.XmlWriter;
6import org.openstreetmap.josm.io.XmlWriter.OsmWriterInterface;
7import java.io.PrintWriter;
8import java.util.Map;
9import java.util.Map.Entry;
10import java.util.HashMap;
11import java.util.Collections;
12import java.util.Collection;
13
14
15
16/**
17 * Represents a single changeset in JOSM. For now its only used during
18 * upload but in the future we may do more.
19 *
20 */
21public final class Changeset /*extends OsmPrimitive*/ implements OsmWriterInterface {
22 /**
23 * The key/value list for this primitive.
24 */
25 public Map<String, String> keys;
26
27 public long id = 0;
28
29 /**
30 * User that created thos changeset, as specified by the server.
31 * Never changed by JOSM.
32 */
33 public User user = null;
34
35 /**
36 * Time of last modification to this object. This is not set by JOSM but
37 * read from the server and delivered back to the server unmodified.
38 */
39 public String end_timestamp = null;
40
41 /**
42 * Time of first modification to this object. This is not set by JOSM but
43 * read from the server and delivered back to the server unmodified.
44 */
45 public String start_timestamp = null;
46
47 private void addTags(PrintWriter out) {
48 if (this.keys != null) {
49 for (Entry<String, String> e : this.keys.entrySet())
50 out.println(" <tag k='"+ XmlWriter.encode(e.getKey()) +
51 "' v='"+XmlWriter.encode(e.getValue())+ "' />");
52 }
53 }
54
55 public final void header(PrintWriter out) {
56 out.print("<osm version='");
57 out.print(Main.pref.get("osm-server.version", "0.6"));
58 out.println("' generator='JOSM'>");
59 }
60 public final void write(PrintWriter out) {
61 out.print(" <changeset");
62 if (id != 0)
63 out.print(" id="+id);
64 if (this.user != null) {
65 out.print(" user='"+XmlWriter.encode(this.user.name)+"'");
66 }
67 out.println(">\n");
68 addTags( out );
69 out.println(" </changeset>");
70 }
71 public final void footer(PrintWriter out) {
72 out.println("</osm>");
73 }
74
75 /******************************************************
76 * This tag stuff is copied from OsmPrimitive. Perhaps a changeset
77 * really is a primitive, but it's not right now. Perhaps it should
78 * be...
79 ******************************************************/
80
81 /**
82 * Set the given value to the given key
83 * @param key The key, for which the value is to be set.
84 * @param value The value for the key.
85 */
86 public final void put(String key, String value) {
87 if (value == null)
88 remove(key);
89 else {
90 if (keys == null)
91 keys = new HashMap<String, String>();
92 keys.put(key, value);
93 }
94 }
95 /**
96 * Remove the given key from the list.
97 */
98 public final void remove(String key) {
99 if (keys != null) {
100 keys.remove(key);
101 if (keys.isEmpty())
102 keys = null;
103 }
104 }
105
106 public final String get(String key) {
107 return keys == null ? null : keys.get(key);
108 }
109
110 public final Collection<Entry<String, String>> entrySet() {
111 if (keys == null)
112 return Collections.emptyList();
113 return keys.entrySet();
114 }
115
116 public final Collection<String> keySet() {
117 if (keys == null)
118 return Collections.emptyList();
119 return keys.keySet();
120 }
121}
Note: See TracBrowser for help on using the repository browser.