Changeset 1499 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-03-18T16:13:41+01:00 (16 years ago)
Author:
stoecker
Message:

close #2302 - patch by jttt - optimizations and encapsulation

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r1415 r1499  
    254254            if (selectedWay.keys != null) {
    255255                wayToAdd.keys = new HashMap<String, String>(selectedWay.keys);
    256                 wayToAdd.checkTagged();
    257                 wayToAdd.checkDirectionTagged();
    258256            }
    259257            newWays.add(wayToAdd);
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r1429 r1499  
    140140        Node c = new Node(selectedNode);
    141141        c.keys = null;
    142         c.tagged = false;
    143142        c.selected = false;
    144143        cmds.add(new ChangeCommand(selectedNode, c));
     
    189188       
    190189        selectedNode = (Node)n;
    191         return  selectedNode.tagged;
     190        return  selectedNode.isTagged();
    192191    }
    193192
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r1389 r1499  
    1717import org.openstreetmap.josm.data.osm.User;
    1818import org.openstreetmap.josm.data.osm.Way;
     19import org.openstreetmap.josm.tools.DateUtils;
    1920
    2021/**
     
    146147
    147148                if (key.equals("timestamp"))
    148                     value = osm.getTimeStr();
     149                    value = DateUtils.fromDate(osm.getTimestamp());
    149150                else
    150151                    value = osm.get(key);
     
    315316    private static class Untagged extends Match {
    316317        @Override public boolean match(OsmPrimitive osm) {
    317             return !osm.tagged;
     318            return !osm.isTagged();
    318319        }
    319320        @Override public String toString() {return "untagged";}
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r1463 r1499  
    189189                if (osm instanceof Way) {
    190190                    for (Node n : ((Way) osm).nodes) {
    191                         if (!n.tagged) {
     191                        if (!n.isTagged()) {
    192192                            CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds, false);
    193193                            n.visit(v);
     
    322322            if (wnew.keys != null) {
    323323                wnew2.keys = new HashMap<String, String>(wnew.keys);
    324                 wnew2.checkTagged();
    325                 wnew2.checkDirectionTagged();
    326324            }
    327325            wnew2.nodes.addAll(n2);
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r1489 r1499  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.text.ParseException;
    7 import java.text.SimpleDateFormat;
     6import java.util.ArrayList;
    87import java.util.Arrays;
    9 import java.util.ArrayList;
    108import java.util.Collection;
    119import java.util.Collections;
    1210import java.util.Date;
    1311import java.util.HashMap;
    14 import java.util.HashSet;
    1512import java.util.Map;
    1613import java.util.Map.Entry;
    1714
     15import org.openstreetmap.josm.Main;
    1816import org.openstreetmap.josm.data.osm.visitor.Visitor;
    19 import org.openstreetmap.josm.tools.DateParser;
    20 import org.openstreetmap.josm.Main;
    2117import org.openstreetmap.josm.gui.mappaint.ElemStyle;
    2218
     
    107103
    108104    /**
    109      * true if this object is considered "tagged". To be "tagged", an object
    110      * must have one or more "non-standard" tags. "created_by" and "source"
    111      * are typically considered "standard" tags and do not make an object
    112      * "tagged".
    113      */
    114     public boolean tagged = false;
    115 
    116     /**
    117      * true if this object has direction dependent tags (e.g. oneway)
    118      */
    119     public boolean hasDirectionKeys = false;
    120 
    121     /**
    122105     * If set to true, this object is currently selected.
    123106     */
    124107    public volatile boolean selected = false;
    125    
     108
    126109    /**
    127110     * If set to true, this object is highlighted. Currently this is only used to
    128      * show which ways/nodes will connect 
     111     * show which ways/nodes will connect
    129112     */
    130113    public volatile boolean highlighted = false;
     114
     115    private int timestamp;
     116
     117    public void setTimestamp(Date timestamp) {
     118        this.timestamp = (int)(timestamp.getTime() / 1000);
     119    }
    131120
    132121    /**
     
    134123     * read from the server and delivered back to the server unmodified. It is
    135124     * used to check against edit conflicts.
    136      */
    137     public String timestamp = null;
    138 
    139     /**
    140      * The timestamp is only parsed when this is really necessary, and this
    141      * is the cache for the result.
    142      */
    143     public Date parsedTimestamp = null;
     125     *
     126     */
     127    public Date getTimestamp() {
     128        return new Date(timestamp * 1000l);
     129    }
     130
     131    public boolean isTimestampEmpty() {
     132        return timestamp == 0;
     133    }
    144134
    145135    /**
     
    155145    public int version = -1;
    156146
     147    private static Collection<String> uninteresting = null;
    157148    /**
    158149     * Contains a list of "uninteresting" keys that do not make an object
     
    160151     * Initialized by checkTagged()
    161152     */
    162     public static Collection<String> uninteresting = null;
     153    public static Collection<String> getUninterestingKeys() {
     154        if(uninteresting == null) {
     155            uninteresting = Main.pref.getCollection("tags.uninteresting",
     156                    Arrays.asList(new String[]{"source","note","comment","converted_by","created_by"}));
     157        }
     158        return uninteresting;
     159    }
     160
     161
     162    private static Collection<String> directionKeys = null;
    163163
    164164    /**
     
    167167     * Initialized by checkDirectionTagged()
    168168     */
    169     public static Collection<String> directionKeys = null;
     169    public static Collection<String> getDirectionKeys() {
     170        if(directionKeys == null) {
     171            directionKeys = Main.pref.getCollection("tags.direction",
     172                    Arrays.asList(new String[]{"oneway","incline","incline_steep","aerialway"}));
     173        }
     174        return directionKeys;
     175    }
    170176
    171177    /**
     
    180186        selected = false;
    181187        modified = true;
    182     }
    183 
    184     /**
    185      * Returns the timestamp for this object, or the current time if none is set.
    186      * Internally, parses the timestamp from XML into a Date object and caches it
    187      * for possible repeated calls.
    188      */
    189     public Date getTimestamp() {
    190         if (parsedTimestamp == null) {
    191             try {
    192                 parsedTimestamp = DateParser.parse(timestamp);
    193             } catch (ParseException ex) {
    194                 parsedTimestamp = new Date();
    195             }
    196         }
    197         return parsedTimestamp;
    198188    }
    199189
     
    242232            keys.put(key, value);
    243233        }
    244         checkTagged();
    245         checkDirectionTagged();
    246234        mappaintStyle = null;
    247235    }
     
    255243                keys = null;
    256244        }
    257         checkTagged();
    258         checkDirectionTagged();
    259245        mappaintStyle = null;
    260246    }
     
    292278        timestamp = osm.timestamp;
    293279        version = osm.version;
    294         tagged = osm.tagged;
    295280        incomplete = osm.incomplete;
    296281        clearCached();
     
    304289     */
    305290    public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    306         return
    307             id == osm.id &&
    308             incomplete == osm.incomplete &&
    309             (semanticOnly || (modified == osm.modified)) &&
    310             deleted == osm.deleted &&
    311             (semanticOnly || (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp))) &&
    312             (semanticOnly || (version==osm.version)) &&
    313             (semanticOnly || (user == null ? osm.user==null : user==osm.user)) &&
    314             (semanticOnly || (visible == osm.visible)) &&
    315             (keys == null ? osm.keys==null : keys.equals(osm.keys));
    316     }
    317 
    318     public String getTimeStr() {
    319         return timestamp == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
    320     }
    321 
    322     /**
    323      * Updates the "tagged" flag. "keys" property should probably be made private
    324      * to make sure this gets called when keys are set.
    325      */
    326     public void checkTagged() {
    327         tagged = false;
    328         if(uninteresting == null)
    329             uninteresting = Main.pref.getCollection("tags.uninteresting",
    330             Arrays.asList(new String[]{"source","note","comment","converted_by","created_by"}));
     291        return id == osm.id
     292        && incomplete == osm.incomplete
     293        && deleted == osm.deleted
     294        && (semanticOnly || (modified == osm.modified
     295         && timestamp == osm.timestamp
     296         && version == osm.version
     297         && visible == osm.visible
     298         && (user == null ? osm.user==null : user==osm.user)))
     299        && (keys == null ? osm.keys==null : keys.equals(osm.keys));
     300    }
     301
     302    /**
     303     * true if this object is considered "tagged". To be "tagged", an object
     304     * must have one or more "non-standard" tags. "created_by" and "source"
     305     * are typically considered "standard" tags and do not make an object
     306     * "tagged".
     307     */
     308    public boolean isTagged() {
     309        // TODO Cache value after keys are made private
     310        getUninterestingKeys();
    331311        if (keys != null) {
    332312            for (Entry<String,String> e : keys.entrySet()) {
    333313                if (!uninteresting.contains(e.getKey())) {
    334                     tagged = true;
    335                     break;
     314                    return true;
    336315                }
    337316            }
    338317        }
    339     }
    340     /**
    341      * Updates the "hasDirectionKeys" flag. "keys" property should probably be made private
    342      * to make sure this gets called when keys are set.
    343      */
    344     public void checkDirectionTagged() {
    345         hasDirectionKeys = false;
    346         if(directionKeys == null)
    347             /* this list only works for keys but not for values (e.g. highway=incline won't work here) */
    348             directionKeys = Main.pref.getCollection("tags.direction",
    349             Arrays.asList(new String[]{"oneway","incline","incline_steep","aerialway","junction"}));
     318        return false;
     319    }
     320    /**
     321     * true if this object has direction dependent tags (e.g. oneway)
     322     */
     323    public boolean hasDirectionKeys() {
     324        // TODO Cache value after keys are made private
     325        getDirectionKeys();
    350326        if (keys != null) {
    351327            for (Entry<String,String> e : keys.entrySet()) {
    352328                if (directionKeys.contains(e.getKey())) {
    353                     hasDirectionKeys = true;
    354                     break;
     329                    return true;
    355330                }
    356331            }
    357332        }
     333        return false;
    358334    }
    359335}
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r1463 r1499  
    9292        nodes.clear();
    9393        nodes.addAll(((Way)osm).nodes);
    94         checkDirectionTagged();
    9594    }
    9695
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1439 r1499  
    157157        else if (n.selected)
    158158            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    159         else if (n.tagged)
     159        else if (n.isTagged())
    160160            drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
    161161        else
     
    245245           (even if the tag is negated as in oneway=false) or the way is selected */
    246246        boolean showDirection = w.selected || ((!useRealWidth) && (showDirectionArrow
    247         && (!showRelevantDirectionsOnly || w.hasDirectionKeys)));
     247        && (!showRelevantDirectionsOnly || w.hasDirectionKeys())));
    248248        /* head only takes over control if the option is true,
    249249           the direction should be shown at all and not only because it's selected */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r1169 r1499  
    235235            }
    236236            if (my.realEqual(other, true)) {
    237                 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
    238                 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
     237                Date myd = my.getTimestamp();
     238                Date otherd = other.getTimestamp();
    239239
    240240                // they differ in modified/timestamp combination only. Auto-resolve it.
     
    242242                if (myd.before(otherd)) {
    243243                    my.modified = other.modified;
    244                     my.timestamp = other.timestamp;
     244                    my.setTimestamp(other.getTimestamp());
    245245                }
    246246                return true; // merge done.
    247247            }
    248248            if (my.id == other.id && my.id != 0) {
    249                 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
    250                 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
     249                Date myd = my.getTimestamp();
     250                Date otherd = other.getTimestamp();
    251251
    252252                if (my.incomplete || other.incomplete) {
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r1415 r1499  
    163163        //profilerN = 0;
    164164        for (final OsmPrimitive osm : data.ways)
    165             if (!osm.deleted && !osm.selected && osm.tagged)
     165            if (!osm.deleted && !osm.selected && osm.isTagged())
    166166            {
    167167                osm.visit(this);
     
    171171
    172172        for (final OsmPrimitive osm : data.ways)
    173             if (!osm.deleted && !osm.selected && !osm.tagged)
     173            if (!osm.deleted && !osm.selected && !osm.isTagged())
    174174            {
    175175                osm.visit(this);
     
    255255        else if (n.selected)
    256256            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    257         else if(n.tagged)
     257        else if(n.isTagged())
    258258            drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
    259259        else
     
    301301
    302302        boolean showThisDirectionArrow = w.selected
    303         || (showDirectionArrow && (!showRelevantDirectionsOnly || w.hasDirectionKeys));
     303        || (showDirectionArrow && (!showRelevantDirectionsOnly || w.hasDirectionKeys()));
    304304        /* head only takes over control if the option is true,
    305305           the direction should be shown at all and not only because it's selected */
     
    313313        } else if(w.selected) {
    314314            wayColor = selectedColor;
    315         } else if (!w.tagged) {
     315        } else if (!w.isTagged()) {
    316316            wayColor = untaggedWayColor;
    317317        } else {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java

    r1169 r1499  
    3636import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3737import org.openstreetmap.josm.gui.SideButton;
     38import org.openstreetmap.josm.tools.DateUtils;
    3839import org.openstreetmap.josm.tools.GBC;
    3940import org.openstreetmap.josm.tools.ImageProvider;
     
    171172            data.setRowCount(0);
    172173            for (HistoryItem i : orderedHistory)
    173                 data.addRow(new Object[]{i.osm, i.osm.timestamp, i.visible});
     174                data.addRow(new Object[]{i.osm, DateUtils.fromDate(i.osm.getTimestamp()), i.visible});
    174175            historyPane.setVisible(true);
    175176            notLoaded.setVisible(false);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationEditor.java

    r1448 r1499  
    410410            // If the user wanted to create a new relation, but hasn't added any members or
    411411            // tags, don't add an empty relation
    412             clone.checkTagged();
    413             if(clone.members.size() == 0 && !clone.tagged)
     412            if(clone.members.size() == 0 && !clone.isTagged())
    414413                return;
    415414            Main.main.undoRedo.add(new AddCommand(clone));
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1465 r1499  
    6868import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
    6969import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     70import org.openstreetmap.josm.tools.DateUtils;
    7071import org.openstreetmap.josm.tools.DontShowAgainInfo;
    7172import org.openstreetmap.josm.tools.GBC;
     
    660661                        if(timestr != null)
    661662                        {
    662                             timestr = timestr.replace("Z","+00:00");
    663                             n.timestamp = timestr;
     663                            n.setTimestamp(DateUtils.fromString(timestr));
    664664                        }
    665665                        ds.nodes.add(n);
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1415 r1499  
    6161import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    6262import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     63import org.openstreetmap.josm.tools.DateUtils;
    6364import org.openstreetmap.josm.tools.GBC;
    6465import org.openstreetmap.josm.tools.ImageProvider;
     
    402403                    trk.trackSegs.add(trkseg);
    403404                }
    404                 if (!n.tagged) {
     405                if (!n.isTagged()) {
    405406                    doneNodes.add(n);
    406407                }
    407                 WayPoint wpt = new WayPoint(n.coor);
    408                 if (n.timestamp != null)
     408                WayPoint wpt = new WayPoint(n.coor);               
     409                if (!n.isTimestampEmpty())
    409410                {
    410                     wpt.attr.put("time", n.timestamp);
     411                    wpt.attr.put("time", DateUtils.fromDate(n.getTimestamp()));
    411412                    wpt.setTime();
    412413                }
     
    420421            if (n.incomplete || n.deleted || doneNodes.contains(n)) continue;
    421422            WayPoint wpt = new WayPoint(n.coor);
    422             if (n.timestamp != null) {
    423                 wpt.attr.put("time", n.timestamp);
     423            if (!n.isTimestampEmpty()) {
     424                wpt.attr.put("time", DateUtils.fromDate(n.getTimestamp()));
    424425                wpt.setTime();
    425426            }
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1494 r1499  
    3333import org.openstreetmap.josm.data.osm.visitor.Visitor;
    3434import org.openstreetmap.josm.gui.PleaseWaitDialog;
     35import org.openstreetmap.josm.tools.DateUtils;
    3536import org.xml.sax.Attributes;
    3637import org.xml.sax.InputSource;
     
    101102               osm.selected = selected;
    102103               osm.deleted = deleted;
    103                osm.timestamp = timestamp;
     104               osm.setTimestamp(getTimestamp());
    104105               osm.user = user;
    105106               osm.visible = visible;
    106107               osm.version = version;
    107                osm.checkTagged();
    108                osm.checkDirectionTagged();
    109108               osm.mappaintStyle = null;
    110109          }
     
    304303          String time = atts.getValue("timestamp");
    305304          if (time != null && time.length() != 0) {
    306                /* Do not parse the date here since it wastes a HUGE amount of time.
    307                 * Moved into OsmPrimitive.
    308                try {
    309                     current.timestamp = DateParser.parse(time);
    310                } catch (ParseException e) {
    311                     e.printStackTrace();
    312                     throw new SAXException(tr("Couldn''t read time format \"{0}\".",time));
    313                }
    314                */
    315                current.timestamp = time;
     305               current.setTimestamp(DateUtils.fromString(time));
    316306          }
    317307
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r1225 r1499  
    1616import org.openstreetmap.josm.data.osm.Way;
    1717import org.openstreetmap.josm.data.osm.visitor.Visitor;
     18import org.openstreetmap.josm.tools.DateUtils;
    1819
    1920/**
     
    201202                out.print(" action='"+action+"'");
    202203        }
    203         if (osm.timestamp != null) {
    204             out.print(" timestamp='"+osm.timestamp+"'");
     204        if (!osm.isTimestampEmpty()) {
     205            out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
    205206        }
    206207        // user and visible added with 0.4 API
Note: See TracChangeset for help on using the changeset viewer.