Ignore:
Timestamp:
2014-01-04T06:39:00+01:00 (6 years ago)
Author:
Don-vip
Message:

fix Sonar issues

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java

    r6520 r6623  
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.actions.AbstractInfoAction;
     33import org.openstreetmap.josm.data.osm.history.History;
    3334import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    3435import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    5859            public void keyReleased(KeyEvent e) {
    5960                // navigate history down/up using the corresponding arrow keys.
    60                 try {
    61                     final HistoryOsmPrimitive ref = model.getReferencePointInTime();
    62                     final HistoryOsmPrimitive cur = model.getCurrentPointInTime();
    63                     if (e.getKeyCode() == KeyEvent.VK_DOWN) {
    64                         // compute both values first and set them afterwards such that nothing is changed in case of an exception (e.g., reached top/bottom)
    65                         final HistoryOsmPrimitive refNext = model.getHistory().from(ref.getVersion()).sortAscending().get(1);
    66                         final HistoryOsmPrimitive curNext = model.getHistory().from(cur.getVersion()).sortAscending().get(1);
    67                         model.setReferencePointInTime(refNext);
    68                         model.setCurrentPointInTime(curNext);
    69                     } else if (e.getKeyCode() == KeyEvent.VK_UP) {
    70                         // compute both values first and set them afterwards such that nothing is changed in case of an exception (e.g., reached top/bottom)
    71                         final HistoryOsmPrimitive refNext = model.getHistory().until(ref.getVersion()).sortDescending().get(1);
    72                         final HistoryOsmPrimitive curNext = model.getHistory().until(cur.getVersion()).sortDescending().get(1);
    73                         model.setReferencePointInTime(refNext);
    74                         model.setCurrentPointInTime(curNext);
     61                long ref = model.getReferencePointInTime().getVersion();
     62                long cur = model.getCurrentPointInTime().getVersion();
     63                if (e.getKeyCode() == KeyEvent.VK_DOWN) {
     64                    History refNext = model.getHistory().from(ref);
     65                    History curNext = model.getHistory().from(cur);
     66                    if (refNext.getNumVersions() > 1 && curNext.getNumVersions() > 1) {
     67                        model.setReferencePointInTime(refNext.sortAscending().get(1));
     68                        model.setCurrentPointInTime(curNext.sortAscending().get(1));
    7569                    }
    76                 } catch (NullPointerException ignore) {
    77                 } catch (IndexOutOfBoundsException ignore) {
     70                } else if (e.getKeyCode() == KeyEvent.VK_UP) {
     71                    History refNext = model.getHistory().until(ref);
     72                    History curNext = model.getHistory().until(cur);
     73                    if (refNext.getNumVersions() > 1 && curNext.getNumVersions() > 1) {
     74                        model.setReferencePointInTime(refNext.sortDescending().get(1));
     75                        model.setCurrentPointInTime(curNext.sortDescending().get(1));
     76                    }
    7877                }
    7978            }
Note: See TracChangeset for help on using the changeset viewer.