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

Last change on this file since 2552 was 2512, checked in by stoecker, 15 years ago

i18n updated, fixed files to reduce problems when applying patches, fix #4017

  • Property svn:mime-type set to text/plain
File size: 4.1 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 }
39
40 private final Map<String, String> keys = new HashMap<String, String>();
41 private boolean modified;
42 private boolean visible = true;
43 private boolean deleted;
44 private long id;
45 private User user;
46 private int version;
47 private int timestamp;
48
49 public boolean isModified() {
50 return modified;
51 }
52 public void setModified(boolean modified) {
53 this.modified = modified;
54 }
55 public boolean isVisible() {
56 return visible;
57 }
58 public void setVisible(boolean visible) {
59 this.visible = visible;
60 }
61 public boolean isDeleted() {
62 return deleted;
63 }
64 public void setDeleted(boolean deleted) {
65 this.deleted = deleted;
66 }
67 public long getId() {
68 return id;
69 }
70 public void setId(long id) {
71 this.id = id;
72 }
73 public User getUser() {
74 return user;
75 }
76 public void setUser(User user) {
77 this.user = user;
78 }
79 public int getVersion() {
80 return version;
81 }
82 public void setVersion(int version) {
83 this.version = version;
84 }
85 public int getTimestamp() {
86 return timestamp;
87 }
88 public void setTimestamp(int timestamp) {
89 this.timestamp = timestamp;
90 }
91 public Map<String, String> getKeys() {
92 return keys;
93 }
94
95 public void clearOsmId() {
96 id = OsmPrimitive.generateUniqueId();
97 }
98
99 public abstract PrimitiveData makeCopy();
100
101 @Override
102 public String toString() {
103 StringBuilder builder = new StringBuilder();
104
105 builder.append(id).append(keys);
106 if (modified) {
107 builder.append("M");
108 }
109 if (visible) {
110 builder.append("V");
111 }
112 if (deleted) {
113 builder.append("D");
114 }
115
116 return builder.toString();
117 }
118
119 // Tagged implementation
120
121 public String get(String key) {
122 return keys.get(key);
123 }
124
125 public boolean hasKeys() {
126 return !keys.isEmpty();
127 }
128
129 public Collection<String> keySet() {
130 return keys.keySet();
131 }
132
133 public void put(String key, String value) {
134 keys.put(key, value);
135 }
136
137 public void remove(String key) {
138 keys.remove(key);
139 }
140
141 public void removeAll() {
142 keys.clear();
143 }
144
145 public void setKeys(Map<String, String> keys) {
146 this.keys.clear();
147 this.keys.putAll(keys);
148 }
149
150 @SuppressWarnings("unchecked")
151 static public <T extends PrimitiveData> List<T> getFilteredList(Collection<T> list, OsmPrimitiveType type) {
152 List<T> ret = new ArrayList<T>();
153 for(PrimitiveData p: list) {
154 if (type.getDataClass().isInstance(p)) {
155 ret.add((T)p);
156 }
157 }
158 return ret;
159 }
160
161 protected void setKeysAsList(String... keys) {
162 assert keys.length % 2 == 0;
163 for (int i=0; i<keys.length/2; i++) {
164 this.keys.put(keys[i * 2], keys[i * 2 + 1]);
165 }
166 }
167
168 /**
169 * PrimitiveId implementation. Returns the same value as getId()
170 */
171 public long getUniqueId() {
172 return id;
173 }
174
175}
Note: See TracBrowser for help on using the repository browser.