Ignore:
Timestamp:
2007-10-11T21:35:15+02:00 (17 years ago)
Author:
framm
Message:
  • alleviated #388 by parsing the timestamps only when they are needed.
Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

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

    r343 r362  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.text.ParseException;
    45import java.text.SimpleDateFormat;
    56import java.util.ArrayList;
     
    1213
    1314import org.openstreetmap.josm.data.osm.visitor.Visitor;
     15import org.openstreetmap.josm.tools.DateParser;
    1416
    1517
     
    8890         * used to check against edit conflicts.
    8991         */
    90         public Date timestamp = null;
    91 
     92        public String timestamp = null;
     93       
     94        /**
     95         * The timestamp is only parsed when this is really necessary, and this
     96         * is the cache for the result.
     97         */
     98        public Date parsedTimestamp = null;
     99       
    92100        /**
    93101         * If set to true, this object is incomplete, which means only the id
     
    108116                modified = true;
    109117        }
     118       
     119        /**
     120         * Returns the timestamp for this object, or the current time if none is set.
     121         * Internally, parses the timestamp from XML into a Date object and caches it
     122         * for possible repeated calls.
     123         */
     124        public Date getTimestamp() {
     125                if (parsedTimestamp == null) {
     126                        try {
     127                                parsedTimestamp = DateParser.parse(timestamp);
     128                        } catch (ParseException ex) {
     129                                parsedTimestamp = new Date();
     130                        }
     131                }
     132                return parsedTimestamp;
     133        }
    110134
    111135        /**
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r343 r362  
    288288        private <P extends OsmPrimitive> boolean mergeAfterId(Map<P,P> merged, Collection<P> primitives, P other) {
    289289                for (P my : primitives) {
    290                         Date d1 = my.timestamp == null ? new Date(0) : my.timestamp;
    291                         Date d2 = other.timestamp == null ? new Date(0) : other.timestamp;
    292290                        if (my.realEqual(other, false)) {
    293291                                if (merged != null)
     
    299297                                if (merged != null)
    300298                                        merged.put(other, my);
    301                                 if (d1.before(d2)) {
     299                                if (my.getTimestamp().before(other.getTimestamp())) {
    302300                                        my.modified = other.modified;
    303301                                        my.timestamp = other.timestamp;
     
    311309                                                merged.put(other, my);
    312310                                } else if (!my.modified && !other.modified) {
    313                                         if (d1.before(d2)) {
     311                                        if (my.getTimestamp().before(other.getTimestamp())) {
    314312                                                cloneFromExceptIncomplete(my, other);
    315313                                                if (merged != null)
     
    317315                                        }
    318316                                } else if (other.modified) {
    319                                         if (d1.after(d2)) {
     317                                        if (my.getTimestamp().after(other.getTimestamp())) {
    320318                                                conflicts.put(my, other);
    321319                                                if (merged != null)
     
    327325                                        }
    328326                                } else if (my.modified) {
    329                                         if (d2.after(d1)) {
     327                                        if (my.getTimestamp().before(other.getTimestamp())) {
    330328                                                conflicts.put(my, other);
    331329                                                if (merged != null)
Note: See TracChangeset for help on using the changeset viewer.