Changeset 2206 in josm for trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
- Timestamp:
- 2009-09-27T20:23:04+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2188 r2206 35 35 abstract public class OsmPrimitive implements Comparable<OsmPrimitive>, Tagged { 36 36 37 private static final int FLAG_MODIFIED = 1 << 0; 38 private static final int FLAG_VISIBLE = 1 << 1; 39 private static final int FLAG_DISABLED = 1 << 2; 40 private static final int FLAG_DELETED = 1 << 3; 41 private static final int FLAG_FILTERED = 1 << 4; 42 private static final int FLAG_SELECTED = 1 << 5; 43 37 44 /** 38 45 * Replies the sub-collection of {@see OsmPrimitive}s of type <code>type</code> present in 39 46 * another collection of {@see OsmPrimitive}s. The result collection is a list. 40 * 47 * 41 48 * If <code>list</code> is null, replies an empty list. 42 * 49 * 43 50 * @param <T> 44 51 * @param list the original list … … 60 67 * Replies the sub-collection of {@see OsmPrimitive}s of type <code>type</code> present in 61 68 * another collection of {@see OsmPrimitive}s. The result collection is a set. 62 * 69 * 63 70 * If <code>list</code> is null, replies an empty set. 64 * 71 * 65 72 * @param <T> 66 73 * @param list the original collection … … 117 124 private long id = 0; 118 125 119 /** 120 * <code>true</code> if the object has been modified since it was loaded from 121 * the server. In this case, on next upload, this object will be updated. 122 * Deleted objects are deleted from the server. If the objects are added (id=0), 123 * the modified is ignored and the object is added to the server. 124 * 125 */ 126 private boolean modified = false; 127 128 /** 129 * <code>true</code>, if the object has been deleted. 130 * 131 */ 132 private boolean deleted = false; 133 134 /** 135 * Visibility status as specified by the server. The visible attribute was 136 * introduced with the 0.4 API to be able to communicate deleted objects 137 * (they will have visible=false). 138 * 139 */ 140 private boolean visible = true; 141 142 /** 143 * <code>true</code>, if the object has been set inactive 144 * 145 */ 146 private boolean disabled = false; 147 148 /** 149 * <code>true</code>, if the object has been filtered out 150 * 151 */ 152 private boolean filtered = false; 126 private volatile byte flags; 127 153 128 154 129 /** … … 157 132 */ 158 133 public User user = null; 159 160 /**161 * If set to true, this object is currently selected.162 *163 */164 private volatile boolean selected = false;165 134 166 135 /** … … 208 177 */ 209 178 public void setDisabled(boolean disabled) { 210 this.disabled = disabled; 179 if (disabled) { 180 flags |= FLAG_DISABLED; 181 } else { 182 flags &= ~FLAG_DISABLED; 183 } 184 211 185 } 212 186 … … 217 191 */ 218 192 public boolean isDisabled() { 219 return disabled;193 return (flags & FLAG_DISABLED) != 0; 220 194 } 221 195 /** … … 225 199 */ 226 200 public void setFiltered(boolean filtered) { 227 this.filtered = filtered; 201 if (filtered) { 202 flags |= FLAG_FILTERED; 203 } else { 204 flags &= ~FLAG_FILTERED; 205 } 228 206 } 229 207 /** … … 233 211 */ 234 212 public boolean isFiltered() { 235 return filtered;213 return (flags & FLAG_FILTERED) != 0; 236 214 } 237 215 … … 243 221 */ 244 222 public void setSelected(boolean selected) { 245 this.selected = selected; 223 if (selected) { 224 flags |= FLAG_SELECTED; 225 } else { 226 flags &= ~FLAG_SELECTED; 227 } 246 228 } 247 229 /** … … 252 234 */ 253 235 public boolean isSelected() { 254 return selected;236 return (flags & FLAG_SELECTED) != 0; 255 237 } 256 238 … … 261 243 */ 262 244 public void setModified(boolean modified) { 263 this.modified = modified; 245 if (modified) { 246 flags |= FLAG_MODIFIED; 247 } else { 248 flags &= ~FLAG_MODIFIED; 249 } 264 250 } 265 251 … … 268 254 * the server. In this case, on next upload, this object will be updated. 269 255 * 256 * Deleted objects are deleted from the server. If the objects are added (id=0), 257 * the modified is ignored and the object is added to the server. 258 * 270 259 * @return <code>true</code> if the object has been modified since it was loaded from 271 260 * the server 272 261 */ 273 262 public boolean isModified() { 274 return modified;263 return (flags & FLAG_MODIFIED) != 0; 275 264 } 276 265 … … 282 271 */ 283 272 public boolean isDeleted() { 284 return deleted;273 return (flags & FLAG_DELETED) != 0; 285 274 } 286 275 … … 292 281 */ 293 282 public boolean isUsable() { 294 return ! deleted&& !incomplete && !disabled;283 return !isDeleted() && !incomplete && !isDisabled(); 295 284 } 296 285 … … 304 293 */ 305 294 public boolean isVisible() { 306 return visible;295 return (flags & FLAG_VISIBLE) != 0; 307 296 } 308 297 … … 318 307 if (id == 0 && visible == false) 319 308 throw new IllegalStateException(tr("A primitive with ID = 0 can't be invisible.")); 320 this.visible = visible; 309 if (visible) { 310 flags |= FLAG_VISIBLE; 311 } else { 312 flags &= ~FLAG_VISIBLE; 313 } 321 314 } 322 315 … … 456 449 */ 457 450 public void setDeleted(boolean deleted) { 458 this.modified = deleted; 459 this.deleted = deleted; 460 this.selected = false; 451 if (deleted) { 452 flags |= FLAG_DELETED; 453 } else { 454 flags &= ~FLAG_DELETED; 455 } 456 setModified(deleted); 457 setSelected(false); 461 458 } 462 459 … … 623 620 keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys); 624 621 id = osm.id; 625 modified = osm.modified;626 deleted = osm.deleted;627 setSelected(osm.isSelected());628 622 timestamp = osm.timestamp; 629 623 version = osm.version; 630 624 incomplete = osm.incomplete; 631 visible= osm.visible;625 flags = osm.flags; 632 626 clearCached(); 633 627 clearErrors(); … … 674 668 675 669 return 676 deleted== other.deleted677 && modified== other.modified670 isDeleted() == other.isDeleted() 671 && isModified() == other.isModified() 678 672 && timestamp == other.timestamp 679 673 && version == other.version 680 && visible== other.visible674 && isVisible() == other.isVisible() 681 675 && (user == null ? other.user==null : user==other.user); 682 676 }
Note:
See TracChangeset
for help on using the changeset viewer.
