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

Last change on this file since 16451 was 16451, checked in by simon04, 4 years ago

see #19251 - Java warning, FindBugs

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.io.IOException;
5import java.io.ObjectInputStream;
6import java.io.ObjectOutputStream;
7import java.io.Serializable;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.Collections;
11import java.util.List;
12import java.util.Map;
13import java.util.stream.Collectors;
14
15import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
16import org.openstreetmap.josm.gui.mappaint.StyleCache;
17
18/**
19 * This class can be used to save properties of OsmPrimitive.
20 *
21 * The main difference between PrimitiveData
22 * and OsmPrimitive is that PrimitiveData is not part of the dataset and changes in PrimitiveData are not
23 * reported by events
24 */
25public abstract class PrimitiveData extends AbstractPrimitive implements Serializable {
26
27 private static final long serialVersionUID = -1044837092478109138L;
28
29 /**
30 * Constructs a new {@code PrimitiveData} with given id.
31 * @param id id
32 * @since 12017
33 */
34 public PrimitiveData(long id) {
35 this.id = id;
36 }
37
38 /**
39 * Constructs a new {@code PrimitiveData} from an existing one.
40 * @param data the data to copy
41 */
42 public PrimitiveData(PrimitiveData data) {
43 cloneFrom(data);
44 }
45
46 /**
47 * Sets the primitive identifier.
48 * @param id primitive identifier
49 */
50 public void setId(long id) {
51 this.id = id;
52 }
53
54 /**
55 * Sets the primitive version.
56 * @param version primitive version
57 */
58 public void setVersion(int version) {
59 this.version = version;
60 }
61
62 /**
63 * override to make it public
64 */
65 @Override
66 public void setIncomplete(boolean incomplete) {
67 super.setIncomplete(incomplete);
68 }
69
70 /**
71 * Returns a copy of this primitive data.
72 * @return a copy of this primitive data
73 */
74 public abstract PrimitiveData makeCopy();
75
76 @Override
77 public String toString() {
78 StringBuilder builder = new StringBuilder();
79 builder.append(id).append(' ').append(Arrays.toString(keys)).append(' ').append(getFlagsAsString());
80 return builder.toString();
81 }
82
83 /**
84 * Returns a filtered list for a given primitive type.
85 * @param <T> primitive type
86 * @param list list to filter
87 * @param type primitive type
88 * @return a filtered list for given primitive type
89 * @deprecated Use {@link Collection#stream()} instead
90 */
91 @Deprecated
92 public static <T extends PrimitiveData> List<T> getFilteredList(Collection<T> list, OsmPrimitiveType type) {
93 return list.stream().filter(p -> type.getDataClass().isInstance(p)).collect(Collectors.toList());
94 }
95
96 @Override
97 protected final void keysChangedImpl(Map<String, String> originalKeys) {
98 }
99
100 private void writeObject(ObjectOutputStream oos) throws IOException {
101 // since super class is not Serializable
102 oos.writeLong(id);
103 oos.writeLong(user == null ? -1 : user.getId());
104 oos.writeInt(version);
105 oos.writeInt(changesetId);
106 oos.writeInt(timestamp);
107 oos.writeObject(keys);
108 oos.writeShort(flags);
109 oos.defaultWriteObject();
110 }
111
112 private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
113 // since super class is not Serializable
114 id = ois.readLong();
115 final long userId = ois.readLong();
116 user = userId == -1 ? null : User.getById(userId);
117 version = ois.readInt();
118 changesetId = ois.readInt();
119 timestamp = ois.readInt();
120 keys = (String[]) ois.readObject();
121 flags = ois.readShort();
122 ois.defaultReadObject();
123 }
124
125 @Override
126 public boolean isTagged() {
127 return hasKeys();
128 }
129
130 @Override
131 public boolean isAnnotated() {
132 return false;
133 }
134
135 @Override
136 public boolean hasDirectionKeys() {
137 return false;
138 }
139
140 @Override
141 public boolean reversedDirection() {
142 return false;
143 }
144
145 @Override
146 public void setHighlighted(boolean highlighted) {
147 // Override if needed
148 }
149
150 @Override
151 public boolean isHighlighted() {
152 return false;
153 }
154
155 @Override
156 public final List<PrimitiveData> getReferrers(boolean allowWithoutDataset) {
157 return Collections.emptyList();
158 }
159
160 @Override
161 public void visitReferrers(PrimitiveVisitor visitor) {
162 // Override if needed
163 }
164
165 @Override
166 public OsmData<?, ?, ?, ?> getDataSet() {
167 return null;
168 }
169
170 @Override
171 public StyleCache getCachedStyle() {
172 return null;
173 }
174
175 @Override
176 public void setCachedStyle(StyleCache mappaintStyle) {
177 // Override if needed
178 }
179
180 @Override
181 public boolean isCachedStyleUpToDate() {
182 return false;
183 }
184
185 @Override
186 public void declareCachedStyleUpToDate() {
187 // Override if needed
188 }
189}
Note: See TracBrowser for help on using the repository browser.