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

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

store incomplete flag in PrimitiveData

  • Property svn:mime-type set to text/plain
File size: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.ArrayList;
5import java.util.Collection;
6import java.util.HashMap;
7import java.util.List;
8import java.util.Map;
9
10/**
11 *
12 * This class can be used to save properties of OsmPrimitive. The main difference between PrimitiveData
13 * and OsmPrimitive is that PrimitiveData is not part of the dataset and changes in PrimitiveData are not
14 * reported by events
15 *
16 */
17public abstract class PrimitiveData implements Tagged, PrimitiveId {
18
19 // Useful?
20 //private boolean disabled;
21 //private boolean filtered;
22 //private boolean selected;
23 //private boolean highlighted;
24
25 public PrimitiveData() {
26 id = OsmPrimitive.generateUniqueId();
27 }
28
29 public PrimitiveData(PrimitiveData data) {
30 this.keys.putAll(data.keys);
31 this.modified = data.modified;
32 this.visible = data.visible;
33 this.deleted = data.deleted;
34 this.id = data.id;
35 this.user = data.user;
36 this.version = data.version;
37 this.timestamp = data.timestamp;
38 this.incomplete = data.incomplete;
39 }
40
41 private final Map<String, String> keys = new HashMap<String, String>();
42 private boolean modified;
43 private boolean visible = true;
44 private boolean deleted;
45 private boolean incomplete;
46 private long id;
47 private User user;
48 private int version;
49 private int timestamp;
50 private int changesetId;
51
52 public boolean isModified() {
53 return modified;
54 }
55 public void setModified(boolean modified) {
56 this.modified = modified;
57 }
58 public boolean isVisible() {
59 return visible;
60 }
61 public void setVisible(boolean visible) {
62 this.visible = visible;
63 }
64 public boolean isDeleted() {
65 return deleted;
66 }
67 public void setDeleted(boolean deleted) {
68 this.deleted = deleted;
69 }
70 public long getId() {
71 return id;
72 }
73 public void setId(long id) {
74 this.id = id;
75 }
76 public User getUser() {
77 return user;
78 }
79 public void setUser(User user) {
80 this.user = user;
81 }
82 public int getVersion() {
83 return version;
84 }
85 public void setVersion(int version) {
86 this.version = version;
87 }
88 public int getTimestamp() {
89 return timestamp;
90 }
91 public void setTimestamp(int timestamp) {
92 this.timestamp = timestamp;
93 }
94
95 public int getChangesetId() {
96 return changesetId;
97 }
98
99 public void setChangesetId(int changesetId) {
100 this.changesetId = changesetId;
101 }
102
103 public Map<String, String> getKeys() {
104 return keys;
105 }
106 public boolean isIncomplete() {
107 return incomplete;
108 }
109 public void setIncomplete(boolean incomplete) {
110 this.incomplete = incomplete;
111 }
112
113 public void clearOsmId() {
114 id = OsmPrimitive.generateUniqueId();
115 }
116
117 public abstract PrimitiveData makeCopy();
118
119 @Override
120 public String toString() {
121 StringBuilder builder = new StringBuilder();
122
123 builder.append(id).append(keys);
124 if (modified) {
125 builder.append("M");
126 }
127 if (visible) {
128 builder.append("V");
129 }
130 if (deleted) {
131 builder.append("D");
132 }
133 if (incomplete) {
134 builder.append("I");
135 }
136
137 return builder.toString();
138 }
139
140 // Tagged implementation
141
142 public String get(String key) {
143 return keys.get(key);
144 }
145
146 public boolean hasKeys() {
147 return !keys.isEmpty();
148 }
149
150 public Collection<String> keySet() {
151 return keys.keySet();
152 }
153
154 public void put(String key, String value) {
155 keys.put(key, value);
156 }
157
158 public void remove(String key) {
159 keys.remove(key);
160 }
161
162 public void removeAll() {
163 keys.clear();
164 }
165
166 public void setKeys(Map<String, String> keys) {
167 this.keys.clear();
168 this.keys.putAll(keys);
169 }
170
171 @SuppressWarnings("unchecked")
172 static public <T extends PrimitiveData> List<T> getFilteredList(Collection<T> list, OsmPrimitiveType type) {
173 List<T> ret = new ArrayList<T>();
174 for(PrimitiveData p: list) {
175 if (type.getDataClass().isInstance(p)) {
176 ret.add((T)p);
177 }
178 }
179 return ret;
180 }
181
182 protected void setKeysAsList(String... keys) {
183 assert keys.length % 2 == 0;
184 for (int i=0; i<keys.length/2; i++) {
185 this.keys.put(keys[i * 2], keys[i * 2 + 1]);
186 }
187 }
188
189 /**
190 * PrimitiveId implementation. Returns the same value as getId()
191 */
192 public long getUniqueId() {
193 return id;
194 }
195
196 public boolean isNew() {
197 return id <= 0;
198 }
199}
Note: See TracBrowser for help on using the repository browser.