- Timestamp:
- 2009-09-27T20:23:04+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 3 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 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java
r2186 r2206 25 25 */ 26 26 public String getRole() { 27 if (role == null)28 return "";29 27 return role; 30 28 } … … 36 34 */ 37 35 public boolean hasRole() { 38 return role != null &&!"".equals(role);36 return !"".equals(role); 39 37 } 40 38 … … 95 93 /** 96 94 * 97 * @return Member 95 * @return Member. Returned value is never null. 98 96 * @since 1937 99 97 */ … … 102 100 } 103 101 102 /** 103 * 104 * @param role Can be null, in this case it's save as "" 105 * @param member Cannot be null 106 */ 104 107 public RelationMember(String role, OsmPrimitive member) { 108 if (role == null) { 109 role = ""; 110 } 111 if (member == null) { 112 throw new IllegalArgumentException("Relation member cannot be null"); 113 } 105 114 this.role = role; 106 115 this.member = member; … … 109 118 /** 110 119 * Copy constructor. 120 * This constructor is left only for backwards compatibility. Copying RelationMember doesn't make sense 121 * because it's immutable 111 122 * @param other relation member to be copied. 112 123 */ 113 124 public RelationMember(RelationMember other) { 114 role = other.role; 115 member = other.member; 125 this(other.role, other.member); 116 126 } 117 127 … … 127 137 */ 128 138 public boolean refersTo(OsmPrimitive primitive) { 129 if (primitive == null) return false;130 if (member == null) return false;131 139 return member == primitive; 132 140 } … … 136 144 final int prime = 31; 137 145 int result = 1; 138 result = prime * result + ((member == null) ? 0 : member.hashCode());139 result = prime * result + ((role == null) ? 0 : role.hashCode());146 result = prime * result + member.hashCode(); 147 result = prime * result + role.hashCode(); 140 148 return result; 141 149 } … … 143 151 @Override 144 152 public boolean equals(Object obj) { 145 if (this == obj) 146 return true; 147 if (obj == null) 153 if (obj instanceof RelationMember) { 154 RelationMember other = (RelationMember) obj; 155 return member.equals(other.getMember()) && role.equals(other.getRole()); 156 } else { 148 157 return false; 149 if (getClass() != obj.getClass()) 150 return false; 151 RelationMember other = (RelationMember) obj; 152 if (member == null) { 153 if (other.member != null) 154 return false; 155 } else if (!member.equals(other.member)) 156 return false; 157 if (role == null) { 158 if (other.role != null) 159 return false; 160 } else if (!role.equals(other.role)) 161 return false; 162 return true; 158 } 163 159 } 164 160 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java
r2120 r2206 582 582 // System.out.println("member " + m.member + " selected " + r.selected); 583 583 584 if(m.getMember() == null) { 585 // TODO Nullable member will not be allowed after RelationMember.member is encalupsed 586 r.putError(tr("Empty member in relation."), true); 587 } else if(m.getMember().isDeleted()) { 584 if (m.getMember().isDeleted()) { 588 585 r.putError(tr("Deleted member ''{0}'' in relation.", 589 586 m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true); … … 678 675 if("-1".equals(onewayviastr)) { 679 676 onewayvia = true; 680 Node t = firstNode;681 677 firstNode = lastNode; 682 678 lastNode = firstNode; … … 851 847 for (RelationMember m : r.getMembers()) 852 848 { 853 if(m.getMember() == null) { 854 //TODO Remove useless nullcheck when RelationMember.member is encalupsed 855 r.putError(tr("Empty member in relation."), true); 856 } else if(m.getMember().isDeleted()) { 849 if (m.getMember().isDeleted()) { 857 850 r.putError(tr("Deleted member ''{0}'' in relation.", 858 851 m.getMember().getDisplayName(DefaultNameFormatter.getInstance())), true);
Note:
See TracChangeset
for help on using the changeset viewer.