Ignore:
Timestamp:
2015-12-11T22:41:08+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix some more issues reported by static code analysis

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java

    r31799 r31812  
    1717 *
    1818 */
    19 public abstract class MapillaryAbstractImage {
     19public class MapillaryAbstractImage {
    2020  /**
    2121   * If two values for field ca differ by less than EPSILON both values are considered equal.
     
    5858   *          The direction of the picture (0 means north).
    5959   */
    60   public MapillaryAbstractImage(double lat, double lon, double ca) {
     60  protected MapillaryAbstractImage(final double lat, final double lon, final double ca) {
    6161    this.latLon = new LatLon(lat, lon);
    6262    this.tempLatLon = this.latLon;
     
    9292   */
    9393  public String getDate() {
    94     StringBuilder format = new StringBuilder(26);
    95     if (Main.pref.getBoolean("iso.dates"))
     94    final StringBuilder format = new StringBuilder(26);
     95    if (Main.pref.getBoolean("iso.dates")) {
    9696      format.append("yyyy-MM-dd");
    97     else
     97    } else {
    9898      format.append("dd/MM/yyyy");
     99    }
    99100    if (Main.pref.getBoolean("mapillary.display-hour", true)) {
    100       if (Main.pref.getBoolean("mapillary.format-24"))
     101      if (Main.pref.getBoolean("mapillary.format-24")) {
    101102        format.append(" - HH:mm:ss (z)");
    102       else
     103      } else {
    103104        format.append(" - h:mm:ss a (z)");
     105      }
    104106    }
    105107    return getDate(format.toString());
     
    116118   */
    117119  public String getDate(String format) {
    118     Date date = new Date(getCapturedAt());
    119 
    120     SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
     120    final Date date = new Date(getCapturedAt());
     121
     122    final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
    121123    formatter.setTimeZone(Calendar.getInstance().getTimeZone());
    122124    return formatter.format(date);
     
    186188   * Moves the image temporally to another position
    187189   *
    188    * @param x
    189    *          The movement of the image in longitude units.
    190    * @param y
    191    *          The movement of the image in latitude units.
    192    */
    193   public void move(double x, double y) {
    194     this.movingLatLon = new LatLon(this.tempLatLon.getY() + y,
    195         this.tempLatLon.getX() + x);
     190   * @param x The movement of the image in longitude units.
     191   * @param y The movement of the image in latitude units.
     192   */
     193  public void move(final double x, final double y) {
     194    this.movingLatLon = new LatLon(this.tempLatLon.getY() + y, this.tempLatLon.getX() + x);
    196195  }
    197196
     
    227226   * Sets the Epoch time when the picture was captured.
    228227   *
    229    * @param capturedAt
    230    *          Epoch time when the image was captured.
    231    */
    232   public void setCapturedAt(long capturedAt) {
     228   * @param capturedAt Epoch time when the image was captured.
     229   */
     230  public void setCapturedAt(final long capturedAt) {
    233231    this.capturedAt = capturedAt;
    234232  }
     
    237235   * Sets the MapillarySequence object which contains the MapillaryImage.
    238236   *
    239    * @param sequence
    240    *          The MapillarySequence that contains the MapillaryImage.
    241    */
    242   public void setSequence(MapillarySequence sequence) {
     237   * @param sequence The MapillarySequence that contains the MapillaryImage.
     238   */
     239  public void setSequence(final MapillarySequence sequence) {
    243240    this.sequence = sequence;
    244241  }
     
    247244   * Set's whether the image should be visible on the map or not.
    248245   *
    249    * @param visible
    250    *          true if the image is set to be visible; false otherwise.
    251    */
    252   public void setVisible(boolean visible) {
     246   * @param visible true if the image is set to be visible; false otherwise.
     247   */
     248  public void setVisible(final boolean visible) {
    253249    this.visible = visible;
    254250  }
     
    266262   * Turns the image direction.
    267263   *
    268    * @param ca
    269    *          The angle the image is moving.
    270    */
    271   public void turn(double ca) {
     264   * @param ca The angle the image is moving.
     265   */
     266  public void turn(final double ca) {
    272267    this.movingCa = this.tempCa + ca;
    273268  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31799 r31812  
    6161  public static CacheAccess<String, BufferedImageCacheEntry> CACHE;
    6262
    63   private final MapillaryDownloadAction downloadAction;
    64   private final MapillaryExportAction exportAction;
     63  private static final MapillaryDownloadAction downloadAction = new MapillaryDownloadAction();
     64  private static final MapillaryExportAction exportAction = new MapillaryExportAction();
    6565  /** Import action */
    66   private final MapillaryImportAction importAction;
     66  private static final MapillaryImportAction importAction = new MapillaryImportAction();
    6767  /** Zoom action */
    68   private static MapillaryZoomAction zoomAction;
    69   private final MapillaryDownloadViewAction downloadViewAction;
    70   private final MapillaryImportIntoSequenceAction importIntoSequenceAction;
    71   private final MapillaryJoinAction joinAction;
     68  private static final MapillaryZoomAction zoomAction = new MapillaryZoomAction();
     69  private static final MapillaryDownloadViewAction downloadViewAction = new MapillaryDownloadViewAction();
     70  private static final MapillaryImportIntoSequenceAction importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
     71  private static final MapillaryJoinAction joinAction = new MapillaryJoinAction();
    7272  /** Walk action */
    73   private static MapillaryWalkAction walkAction;
     73  private static final MapillaryWalkAction walkAction = new MapillaryWalkAction();
    7474  /** Upload action */
    75   private static MapillaryUploadAction uploadAction;
     75  private static final MapillaryUploadAction uploadAction = new MapillaryUploadAction();
    7676
    7777  /** Menu button for the {@link MapillaryDownloadAction} action. */
     
    103103    super(info);
    104104
    105     downloadAction = new MapillaryDownloadAction();
    106     walkAction = new MapillaryWalkAction();
    107     exportAction = new MapillaryExportAction();
    108     importAction = new MapillaryImportAction();
    109     zoomAction = new MapillaryZoomAction();
    110     downloadViewAction = new MapillaryDownloadViewAction();
    111     importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
    112     joinAction = new MapillaryJoinAction();
    113     uploadAction = new MapillaryUploadAction();
    114 
    115105    if (Main.main != null) { // important for headless mode
    116       downloadMenu = MainMenu.add(Main.main.menu.imageryMenu, this.downloadAction, false);
     106      downloadMenu = MainMenu.add(Main.main.menu.imageryMenu, downloadAction, false);
    117107      exportMenu = MainMenu.add(Main.main.menu.fileMenu, exportAction, false, 14);
    118108      importIntoSequenceMenu = MainMenu.add(Main.main.menu.fileMenu, importIntoSequenceAction, false, 14);
     
    120110      uploadMenu = MainMenu.add(Main.main.menu.fileMenu, uploadAction, false, 14);
    121111      zoomMenu = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
    122       downloadViewMenu = MainMenu.add(Main.main.menu.fileMenu, this.downloadViewAction, false, 14);
    123       joinMenu = MainMenu.add(Main.main.menu.dataMenu, this.joinAction, false);
     112      downloadViewMenu = MainMenu.add(Main.main.menu.fileMenu, downloadViewAction, false, 14);
     113      joinMenu = MainMenu.add(Main.main.menu.dataMenu, joinAction, false);
    124114      walkMenu = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false);
    125115
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31799 r31812  
    5555    if (pane.getValue() != null
    5656        && (int) pane.getValue() == JOptionPane.OK_OPTION
    57         && dialog.delete != null) {
    58       if (dialog.sequence.isSelected()) {
    59         UploadUtils.uploadSequence(MapillaryLayer.getInstance().getData()
    60             .getSelectedImage().getSequence(), dialog.delete.isSelected());
    61       }
     57        && dialog.delete != null
     58        && dialog.sequence.isSelected()) {
     59      UploadUtils.uploadSequence(
     60          MapillaryLayer.getInstance().getData().getSelectedImage().getSequence(),
     61          dialog.delete.isSelected()
     62      );
    6263    }
    6364  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r31797 r31812  
    4040 *
    4141 */
    42 public class MapillaryFilterDialog extends ToggleDialog implements
    43     MapillaryDataListener {
     42public class MapillaryFilterDialog extends ToggleDialog implements MapillaryDataListener {
    4443
    4544  private static final long serialVersionUID = -4192029663670922103L;
    4645
    47   private static MapillaryFilterDialog INSTANCE;
    48 
    49   private static final String[] TIME_LIST = { tr("All"), tr("Years"),
    50       tr("Months"), tr("Days") };
     46  private static MapillaryFilterDialog instance;
     47
     48  private static final String[] TIME_LIST = { tr("All"), tr("Years"), tr("Months"), tr("Days") };
    5149
    5250  private final JPanel panel;
    5351
    5452  /** Spinner to choose the range of dates. */
    55   public SpinnerNumberModel spinner;
     53  private final SpinnerNumberModel spinner;
    5654
    5755  private final JCheckBox imported = new JCheckBox(tr("Imported images"));
    58   private final JCheckBox downloaded = new JCheckBox(
    59       new downloadCheckBoxAction());
     56  private final JCheckBox downloaded = new JCheckBox(new DownloadCheckBoxAction());
    6057  private final JCheckBox onlySigns = new JCheckBox(new OnlySignsAction());
    6158  private final JComboBox<String> time;
     
    6663  private final JButton signChooser = new JButton(new SignChooserAction());
    6764
    68   private final MapillaryFilterChooseSigns signFilter = MapillaryFilterChooseSigns
    69       .getInstance();
     65  private final MapillaryFilterChooseSigns signFilter = MapillaryFilterChooseSigns.getInstance();
    7066
    7167  /** The list of sign names */
    72   private final String[] SIGN_TAGS = { "prohibitory_speed_limit",
     68  private static final String[] SIGN_TAGS = { "prohibitory_speed_limit",
    7369      "priority_stop", "other_give_way", "mandatory_roundabout",
    7470      "other_no_entry", "prohibitory_no_traffic_both_ways",
     
    7874      "danger_pedestrian_crossing", "prohibitory_no_u_turn",
    7975      "prohibitory_noturn" };
    80   /** The the {@link JCheckBox} where the respective tag should be searched */
     76  /** The {@link JCheckBox} where the respective tag should be searched */
    8177  private final JCheckBox[] SIGN_CHECKBOXES = { this.signFilter.maxSpeed,
    8278      this.signFilter.stop, this.signFilter.giveWay,
     
    137133
    138134  /**
    139    * Returns the unique instance of the class.
    140    *
    141    * @return THe unique instance of the class.
    142    */
    143   public static MapillaryFilterDialog getInstance() {
    144     if (INSTANCE == null)
    145       INSTANCE = new MapillaryFilterDialog();
    146     return INSTANCE;
     135   * @return the unique instance of the class.
     136   */
     137  public static synchronized MapillaryFilterDialog getInstance() {
     138    if (instance == null)
     139      instance = new MapillaryFilterDialog();
     140    return instance;
    147141  }
    148142
     
    153147
    154148  @Override
    155   public void selectedImageChanged(MapillaryAbstractImage oldImage,
    156       MapillaryAbstractImage newImage) {
     149  public void selectedImageChanged(MapillaryAbstractImage oldImage, MapillaryAbstractImage newImage) {
     150    // Do nothing when image selection changed
    157151  }
    158152
     
    179173    boolean onlySigns = this.onlySigns.isSelected();
    180174
    181     for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData()
    182         .getImages()) {
     175    for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData().getImages()) {
    183176      img.setVisible(true);
    184177      if (img instanceof MapillaryImportedImage) {
     
    201194          }
    202195        }
    203         if (!this.user.getText().equals("")
     196        if (!"".equals(user.getText())
    204197            && !this.user.getText().equals(((MapillaryImage) img).getUser())) {
    205198          img.setVisible(false);
     
    209202      // Calculates the amount of days since the image was taken
    210203      Long currentTime = currentTime();
    211       if (this.time.getSelectedItem().equals(TIME_LIST[1])) {
    212         if (img.getCapturedAt() < currentTime
    213             - ((Integer) this.spinner.getValue()).longValue() * 365 * 24 * 60
    214             * 60 * 1000) {
     204      long[] timeFactor = new long[]{
     205          31536000000L, // = 365 * 24 * 60 * 60 * 1000 = number of ms in a year
     206          2592000000L, // = 30 * 24 * 60 * 60 * 1000 = number of ms in a month
     207          86400000 // = 24 * 60 * 60 * 1000 = number of ms in a day
     208      };
     209      for (int i = 1; i <= 3; i++) {
     210        if (TIME_LIST[i].equals(time.getSelectedItem())
     211            && img.getCapturedAt() < currentTime - ((Integer) spinner.getValue()).longValue() * timeFactor[i - 1]
     212        ) {
    215213          img.setVisible(false);
    216           continue;
    217         }
    218       }
    219       if (this.time.getSelectedItem().equals(TIME_LIST[2])) {
    220         if (img.getCapturedAt() < currentTime
    221             - ((Integer) this.spinner.getValue()).longValue() * 30 * 24 * 60
    222             * 60 * 1000) {
    223           img.setVisible(false);
    224           continue;
    225         }
    226       }
    227       if (this.time.getSelectedItem().equals(TIME_LIST[3])) {
    228         if (img.getCapturedAt() < currentTime
    229             - ((Integer) this.spinner.getValue()).longValue() * 60 * 60 * 1000) {
    230           img.setVisible(false);
    231           continue;
    232214        }
    233215      }
     
    246228   */
    247229  private boolean checkSigns(MapillaryImage img) {
    248     for (int i = 0; i < this.SIGN_TAGS.length; i++) {
    249       if (checkSign(img, this.SIGN_CHECKBOXES[i], this.SIGN_TAGS[i]))
     230    for (int i = 0; i < SIGN_TAGS.length; i++) {
     231      if (checkSign(img, this.SIGN_CHECKBOXES[i], SIGN_TAGS[i]))
    250232        return true;
    251233    }
     
    270252  }
    271253
    272   private class downloadCheckBoxAction extends AbstractAction {
     254  private class DownloadCheckBoxAction extends AbstractAction {
    273255
    274256    private static final long serialVersionUID = 4672634002899519496L;
    275257
    276     public downloadCheckBoxAction() {
     258    public DownloadCheckBoxAction() {
    277259      putValue(NAME, tr("Downloaded images"));
    278260    }
     
    280262    @Override
    281263    public void actionPerformed(ActionEvent arg0) {
    282       MapillaryFilterDialog.this.onlySigns
    283           .setEnabled(MapillaryFilterDialog.this.downloaded.isSelected());
     264      onlySigns.setEnabled(downloaded.isSelected());
    284265    }
    285266  }
     
    325306    @Override
    326307    public void actionPerformed(ActionEvent arg0) {
    327       MapillaryFilterDialog.this.signChooser
    328           .setEnabled(MapillaryFilterDialog.this.onlySigns.isSelected());
     308      signChooser.setEnabled(onlySigns.isSelected());
    329309    }
    330310  }
     
    360340   * Destroys the unique instance of the class.
    361341   */
    362   public static void destroyInstance() {
    363     MapillaryFilterDialog.INSTANCE = null;
     342  public static synchronized void destroyInstance() {
     343    instance = null;
    364344  }
    365345}
Note: See TracChangeset for help on using the changeset viewer.