Changeset 6450 in josm for trunk


Ignore:
Timestamp:
2013-12-07T13:51:13+01:00 (10 years ago)
Author:
Don-vip
Message:

Sonar/Findbugs: fix recent issues

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r6397 r6450  
    116116   
    117117    protected final void setSequence(Command[] sequence) {
    118         this.sequence = sequence;
     118        this.sequence = Arrays.copyOf(sequence, sequence.length);
    119119    }
    120120   
  • trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java

    r6424 r6450  
    162162     * Updates the changeset comment model upon changes in the input field.
    163163     */
    164     class CommentModelListener extends FocusAdapter implements ActionListener {
     164    static class CommentModelListener extends FocusAdapter implements ActionListener {
    165165
    166166        final HistoryComboBox source;
     
    186186     * in sync with the current changeset comment
    187187     */
    188     class ChangesetCommentObserver implements Observer {
     188    static class ChangesetCommentObserver implements Observer {
    189189
    190190        private final HistoryComboBox destination;
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r6392 r6450  
    10741074        List<ImageEntry> dateImgLst = new ArrayList<ImageEntry>(yLayer.data.size());
    10751075        for (ImageEntry e : yLayer.data) {
    1076             if (e.getExifTime() == null) {
     1076            if (!e.hasExifTime()) {
    10771077                continue;
    10781078            }
     
    11591159    }
    11601160
     1161    private static Double getElevation(WayPoint wp) {
     1162        String value = (String) wp.attr.get("ele");
     1163        if (value != null) {
     1164            try {
     1165                return new Double(value);
     1166            } catch (NumberFormatException e) {
     1167                Main.warn(e);
     1168            }
     1169        }
     1170        return null;
     1171    }
     1172   
    11611173    private int matchPoints(List<ImageEntry> images, WayPoint prevWp, long prevWpTime,
    11621174            WayPoint curWp, long curWpTime, long offset) {
     
    11751187        Double speed = null;
    11761188        Double prevElevation = null;
    1177         Double curElevation = null;
    11781189
    11791190        if (prevWp != null) {
     
    11831194                speed = 3600 * distance / (curWpTime - prevWpTime);
    11841195            }
    1185             try {
    1186                 prevElevation = new Double((String) prevWp.attr.get("ele"));
    1187             } catch(Exception e) {}
    1188         }
    1189 
    1190         try {
    1191             curElevation = new Double((String) curWp.attr.get("ele"));
    1192         } catch (Exception e) {}
     1196            prevElevation = getElevation(prevWp);
     1197        }
     1198
     1199        Double curElevation = getElevation(curWp);
    11931200
    11941201        // First trackpoint, then interval is set to five seconds, i.e. photos up to five seconds
    11951202        // before the first point will be geotagged with the starting point
    1196         if(prevWpTime == 0 || curWpTime <= prevWpTime) {
     1203        if (prevWpTime == 0 || curWpTime <= prevWpTime) {
    11971204            while (true) {
    11981205                if (i < 0) {
     
    12001207                }
    12011208                final ImageEntry curImg = images.get(i);
    1202                 if (curImg.getExifTime().getTime() > curWpTime
    1203                         || curImg.getExifTime().getTime() < curWpTime - interval) {
     1209                long time = curImg.getExifTime().getTime();
     1210                if (time > curWpTime || time < curWpTime - interval) {
    12041211                    break;
    12051212                }
    1206                 if(curImg.tmp.getPos() == null) {
     1213                if (curImg.tmp.getPos() == null) {
    12071214                    curImg.tmp.setPos(curWp.getCoor());
    12081215                    curImg.tmp.setSpeed(speed);
     
    12291236            }
    12301237
    1231             if(curImg.tmp.getPos() == null) {
    1232                 // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless
    1233                 // variable
     1238            if (curImg.tmp.getPos() == null) {
     1239                // The values of timeDiff are between 0 and 1, it is not seconds but a dimensionless variable
    12341240                double timeDiff = (double)(imgTime - prevWpTime) / interval;
    12351241                curImg.tmp.setPos(prevWp.getCoor().interpolate(curWp.getCoor(), timeDiff));
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r6392 r6450  
    2626import java.util.Collection;
    2727import java.util.Collections;
    28 import java.util.Date;
    2928import java.util.GregorianCalendar;
    3029import java.util.HashSet;
     
    154153                try {
    155154                    e.setExifTime(ExifReader.readTime(f));
    156                 } catch (ParseException e1) {
     155                } catch (ParseException ex) {
    157156                    e.setExifTime(null);
    158157                }
     
    636635            }
    637636            else {
    638                 // No GPS date stamp in EXIF data.  Copy it from EXIF time.
     637                // No GPS date stamp in EXIF data. Copy it from EXIF time.
    639638                // Date is not set if EXIF time is not available.
    640                 Date exifTime = e.getExifTime();
    641                 if (exifTime != null) {
     639                if (e.hasExifTime()) {
    642640                    // Time not set yet, so we can copy everything, not just date.
    643                     cal.setTime(exifTime);
     641                    cal.setTime(e.getExifTime());
    644642                }
    645643            }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java

    r6392 r6450  
    4141
    4242    /**
    43      * When the corralation dialog is open, we like to show the image position
     43     * When the correlation dialog is open, we like to show the image position
    4444     * for the current time offset on the map in real time.
    4545     * On the other hand, when the user aborts this operation, the old values
     
    6868        return elevation;
    6969    }
     70
    7071    public Date getGpsTime() {
    7172        if (tmp != null)
    72             return tmp.gpsTime;
    73         return gpsTime;
     73            return getDefensiveDate(tmp.gpsTime);
     74        return getDefensiveDate(gpsTime);
     75    }
     76
     77    /**
     78     * Convenient way to determine if this entry has a GPS time, without the cost of building a defensive copy.
     79     * @return {@code true} if this entry has a GPS time
     80     * @since 6450
     81     */
     82    public final boolean hasGpsTime() {
     83        return (tmp != null && tmp.gpsTime != null) || gpsTime != null;
    7484    }
    7585
     
    8494    }
    8595    public Date getExifTime() {
    86         return exifTime;
     96        return getDefensiveDate(exifTime);
     97    }
     98   
     99    /**
     100     * Convenient way to determine if this entry has a EXIF time, without the cost of building a defensive copy.
     101     * @return {@code true} if this entry has a EXIF time
     102     * @since 6450
     103     */
     104    public final boolean hasExifTime() {
     105        return exifTime != null;
    87106    }
    88107   
     
    93112     */
    94113    public final Date getExifGpsTime() {
    95         return exifGpsTime;
     114        return getDefensiveDate(exifGpsTime);
     115    }
     116   
     117    /**
     118     * Convenient way to determine if this entry has a EXIF GPS time, without the cost of building a defensive copy.
     119     * @return {@code true} if this entry has a EXIF GPS time
     120     * @since 6450
     121     */
     122    public final boolean hasExifGpsTime() {
     123        return exifGpsTime != null;
     124    }
     125   
     126    private static Date getDefensiveDate(Date date) {
     127        if (date == null)
     128            return null;
     129        return new Date(date.getTime());
    96130    }
    97131   
     
    129163    }
    130164    public void setExifTime(Date exifTime) {
    131         this.exifTime = exifTime;
     165        this.exifTime = getDefensiveDate(exifTime);
    132166    }
    133167   
     
    138172     */
    139173    public final void setExifGpsTime(Date exifGpsTime) {
    140         this.exifGpsTime = exifGpsTime;
     174        this.exifGpsTime = getDefensiveDate(exifGpsTime);
    141175    }
    142176   
    143177    public void setGpsTime(Date gpsTime) {
    144         this.gpsTime = gpsTime;
     178        this.gpsTime = getDefensiveDate(gpsTime);
    145179    }
    146180    public void setExifCoor(LatLon exifCoor) {
     
    228262        // This can be removed once isNewGpsData is used instead of the GPS time.
    229263        if (gpsTime == null) {
    230             Date gpsTime = getExifGpsTime();
    231             if (gpsTime == null) {
    232                 gpsTime = getExifTime();
    233                 if (gpsTime == null) {
     264            Date time = getExifGpsTime();
     265            if (time == null) {
     266                time = getExifTime();
     267                if (time == null) {
    234268                    // Time still not set, take the current time.
    235                     gpsTime = new Date();
     269                    time = new Date();
    236270                }
    237271            }
    238             setGpsTime(gpsTime);
    239         }
    240         if (tmp != null && tmp.getGpsTime() == null) {
     272            gpsTime = time;
     273        }
     274        if (tmp != null && !tmp.hasGpsTime()) {
    241275            // tmp.gpsTime overrides gpsTime, so we set it too.
    242             tmp.setGpsTime(getGpsTime());
     276            tmp.gpsTime = gpsTime;
    243277        }
    244278    }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r6392 r6450  
    247247            }
    248248            DateFormat dtf = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    249             if (entry.getExifTime() != null) {
     249            if (entry.hasExifTime()) {
    250250                osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExifTime())));
    251251            }
    252             if (entry.getGpsTime() != null) {
     252            if (entry.hasGpsTime()) {
    253253                osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsTime())));
    254254            }
  • trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionExporter.java

    r6392 r6450  
    9393                addAttr("elevation", entry.getElevation().toString(), imgElem, support);
    9494            }
    95             if (entry.getGpsTime() != null) {
     95            if (entry.hasGpsTime()) {
    9696                addAttr("gps-time", Long.toString(entry.getGpsTime().getTime()), imgElem, support);
    9797            }
     
    9999                addAttr("exif-orientation", Integer.toString(entry.getExifOrientation()), imgElem, support);
    100100            }
    101             if (entry.getExifTime() != null) {
     101            if (entry.hasExifTime()) {
    102102                addAttr("exif-time", Long.toString(entry.getExifTime().getTime()), imgElem, support);
    103103            }
    104             if (entry.getExifGpsTime() != null) {
     104            if (entry.hasExifGpsTime()) {
    105105                addAttr("exif-gps-time", Long.toString(entry.getExifGpsTime().getTime()), imgElem, support);
    106106            }
  • trunk/src/org/openstreetmap/josm/io/session/GeoImageSessionImporter.java

    r6392 r6450  
    6969                                } else if (attrElem.getTagName().equals("exif-image-direction")) {
    7070                                    entry.setExifImgDir(Double.parseDouble(attrElem.getTextContent()));
    71                                 } else if (attrElem.getTagName().equals("is-new-gps-data")) {
    72                                     if (Boolean.parseBoolean(attrElem.getTextContent())) {
    73                                         entry.flagNewGpsData();
    74                                     }
     71                                } else if (attrElem.getTagName().equals("is-new-gps-data") && Boolean.parseBoolean(attrElem.getTextContent())) {
     72                                    entry.flagNewGpsData();
    7573                                }
    7674                                // TODO: handle thumbnail loading
Note: See TracChangeset for help on using the changeset viewer.