Ignore:
Timestamp:
2015-12-15T14:04:00+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix Sonar complaints about split overload methods

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

Legend:

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

    r31815 r31826  
    5050
    5151  /**
     52   * Adds an MapillaryImage to the object, and then repaints mapView.
     53   *
     54   * @param image
     55   *          The image to be added.
     56   */
     57  public synchronized void add(MapillaryAbstractImage image) {
     58    add(image, true);
     59  }
     60
     61  /**
     62   * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
     63   * needed for concurrency.
     64   *
     65   * @param image
     66   *          The image to be added.
     67   * @param update
     68   *          Whether the map must be updated or not.
     69   */
     70  public synchronized void add(MapillaryAbstractImage image, boolean update) {
     71    if (!this.images.contains(image)) {
     72      this.images.add(image);
     73    }
     74    if (update)
     75      dataUpdated();
     76    fireImagesAdded();
     77  }
     78
     79  /**
    5280   * Adds a set of MapillaryImages to the object, and then repaints mapView.
    5381   *
     
    6088
    6189  /**
    62    * Adds an MapillaryImage to the object, and then repaints mapView.
    63    *
    64    * @param image
    65    *          The image to be added.
    66    */
    67   public synchronized void add(MapillaryAbstractImage image) {
    68     add(image, true);
     90   * Adds a set of {link MapillaryAbstractImage} objects to this object.
     91   *
     92   * @param images
     93   *          The set of images to be added.
     94   * @param update
     95   *          Whether the map must be updated or not.
     96   */
     97  public synchronized void add(List<MapillaryAbstractImage> images, boolean update) {
     98    for (MapillaryAbstractImage image : images) {
     99      add(image, update);
     100    }
     101  }
     102
     103  /**
     104   * Adds a new listener.
     105   *
     106   * @param lis
     107   *          Listener to be added.
     108   */
     109  public void addListener(MapillaryDataListener lis) {
     110    this.listeners.add(lis);
     111  }
     112
     113  /**
     114   * Adds a {@link MapillaryImage} object to the list of selected images, (when
     115   * ctrl + click)
     116   *
     117   * @param image
     118   *          The {@link MapillaryImage} object to be added.
     119   */
     120  public void addMultiSelectedImage(MapillaryAbstractImage image) {
     121    if (!this.multiSelectedImages.contains(image)) {
     122      if (this.getSelectedImage() != null)
     123        this.multiSelectedImages.add(image);
     124      else
     125        this.setSelectedImage(image);
     126    }
     127    if (Main.main != null)
     128      Main.map.mapView.repaint();
     129  }
     130
     131  /**
     132   * Adds a set of {@code MapillaryAbstractImage} objects to the list of
     133   * selected images.
     134   *
     135   * @param images
     136   *          A List object containing the set of images to be added.
     137   */
     138  public void addMultiSelectedImage(List<MapillaryAbstractImage> images) {
     139    for (MapillaryAbstractImage image : images)
     140      if (!this.multiSelectedImages.contains(image)) {
     141        if (this.getSelectedImage() != null)
     142          this.multiSelectedImages.add(image);
     143        else
     144          this.setSelectedImage(image);
     145      }
     146    Main.map.mapView.repaint();
    69147  }
    70148
     
    103181
    104182  /**
    105    * Adds a new listener.
    106    *
    107    * @param lis
    108    *          Listener to be added.
    109    */
    110   public void addListener(MapillaryDataListener lis) {
    111     this.listeners.add(lis);
    112   }
    113 
    114   /**
    115183   * Removes a listener.
    116184   *
     
    123191
    124192  /**
    125    * Adds a set of {link MapillaryAbstractImage} objects to this object.
    126    *
    127    * @param images
    128    *          The set of images to be added.
    129    * @param update
    130    *          Whether the map must be updated or not.
    131    */
    132   public synchronized void add(List<MapillaryAbstractImage> images,
    133       boolean update) {
    134     for (MapillaryAbstractImage image : images) {
    135       add(image, update);
    136     }
    137   }
    138 
    139   /**
    140193   * Highlights the image under the cursor.
    141194   *
     
    154207  public MapillaryAbstractImage getHighlightedImage() {
    155208    return this.highlightedImage;
    156   }
    157 
    158   /**
    159    * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
    160    * needed for concurrency.
    161    *
    162    * @param image
    163    *          The image to be added.
    164    * @param update
    165    *          Whether the map must be updated or not.
    166    */
    167   public synchronized void add(MapillaryAbstractImage image, boolean update) {
    168     if (!this.images.contains(image)) {
    169       this.images.add(image);
    170     }
    171     if (update)
    172       dataUpdated();
    173     fireImagesAdded();
    174209  }
    175210
     
    343378
    344379  /**
    345    * Adds a {@link MapillaryImage} object to the list of selected images, (when
    346    * ctrl + click)
    347    *
    348    * @param image
    349    *          The {@link MapillaryImage} object to be added.
    350    */
    351   public void addMultiSelectedImage(MapillaryAbstractImage image) {
    352     if (!this.multiSelectedImages.contains(image)) {
    353       if (this.getSelectedImage() != null)
    354         this.multiSelectedImages.add(image);
    355       else
    356         this.setSelectedImage(image);
    357     }
    358     if (Main.main != null)
    359       Main.map.mapView.repaint();
    360   }
    361 
    362   /**
    363    * Adds a set of {@code MapillaryAbstractImage} objects to the list of
    364    * selected images.
    365    *
    366    * @param images
    367    *          A List object containing the set of images to be added.
    368    */
    369   public void addMultiSelectedImage(List<MapillaryAbstractImage> images) {
    370     for (MapillaryAbstractImage image : images)
    371       if (!this.multiSelectedImages.contains(image)) {
    372         if (this.getSelectedImage() != null)
    373           this.multiSelectedImages.add(image);
    374         else
    375           this.setSelectedImage(image);
    376       }
    377     Main.map.mapView.repaint();
    378   }
    379 
    380   /**
    381380   * Returns a List containing all {@code MapillaryAbstractImage} objects
    382381   * selected with ctrl + click.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31815 r31826  
    4343
    4444  /**
    45    * Returns all {@link MapillaryAbstractImage} objects contained by this
    46    * object.
    47    *
    48    * @return A {@link List} object containing all the
    49    *         {@link MapillaryAbstractImage} objects that are part of the
    50    *         sequence.
    51    */
    52   public List<MapillaryAbstractImage> getImages() {
    53     return this.images;
    54   }
    55 
    56   /**
    57    * Returns the Epoch time when the sequence was captured.
    58    *
    59    * @return A long containing the Epoch time when the sequence was captured.
    60    *
    61    */
    62   public long getCreatedAt() {
    63     return this.createdAt;
    64   }
    65 
    66   /**
    6745   * Adds a new {@link MapillaryAbstractImage} object to the database.
    6846   *
     
    7250  public synchronized void add(MapillaryAbstractImage image) {
    7351    this.images.add(image);
    74   }
    75 
    76   /**
    77    * Returns the unique identifier of the sequence.
    78    *
    79    * @return A {@code String} containing the unique identifier of the sequence.
    80    *         null means that the sequence has been created locally for imported
    81    *         images.
    82    */
    83   public String getKey() {
    84     return this.key;
    8552  }
    8653
     
    9764
    9865  /**
    99    * Removes a {@link MapillaryAbstractImage} object from the database.
     66   * Returns the Epoch time when the sequence was captured.
    10067   *
    101    * @param image
    102    *          The {@link MapillaryAbstractImage} object to be removed.
     68   * @return A long containing the Epoch time when the sequence was captured.
     69   *
    10370   */
    104   public void remove(MapillaryAbstractImage image) {
    105     this.images.remove(image);
     71  public long getCreatedAt() {
     72    return this.createdAt;
     73  }
     74
     75  /**
     76   * Returns all {@link MapillaryAbstractImage} objects contained by this
     77   * object.
     78   *
     79   * @return A {@link List} object containing all the
     80   *         {@link MapillaryAbstractImage} objects that are part of the
     81   *         sequence.
     82   */
     83  public List<MapillaryAbstractImage> getImages() {
     84    return this.images;
     85  }
     86
     87  /**
     88   * Returns the unique identifier of the sequence.
     89   *
     90   * @return A {@code String} containing the unique identifier of the sequence.
     91   *         null means that the sequence has been created locally for imported
     92   *         images.
     93   */
     94  public String getKey() {
     95    return this.key;
    10696  }
    10797
     
    147137    return this.images.get(i - 1);
    148138  }
     139
     140  /**
     141   * Removes a {@link MapillaryAbstractImage} object from the database.
     142   *
     143   * @param image
     144   *          The {@link MapillaryAbstractImage} object to be removed.
     145   */
     146  public void remove(MapillaryAbstractImage image) {
     147    this.images.remove(image);
     148  }
    149149}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r31799 r31826  
    6262  }
    6363
    64   private static void run(Thread t) {
    65     threads.add(t);
    66     EXECUTOR.execute(t);
    67   }
    68 
    69   /**
    70    * If some part of the current view has not been downloaded, it is downloaded.
    71    */
    72   public static void completeView() {
    73     if (getMode() != MODES.Semiautomatic && getMode() != MODES.Manual)
    74       throw new IllegalStateException("Must be in semiautomatic or manual mode");
    75     Bounds view = Main.map.mapView.getRealBounds();
    76     if (view.getArea() > MAX_AREA)
    77       return;
    78     if (isViewDownloaded(view))
    79       return;
    80     MapillaryLayer.getInstance().getData().bounds.add(view);
    81     getImages(view);
    82   }
    83 
    84   private static boolean isViewDownloaded(Bounds view) {
    85     int n = 15;
    86     boolean[][] inside = new boolean[n][n];
    87     for (int i = 0; i < n; i++) {
    88       for (int j = 0; j < n; j++) {
    89         if (isInBounds(new LatLon(view.getMinLat()
    90             + (view.getMaxLat() - view.getMinLat()) * ((double) i / n),
    91             view.getMinLon() + (view.getMaxLon() - view.getMinLon())
    92                 * ((double) j / n)))) {
    93           inside[i][j] = true;
    94         }
    95       }
    96     }
    97     for (int i = 0; i < n; i++) {
    98       for (int j = 0; j < n; j++) {
    99         if (!inside[i][j])
    100           return false;
    101       }
    102     }
    103     return true;
    104   }
    105 
    106   /**
    107    * Checks if the given {@link LatLon} object lies inside the bounds of the
    108    * image.
    109    *
    110    * @param latlon
    111    *          The coordinates to check.
    112    * @return true if it lies inside the bounds; false otherwise;
    113    */
    114   private static boolean isInBounds(LatLon latlon) {
    115     for (Bounds bounds : MapillaryLayer.getInstance().getData().bounds) {
    116       if (bounds.contains(latlon))
    117         return true;
    118     }
    119     return false;
    120   }
    121 
    12264  /**
    12365   * Gets the images within the given bounds.
     
    12870  public static void getImages(Bounds bounds) {
    12971    getImages(bounds.getMin(), bounds.getMax());
    130   }
    131 
    132   /**
    133    * Downloads all images of the area covered by the OSM data. This is only just
    134    * for automatic download.
    135    */
    136   public static void automaticDownload() {
    137     MapillaryLayer layer = MapillaryLayer.getInstance();
    138     if (Main.map.mapView.getEditLayer() == null)
    139       return;
    140     if (isAreaTooBig()) {
    141       tooBigErrorDialog();
    142       return;
    143     }
    144     if (getMode() != MODES.Automatic)
    145       throw new IllegalStateException("Must be in automatic mode.");
    146     for (Bounds bounds : Main.map.mapView.getEditLayer().data
    147         .getDataSourceBounds()) {
    148       if (!layer.getData().bounds.contains(bounds)) {
    149         layer.getData().bounds.add(bounds);
    150         MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
    151       }
    152     }
    153   }
    154 
    155   /**
    156    * Checks if the area of the OSM data is too big. This means that probably
    157    * lots of Mapillary images are going to be downloaded, slowing down the
    158    * program too much. To solve this the automatic is stopped, an alert is shown
    159    * and you will have to download areas manually.
    160    */
    161   private static boolean isAreaTooBig() {
    162     double area = 0;
    163     for (Bounds bounds : Main.map.mapView.getEditLayer().data
    164         .getDataSourceBounds()) {
    165       area += bounds.getArea();
    166     }
    167     if (area > MAX_AREA)
    168       return true;
    169     return false;
    17072  }
    17173
     
    19092  }
    19193
    192   private static void tooBigErrorDialog() {
     94  private static void run(Thread t) {
     95    threads.add(t);
     96    EXECUTOR.execute(t);
     97  }
     98
     99  /**
     100   * If some part of the current view has not been downloaded, it is downloaded.
     101   */
     102  public static void completeView() {
     103    if (getMode() != MODES.Semiautomatic && getMode() != MODES.Manual)
     104      throw new IllegalStateException("Must be in semiautomatic or manual mode");
     105    Bounds view = Main.map.mapView.getRealBounds();
     106    if (view.getArea() > MAX_AREA)
     107      return;
     108    if (isViewDownloaded(view))
     109      return;
     110    MapillaryLayer.getInstance().getData().bounds.add(view);
     111    getImages(view);
     112  }
     113
     114  private static boolean isViewDownloaded(Bounds view) {
     115    int n = 15;
     116    boolean[][] inside = new boolean[n][n];
     117    for (int i = 0; i < n; i++) {
     118      for (int j = 0; j < n; j++) {
     119        if (isInBounds(new LatLon(view.getMinLat()
     120            + (view.getMaxLat() - view.getMinLat()) * ((double) i / n),
     121            view.getMinLon() + (view.getMaxLon() - view.getMinLon())
     122                * ((double) j / n)))) {
     123          inside[i][j] = true;
     124        }
     125      }
     126    }
     127    for (int i = 0; i < n; i++) {
     128      for (int j = 0; j < n; j++) {
     129        if (!inside[i][j])
     130          return false;
     131      }
     132    }
     133    return true;
     134  }
     135
     136  /**
     137   * Checks if the given {@link LatLon} object lies inside the bounds of the
     138   * image.
     139   *
     140   * @param latlon
     141   *          The coordinates to check.
     142   * @return true if it lies inside the bounds; false otherwise;
     143   */
     144  private static boolean isInBounds(LatLon latlon) {
     145    for (Bounds bounds : MapillaryLayer.getInstance().getData().bounds) {
     146      if (bounds.contains(latlon))
     147        return true;
     148    }
     149    return false;
     150  }
     151
     152  /**
     153   * Downloads all images of the area covered by the OSM data. This is only just
     154   * for automatic download.
     155   */
     156  public static void automaticDownload() {
     157    MapillaryLayer layer = MapillaryLayer.getInstance();
     158    if (Main.map.mapView.getEditLayer() == null)
     159      return;
     160    if (isAreaTooBig()) {
     161      tooBigErrorDialog();
     162      return;
     163    }
     164    if (getMode() != MODES.Automatic)
     165      throw new IllegalStateException("Must be in automatic mode.");
     166    for (Bounds bounds : Main.map.mapView.getEditLayer().data
     167        .getDataSourceBounds()) {
     168      if (!layer.getData().bounds.contains(bounds)) {
     169        layer.getData().bounds.add(bounds);
     170        MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
     171      }
     172    }
     173  }
     174
     175  /**
     176   * Checks if the area of the OSM data is too big. This means that probably
     177   * lots of Mapillary images are going to be downloaded, slowing down the
     178   * program too much. To solve this the automatic is stopped, an alert is shown
     179   * and you will have to download areas manually.
     180   */
     181  private static boolean isAreaTooBig() {
     182    double area = 0;
     183    for (Bounds bounds : Main.map.mapView.getEditLayer().data
     184        .getDataSourceBounds()) {
     185      area += bounds.getArea();
     186    }
     187    if (area > MAX_AREA)
     188      return true;
     189    return false;
     190  }
     191
     192  protected static void tooBigErrorDialog() {
    193193    if (!SwingUtilities.isEventDispatchThread()) {
    194194      SwingUtilities.invokeLater(new Runnable() {
Note: See TracChangeset for help on using the changeset viewer.