Changeset 86 in josm for src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
- Timestamp:
- 2006-04-21T14:31:51+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r81 r86 8 8 import java.util.Map.Entry; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 11 … … 38 37 39 38 /** 40 * <code>true</code>, if the objects content (not the properties) has been 41 * modified since it was loaded from the server. In this case, on next upload, 42 * this object will be updated. Deleted objects are deleted from the server. 43 * If the objects are added (id=0), the modified is ignored and the object is 44 * added to the server. 39 * <code>true</code>, if the object has been modified since it was loaded from 40 * the server. In this case, on next upload, this object will be updated. 41 * Deleted objects are deleted from the server. If the objects are added (id=0), 42 * the modified is ignored and the object is added to the server. 45 43 */ 46 44 public boolean modified = false; 47 45 48 46 /** 49 * <code>true</code>, if the object's keys has been changed by JOSM since50 * last update.51 */52 public boolean modifiedProperties = false;53 54 /**55 47 * <code>true</code>, if the object has been deleted. 56 48 */ 57 p rivateboolean deleted = false;49 public boolean deleted = false; 58 50 59 51 /** 60 52 * If set to true, this object is currently selected. 61 53 */ 62 p rivate boolean selected = false;54 public volatile boolean selected = false; 63 55 64 56 /** … … 67 59 * used to check against edit conflicts. 68 60 */ 69 public Date lastModified= null;61 public Date timestamp = null; 70 62 71 63 /** … … 76 68 abstract public void visit(Visitor visitor); 77 69 78 /** 79 * Return <code>true</code>, if either <code>this.keys</code> and 80 * <code>other.keys</code> is <code>null</code> or if they do not share Keys 81 * with different values. 82 * 83 * @param other The second key-set to compare with. 84 * @return True, if the keysets are mergable 85 */ 86 final public boolean keyPropertiesMergable(OsmPrimitive other) { 87 if ((keys == null) != (other.keys == null)) 88 return false; 89 90 if (keys != null) { 91 for (String k : keys.keySet()) 92 if (other.keys.containsKey(k) && !keys.get(k).equals(other.keys.get(k))) 93 return false; 94 for (String k : other.keys.keySet()) 95 if (keys.containsKey(k) && !other.keys.get(k).equals(keys.get(k))) 96 return false; 97 } 98 return true; 99 } 100 101 /** 102 * Mark the primitive as selected or not selected and fires a selection 103 * changed later, if the value actualy changed. 104 * @param selected Whether the primitive should be selected or not. 105 */ 106 final public void setSelected(boolean selected) { 107 if (selected != this.selected) 108 Main.main.ds.fireSelectionChanged(); 109 this.selected = selected; 110 } 111 112 /** 113 * @return Return whether the primitive is selected on screen. 114 */ 115 final public boolean isSelected() { 116 return selected; 117 } 118 119 120 public void setDeleted(boolean deleted) { 70 public final void delete(boolean deleted) { 121 71 this.deleted = deleted; 122 setSelected(false); 123 } 124 125 public boolean isDeleted() { 126 return deleted; 72 selected = false; 73 modified = true; 127 74 } 128 75 … … 133 80 * An primitive is equal to its incomplete counter part. 134 81 */ 135 @Override 136 public boolean equals(Object obj) { 82 @Override public final boolean equals(Object obj) { 137 83 if (obj == null || getClass() != obj.getClass() || id == 0 || ((OsmPrimitive)obj).id == 0) 138 84 return super.equals(obj); … … 145 91 * An primitive has the same hashcode as its incomplete counter part. 146 92 */ 147 @Override 148 public int hashCode() { 93 @Override public final int hashCode() { 149 94 return id == 0 ? super.hashCode() : (int)id; 150 95 } … … 155 100 * @param value The value for the key. 156 101 */ 157 public void put(String key, String value) { 158 if (keys == null) 159 keys = new HashMap<String, String>(); 160 keys.put(key, value); 102 public final void put(String key, String value) { 103 if (value == null) 104 remove(key); 105 else { 106 if (keys == null) 107 keys = new HashMap<String, String>(); 108 keys.put(key, value); 109 } 161 110 } 162 111 /** 163 112 * Remove the given key from the list. 164 113 */ 165 public void remove(String key) {114 public final void remove(String key) { 166 115 if (keys != null) { 167 116 keys.remove(key); … … 171 120 } 172 121 173 public String get(String key) {122 public final String get(String key) { 174 123 return keys == null ? null : keys.get(key); 175 124 } 176 177 public Collection<Entry<String, String>> entrySet() {125 126 public final Collection<Entry<String, String>> entrySet() { 178 127 if (keys == null) 179 128 return Collections.emptyList(); … … 181 130 } 182 131 183 public Collection<String> keySet() {132 public final Collection<String> keySet() { 184 133 if (keys == null) 185 134 return Collections.emptyList(); … … 192 141 */ 193 142 public void cloneFrom(OsmPrimitive osm) { 194 keys = osm.keys ;143 keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys); 195 144 id = osm.id; 196 145 modified = osm.modified; 197 modifiedProperties = osm.modifiedProperties;198 146 deleted = osm.deleted; 199 147 selected = osm.selected; 200 lastModified = osm.lastModified; 148 timestamp = osm.timestamp; 149 } 150 151 /** 152 * Perform an equality compare for all non-volatile fields not only for the id 153 * but for the whole object (for conflict resolving etc) 154 */ 155 public boolean realEqual(OsmPrimitive osm) { 156 return 157 id == osm.id && 158 modified == osm.modified && 159 deleted == osm.deleted && 160 (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp)) && 161 (keys == null ? osm.keys==null : keys.equals(osm.keys)); 201 162 } 202 163 }
Note:
See TracChangeset
for help on using the changeset viewer.