Ticket #11249: 0001-Removed-unneccessary-boxing-of-ints-doubles.patch

File 0001-Removed-unneccessary-boxing-of-ints-doubles.patch, 4.7 KB (added by michael2402, 9 years ago)
  • src/org/openstreetmap/josm/io/AbstractParser.java

    From 9a26ff88bb37baaa5d2e3ad3b5eca96964f47281 Mon Sep 17 00:00:00 2001
    From: Michael Zangl <michael.zangl@student.kit.edu>
    Date: Fri, 20 Mar 2015 15:46:10 +0100
    Subject: [PATCH] Removed unneccessary boxing of ints/doubles
    
    ---
     src/org/openstreetmap/josm/io/AbstractParser.java  | 23 +++++++++++-----------
     .../openstreetmap/josm/tools/date/DateUtils.java   |  2 +-
     2 files changed, 13 insertions(+), 12 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/io/AbstractParser.java b/src/org/openstreetmap/josm/io/AbstractParser.java
    index f53b797..0b05d0d 100644
    a b import org.xml.sax.helpers.DefaultHandler;  
    2424 * @since 6201
    2525 */
    2626public abstract class AbstractParser extends DefaultHandler {
    27    
     27
    2828    /** the current primitive to be read */
    2929    protected HistoryOsmPrimitive currentPrimitive;
    3030    protected Locator locator;
    public abstract class AbstractParser extends DefaultHandler {  
    3333    public void setDocumentLocator(Locator locator) {
    3434        this.locator = locator;
    3535    }
    36    
     36
    3737    protected abstract void throwException(String message) throws SAXException;
    3838
    3939    protected final long getMandatoryAttributeLong(Attributes attr, String name) throws SAXException {
    public abstract class AbstractParser extends DefaultHandler {  
    4141        if (v == null) {
    4242            throwException(tr("Missing mandatory attribute ''{0}''.", name));
    4343        }
    44         Long l = 0L;
     44        long l = 0L;
    4545        try {
    4646            l = Long.parseLong(v);
    4747        } catch(NumberFormatException e) {
    public abstract class AbstractParser extends DefaultHandler {  
    6969        return l;
    7070    }
    7171
    72     protected final Double getAttributeDouble(Attributes attr, String name) throws SAXException {
     72    protected final double getAttributeDouble(Attributes attr, String name) throws SAXException {
    7373        String v = attr.getValue(name);
    7474        if (v == null) {
    75             return null;
     75            // Indicates not found.
     76            return Double.NaN;
    7677        }
    7778        double d = 0.0;
    7879        try {
    public abstract class AbstractParser extends DefaultHandler {  
    101102        throwException(tr("Illegal value for mandatory attribute ''{0}'' of type boolean. Got ''{1}''.", name, v));
    102103        return false; // not reached
    103104    }
    104    
     105
    105106    protected final HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException {
    106107        long id = getMandatoryAttributeLong(atts,"id");
    107108        long version = getMandatoryAttributeLong(atts,"version");
    public abstract class AbstractParser extends DefaultHandler {  
    125126        Date timestamp = DateUtils.fromString(v);
    126127        HistoryOsmPrimitive primitive = null;
    127128        if (type.equals(OsmPrimitiveType.NODE)) {
    128             Double lat = getAttributeDouble(atts, "lat");
    129             Double lon = getAttributeDouble(atts, "lon");
    130             LatLon coor = (lat != null && lon != null) ? new LatLon(lat,lon) : null;
     129            double lat = getAttributeDouble(atts, "lat");
     130            double lon = getAttributeDouble(atts, "lon");
     131            LatLon coor = (lat != Double.NaN && lon != Double.NaN) ? new LatLon(lat,lon) : null;
    131132            primitive = new HistoryNode(
    132133                    id,version,visible,user,changesetId,timestamp,coor
    133134            );
    public abstract class AbstractParser extends DefaultHandler {  
    151152    protected final void startWay(Attributes atts) throws SAXException {
    152153        currentPrimitive = createPrimitive(atts, OsmPrimitiveType.WAY);
    153154    }
    154    
     155
    155156    protected final void startRelation(Attributes atts) throws SAXException {
    156157        currentPrimitive = createPrimitive(atts, OsmPrimitiveType.RELATION);
    157158    }
    public abstract class AbstractParser extends DefaultHandler {  
    180181        RelationMemberData member = new RelationMemberData(role, type,ref);
    181182        ((HistoryRelation)currentPrimitive).addMember(member);
    182183    }
    183    
     184
    184185    protected final boolean doStartElement(String qName, Attributes atts) throws SAXException {
    185186        switch (qName) {
    186187        case "node":
  • src/org/openstreetmap/josm/tools/date/DateUtils.java

    diff --git a/src/org/openstreetmap/josm/tools/date/DateUtils.java b/src/org/openstreetmap/josm/tools/date/DateUtils.java
    index 42d6610..6ac540e 100644
    a b public final class DateUtils {  
    141141    }
    142142
    143143    private static int parsePart(String str, int off, int len) {
    144         return Integer.valueOf(str.substring(off, off+len));
     144        return Integer.parseInt(str.substring(off, off+len));
    145145    }
    146146
    147147    /**