Ignore:
Timestamp:
2006-04-21T14:31:51+02:00 (18 years ago)
Author:
imi
Message:
  • added conflicts and resolve conflict dialog

This is one of those "changed everything" checkpoint.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r81 r86  
    88import java.util.Map.Entry;
    99
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1211
     
    3837
    3938        /**
    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.
    4543         */
    4644        public boolean modified = false;
    4745
    4846        /**
    49          * <code>true</code>, if the object's keys has been changed by JOSM since
    50          * last update.
    51          */
    52         public boolean modifiedProperties = false;
    53        
    54         /**
    5547         * <code>true</code>, if the object has been deleted.
    5648         */
    57         private boolean deleted = false;
     49        public boolean deleted = false;
    5850
    5951        /**
    6052         * If set to true, this object is currently selected.
    6153         */
    62         private boolean selected = false;
     54        public volatile boolean selected = false;
    6355
    6456        /**
     
    6759         * used to check against edit conflicts.
    6860         */
    69         public Date lastModified = null;
     61        public Date timestamp = null;
    7062
    7163        /**
     
    7668        abstract public void visit(Visitor visitor);
    7769
    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) {
    12171                this.deleted = deleted;
    122                 setSelected(false);
    123         }
    124 
    125         public boolean isDeleted() {
    126                 return deleted;
     72                selected = false;
     73                modified = true;
    12774        }
    12875
     
    13380         * An primitive is equal to its incomplete counter part.
    13481         */
    135         @Override
    136         public boolean equals(Object obj) {
     82        @Override public final boolean equals(Object obj) {
    13783                if (obj == null || getClass() != obj.getClass() || id == 0 || ((OsmPrimitive)obj).id == 0)
    13884                        return super.equals(obj);
     
    14591         * An primitive has the same hashcode as its incomplete counter part.
    14692         */
    147         @Override
    148         public int hashCode() {
     93        @Override public final int hashCode() {
    14994                return id == 0 ? super.hashCode() : (int)id;
    15095        }
     
    155100         * @param value The value for the key.
    156101         */
    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                }
    161110        }
    162111        /**
    163112         * Remove the given key from the list.
    164113         */
    165         public void remove(String key) {
     114        public final void remove(String key) {
    166115                if (keys != null) {
    167116                        keys.remove(key);
     
    171120        }
    172121
    173         public String get(String key) {
     122        public final String get(String key) {
    174123                return keys == null ? null : keys.get(key);
    175124        }
    176        
    177         public Collection<Entry<String, String>> entrySet() {
     125
     126        public final Collection<Entry<String, String>> entrySet() {
    178127                if (keys == null)
    179128                        return Collections.emptyList();
     
    181130        }
    182131
    183         public Collection<String> keySet() {
     132        public final Collection<String> keySet() {
    184133                if (keys == null)
    185134                        return Collections.emptyList();
     
    192141         */
    193142        public void cloneFrom(OsmPrimitive osm) {
    194                 keys = osm.keys;
     143                keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys);
    195144                id = osm.id;
    196145                modified = osm.modified;
    197                 modifiedProperties = osm.modifiedProperties;
    198146                deleted = osm.deleted;
    199147                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));
    201162        }
    202163}
Note: See TracChangeset for help on using the changeset viewer.