Changeset 32978 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-09-11T13:47:54+02:00 (8 years ago)
Author:
nokutu
Message:

More streams

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/actions/MapillaryExportAction.java

    r32974 r32978  
    9292    } else if (this.dialog.group.isSelected(this.dialog.rewrite.getModel())) {
    9393      ArrayList<MapillaryImportedImage> images = new ArrayList<>();
    94       for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) {
    95         if (image instanceof MapillaryImportedImage) {
    96           images.add((MapillaryImportedImage) image);
    97         }
    98       }
     94      MapillaryLayer.getInstance().getData().getImages().stream().filter(img -> img instanceof MapillaryImportedImage).forEach(img -> images.add((MapillaryImportedImage) img));
    9995      try {
    10096        Main.worker.submit(new MapillaryExportManager(images));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r32976 r32978  
    77import java.util.concurrent.ThreadPoolExecutor;
    88import java.util.concurrent.TimeUnit;
     9import java.util.stream.IntStream;
    910
    1011import javax.swing.JOptionPane;
     
    2324 *
    2425 * @author nokutu
    25  *
    2626 */
    2727public final class MapillaryDownloader {
     
    8080  }
    8181
    82   /** All the Threads that have been run. Used to interrupt them properly. */
    83   //private static List<Thread> threads = new ArrayList<>();
    84 
    8582  /** Max area to be downloaded */
    86   public static final double MAX_AREA = Main.pref.getDouble("mapillary.max-download-area", 0.015);
     83  private static final double MAX_AREA = Main.pref.getDouble("mapillary.max-download-area", 0.015);
    8784
    8885  /** Executor that will run the petitions. */
    89   private static ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
     86  private static ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100));
    9087
    9188  private MapillaryDownloader() {
     
    9794   * sequences that pass through the given rectangle.
    9895   *
    99    * @param minLatLon
    100    *          The minimum latitude and longitude of the rectangle.
    101    * @param maxLatLon
    102    *          The maximum latitude and longitude of the rectangle
     96   * @param minLatLon The minimum latitude and longitude of the rectangle.
     97   * @param maxLatLon The maximum latitude and longitude of the rectangle
    10398   */
    10499  public static void getImages(LatLon minLatLon, LatLon maxLatLon) {
     
    112107   * Gets the images within the given bounds.
    113108   *
    114    * @param bounds
    115    *          A {@link Bounds} object containing the area to be downloaded.
     109   * @param bounds A {@link Bounds} object containing the area to be downloaded.
    116110   */
    117111  public static void getImages(Bounds bounds) {
     
    125119   */
    126120  public static MapillaryDownloader.DOWNLOAD_MODE getMode() {
    127    return MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().tempSemiautomatic
    128      ? DOWNLOAD_MODE.VISIBLE_AREA
    129      : DOWNLOAD_MODE.fromPrefId(Main.pref.get("mapillary.download-mode"));
     121    return MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().tempSemiautomatic
     122      ? DOWNLOAD_MODE.VISIBLE_AREA
     123      : DOWNLOAD_MODE.fromPrefId(Main.pref.get("mapillary.download-mode"));
    130124  }
    131125
     
    159153      for (int j = 0; j < n; j++) {
    160154        if (isInBounds(new LatLon(view.getMinLat()
    161             + (view.getMaxLat() - view.getMinLat()) * ((double) i / n),
    162             view.getMinLon() + (view.getMaxLon() - view.getMinLon())
    163                 * ((double) j / n)))) {
     155          + (view.getMaxLat() - view.getMinLat()) * ((double) i / n),
     156          view.getMinLon() + (view.getMaxLon() - view.getMinLon())
     157            * ((double) j / n)))) {
    164158          inside[i][j] = true;
    165159        }
     
    179173   * image.
    180174   *
    181    * @param latlon
    182    *          The coordinates to check.
     175   * @param latlon The coordinates to check.
     176   *
    183177   * @return true if it lies inside the bounds; false otherwise;
    184178   */
    185179  private static boolean isInBounds(LatLon latlon) {
    186     for (Bounds bounds : MapillaryLayer.getInstance().getData().getBounds()) {
    187       if (bounds.contains(latlon))
    188         return true;
    189     }
    190     return false;
     180    return MapillaryLayer.getInstance().getData().getBounds().parallelStream().anyMatch(b -> b.contains(latlon));
    191181  }
    192182
     
    206196      throw new IllegalStateException("Must be in automatic mode.");
    207197    }
    208     for (Bounds bounds : Main.getLayerManager().getEditLayer().data.getDataSourceBounds()) {
    209       if (!MapillaryLayer.getInstance().getData().getBounds().contains(bounds)) {
    210         MapillaryLayer.getInstance().getData().getBounds().add(bounds);
    211         MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
    212       }
    213     }
     198    Main.getLayerManager().getEditLayer().data.getDataSourceBounds().stream().filter(bounds -> !MapillaryLayer.getInstance().getData().getBounds().contains(bounds)).forEach(bounds -> {
     199      MapillaryLayer.getInstance().getData().getBounds().add(bounds);
     200      MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
     201    });
    214202  }
    215203
     
    221209   */
    222210  private static boolean isAreaTooBig() {
    223     double area = 0;
    224     for (Bounds bounds : Main.getLayerManager().getEditLayer().data.getDataSourceBounds()) {
    225       area += bounds.getArea();
    226     }
     211    double area = Main.getLayerManager().getEditLayer().data.getDataSourceBounds().parallelStream().map(Bounds::getArea).reduce(0.0, Double::sum);
    227212    return area > MAX_AREA;
    228213  }
     
    233218      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), true);
    234219      JOptionPane
    235           .showMessageDialog(
    236               Main.parent,
    237               I18n.tr("The downloaded OSM area is too big. Download mode has been changed to semiautomatic until the layer is restarted."));
     220        .showMessageDialog(
     221          Main.parent,
     222          I18n.tr("The downloaded OSM area is too big. Download mode has been changed to semiautomatic until the layer is restarted."));
    238223    } else {
    239       SwingUtilities.invokeLater(() -> tooBigErrorDialog());
     224      SwingUtilities.invokeLater(MapillaryDownloader::tooBigErrorDialog);
    240225    }
    241226  }
     
    245230   */
    246231  public static void stopAll() {
    247     /*for (Thread t : threads) {
    248       if (t.isAlive())
    249         Main.info(t+" is still alive!");
    250       t.interrupt();
    251     }
    252     threads.clear();*/
    253232    executor.shutdownNow();
    254233    try {
     
    258237    }
    259238    executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
    260         new ArrayBlockingQueue<Runnable>(100));
     239      new ArrayBlockingQueue<>(100));
    261240  }
    262241}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r32658 r32978  
    100100        synchronized (this) {
    101101          try {
    102             wait(100);
     102            Thread.sleep(100);
    103103          } catch (InterruptedException e) {
     104            return;
    104105          }
    105106        }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java

    r32659 r32978  
    5757          || this.lastClick.previous() == this.data.getHighlightedImage()) {
    5858        MapillaryRecord.getInstance().addCommand(
    59             new CommandUnjoin(Arrays.asList(new MapillaryAbstractImage[] {
    60                 this.lastClick, this.data.getHighlightedImage() })));
     59            new CommandUnjoin(Arrays.asList(this.lastClick, this.data.getHighlightedImage())));
    6160      }
    6261      this.lastClick = null;
Note: See TracChangeset for help on using the changeset viewer.