Changeset 32979 in osm for applications/editors/josm


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

Trying to improve inspection results

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

Legend:

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

    r32383 r32979  
    88import java.util.concurrent.ConcurrentHashMap;
    99import java.util.concurrent.CopyOnWriteArrayList;
     10import java.util.stream.Collectors;
    1011
    1112import org.openstreetmap.josm.Main;
     
    143144   */
    144145  public void addMultiSelectedImage(Set<MapillaryAbstractImage> images) {
    145     for (MapillaryAbstractImage image : images) {
    146       if (!this.multiSelectedImages.contains(image)) {
    147         if (this.getSelectedImage() == null) {
    148           this.setSelectedImage(image);
    149         } else {
    150           this.multiSelectedImages.add(image);
    151         }
    152       }
    153     }
     146    images.stream().filter(image -> !this.multiSelectedImages.contains(image)).forEach(image -> {
     147      if (this.getSelectedImage() == null) {
     148        this.setSelectedImage(image);
     149      } else {
     150        this.multiSelectedImages.add(image);
     151      }
     152    });
    154153    Main.map.mapView.repaint();
    155154  }
     
    186185   */
    187186  public synchronized void remove(Set<MapillaryAbstractImage> images) {
    188     for (MapillaryAbstractImage img : images) {
    189       remove(img);
    190     }
     187    images.forEach(this::remove);
    191188  }
    192189
     
    240237   */
    241238  public synchronized Set<MapillarySequence> getSequences() {
    242     Set<MapillarySequence> result = new HashSet<>();
    243     for (MapillaryAbstractImage img : getImages()) {
    244       result.add(img.getSequence());
    245     }
     239    Set<MapillarySequence> result = getImages().stream().map(MapillaryAbstractImage::getSequence).collect(Collectors.toSet());
    246240    return result;
    247241  }
     
    259253    if (this.listeners.isEmpty())
    260254      return;
    261     for (MapillaryDataListener lis : this.listeners) {
    262       if (lis != null)
    263         lis.imagesAdded();
    264     }
     255    this.listeners.stream().filter(lis -> lis != null).forEach(MapillaryDataListener::imagesAdded);
    265256  }
    266257
     
    385376    if (this.listeners.isEmpty())
    386377      return;
    387     for (MapillaryDataListener lis : this.listeners) {
    388       if (lis != null)
    389         lis.selectedImageChanged(oldImage, newImage);
    390     }
     378    this.listeners.stream().filter(lis -> lis != null).forEach(lis -> lis.selectedImageChanged(oldImage, newImage));
    391379  }
    392380
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r32974 r32979  
    8383  @Override
    8484  public boolean equals(Object other) {
    85     if (other != null && other.getClass() == this.getClass())
    86       return this.file.equals(((MapillaryImportedImage) other).file);
    87     return false;
     85    return other != null && other.getClass() == this.getClass() && this.file.equals(((MapillaryImportedImage) other).file);
    8886  }
    8987
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r32974 r32979  
    6969 *
    7070 * @author nokutu
    71  *
    7271 */
    7372public final class MapillaryLayer extends AbstractModifiableLayer implements
    74     DataSetListener, ActiveLayerChangeListener {
     73  DataSetListener, ActiveLayerChangeListener {
    7574
    7675  /** Maximum distance for the red/blue lines. */
    7776  public static final int SEQUENCE_MAX_JUMP_DISTANCE = Main.pref.getInteger(
    78       "mapillary.sequence-max-jump-distance", 100);
     77    "mapillary.sequence-max-jump-distance", 100);
    7978
    8079  /** If the download is in semiautomatic during this object lifetime. */
     
    132131    if (Main.main != null) {
    133132      MapillaryMainDialog.getInstance()
    134           .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
    135           .put(KeyStroke.getKeyStroke("DELETE"), "MapillaryDel");
     133        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
     134        .put(KeyStroke.getKeyStroke("DELETE"), "MapillaryDel");
    136135      MapillaryMainDialog.getInstance().getActionMap()
    137           .put("MapillaryDel", new DeleteImageAction());
     136        .put("MapillaryDel", new DeleteImageAction());
    138137    }
    139138
     
    146145   * Changes the mode the the given one.
    147146   *
    148    * @param mode
    149    *          The mode that is going to be activated.
     147   * @param mode The mode that is going to be activated.
    150148   */
    151149  public void setMode(AbstractMode mode) {
     
    354352        if (imageAbs instanceof MapillaryImage && !((MapillaryImage) imageAbs).getSigns().isEmpty()) {
    355353          g.drawImage(
    356               MapillaryPlugin.MAP_SIGN.getImage(),
    357               p.x - MapillaryPlugin.MAP_SIGN.getIconWidth() / 2,
    358               p.y - MapillaryPlugin.MAP_SIGN.getIconHeight() / 2,
    359               Main.map.mapView
     354            MapillaryPlugin.MAP_SIGN.getImage(),
     355            p.x - MapillaryPlugin.MAP_SIGN.getIconWidth() / 2,
     356            p.y - MapillaryPlugin.MAP_SIGN.getIconHeight() / 2,
     357            Main.map.mapView
    360358          );
    361359        }
     
    370368   * Draws the highlight of the icon.
    371369   *
    372    * @param g  the graphics context
    373    * @param p  the {@link Point} where the image must be set.
    374    * @param size  the width in pixels of the highlight.
     370   * @param g the graphics context
     371   * @param p the {@link Point} where the image must be set.
     372   * @param size the width in pixels of the highlight.
    375373   */
    376374  private void drawPointHighlight(Graphics2D g, Point p, int size) {
     
    378376    Color highlightColor = PaintColors.HIGHLIGHT.get();
    379377    Color highlightColorTransparent = new Color(highlightColor.getRed(),
    380         highlightColor.getGreen(), highlightColor.getBlue(), 100);
     378      highlightColor.getGreen(), highlightColor.getBlue(), 100);
    381379    g.setColor(highlightColorTransparent);
    382380    int s = size + this.highlightPointRadius;
     
    393391   * image.
    394392   *
    395    * @param g  the graphics context
    396    * @param image  The {@link MapillaryAbstractImage} which is being drown.
    397    * @param icon  The {@link ImageIcon} that represents the image.
    398    * @param p  The P¡{@link Point} when the image lies.
     393   * @param g the graphics context
     394   * @param image The {@link MapillaryAbstractImage} which is being drown.
     395   * @param icon The {@link ImageIcon} that represents the image.
     396   * @param p The P¡{@link Point} when the image lies.
    399397   */
    400398  private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon, Point p) {
     
    430428  public void mergeFrom(Layer from) {
    431429    throw new UnsupportedOperationException(
    432         "This layer does not support merging yet");
     430      "This layer does not support merging yet");
    433431  }
    434432
     
    447445   *
    448446   * @return An array of length 2 containing the two closest images belonging to
    449    *         different sequences.
     447   * different sequences.
    450448   */
    451449  private MapillaryImage[] getClosestImagesFromDifferentSequences() {
     
    455453    MapillaryImage[] ret = new MapillaryImage[2];
    456454    double[] distances = {
    457         SEQUENCE_MAX_JUMP_DISTANCE,
    458         SEQUENCE_MAX_JUMP_DISTANCE
     455      SEQUENCE_MAX_JUMP_DISTANCE,
     456      SEQUENCE_MAX_JUMP_DISTANCE
    459457    };
    460458    LatLon selectedCoords = this.data.getSelectedImage().getMovingLatLon();
     
    466464      MapillaryImage image = (MapillaryImage) imagePrev;
    467465      if (image.getMovingLatLon().greatCircleDistance(selectedCoords) < SEQUENCE_MAX_JUMP_DISTANCE
    468           && selected.getSequence() != image.getSequence()) {
     466        && selected.getSequence() != image.getSequence()) {
    469467        if (
    470             ret[0] == null && ret[1] == null
     468          ret[0] == null && ret[1] == null
    471469            || image.getMovingLatLon().greatCircleDistance(selectedCoords) < distances[0]
    472470            && (ret[1] == null || image.getSequence() != ret[1].getSequence())
    473         ) {
     471          ) {
    474472          ret[0] = image;
    475473          distances[0] = image.getMovingLatLon().greatCircleDistance(selectedCoords);
    476474        } else if ((ret[1] == null || image.getMovingLatLon().greatCircleDistance(
    477             selectedCoords) < distances[1])
    478             && image.getSequence() != ret[0].getSequence()) {
     475          selectedCoords) < distances[1])
     476          && image.getSequence() != ret[0].getSequence()) {
    479477          ret[1] = image;
    480478          distances[1] = image.getMovingLatLon().greatCircleDistance(selectedCoords);
     
    492490  @Override
    493491  public Object getInfoComponent() {
    494     return new StringBuilder(35)
    495       .append(tr("Mapillary layer"))
    496       .append('\n')
    497       .append(tr("Total images:"))
    498       .append(' ')
    499       .append(this.data.size())
    500       .append('\n')
    501       .toString();
     492    return tr("Mapillary layer") +
     493      '\n' +
     494      tr("Total images:") +
     495      ' ' +
     496      this.data.size() +
     497      '\n';
    502498  }
    503499
     
    574570   *
    575571   * @author nokutu
    576    *
    577572   */
    578573  private static class DelayedDownload extends Thread {
     
    593588   *
    594589   * @author nokutu
    595    *
    596590   */
    597591  private class DeleteImageAction extends AbstractAction {
     
    603597      if (instance != null)
    604598        MapillaryRecord.getInstance().addCommand(
    605             new CommandDelete(getData().getMultiSelectedImages()));
     599          new CommandDelete(getData().getMultiSelectedImages()));
    606600    }
    607601  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLocationChangeset.java

    r32593 r32979  
    2121
    2222  private void fireListeners() {
    23     for (MapillaryChangesetListener listener : listeners) {
    24       listener.changesetChanged();
    25     }
     23    listeners.forEach(MapillaryChangesetListener::changesetChanged);
    2624  }
    2725
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySign.java

    r32977 r32979  
    11package org.openstreetmap.josm.plugins.mapillary;
    2 
    3 import org.openstreetmap.josm.Main;
    42
    53import java.io.BufferedReader;
    64import java.io.IOException;
    75import java.io.InputStreamReader;
    8 import java.nio.charset.Charset;
    96import java.util.HashMap;
    107import java.util.Map;
    118import java.util.Optional;
    129
     10import org.openstreetmap.josm.Main;
     11
    1312/**
    14  * Created by nokutu on 30/07/16.
     13 * Each {@link MapillarySign} represents a traffic sign detected by the Mapillary's system.
     14 *
     15 * @author nokutu
    1516 */
    1617public class MapillarySign {
     
    3334        BufferedReader br = new BufferedReader(new InputStreamReader(
    3435          MapillarySign.class.getResourceAsStream("/data/signs/" + country + ".cson"), "UTF-8"
    35         ));
     36        ))
    3637      ) {
    3738        String line = "";
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java

    r32978 r32979  
    7979          if (image instanceof MapillaryImage) {
    8080            if (!images.contains(image)) {
    81               images.addAll(((MapillaryImage) image).getSequence().getImages());
     81              images.addAll(image.getSequence().getImages());
    8282            }
    8383          } else {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java

    r32977 r32979  
    148148      this.interrupt();
    149149    } else {
    150       SwingUtilities.invokeLater(() -> stopWalk());
     150      SwingUtilities.invokeLater(this::stopWalk);
    151151    }
    152152  }
     
    161161      MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.MODE.NORMAL);
    162162    } else {
    163       SwingUtilities.invokeLater(() -> end());
     163      SwingUtilities.invokeLater(this::end);
    164164    }
    165165  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/CacheUtils.java

    r32374 r32979  
    2727    FULL_IMAGE,
    2828    /** Both of them */
    29     BOTH;
     29    BOTH
    3030  }
    3131
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java

    r32974 r32979  
    4444   */
    4545  public MapillaryCache(String key, Type type) {
    46     super(MapillaryPlugin.getCache(), 50000, 50000, new HashMap<String, String>());
     46    super(MapillaryPlugin.getCache(), 50000, 50000, new HashMap<>());
    4747    String k = null;
    4848    URL u = null;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r32653 r32979  
    112112    LinkPopUp(final String key) {
    113113      this.copy = new JMenuItem(tr("Copy key"));
    114       this.copy.addActionListener(new ActionListener() {
    115         @Override
    116         public void actionPerformed(ActionEvent paramActionEvent) {
    117           Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(key), null);
    118         }
    119       });
     114      this.copy.addActionListener(paramActionEvent -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(key), null));
    120115      add(this.copy);
    121116
    122117      this.copyTag = new JMenuItem(tr("Copy key tag"));
    123       this.copyTag.addActionListener(new ActionListener() {
    124         @Override
    125         public void actionPerformed(ActionEvent paramActionEvent) {
    126           Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("mapillary=" + key), null);
    127         }
    128       });
     118      this.copyTag.addActionListener(paramActionEvent -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("mapillary=" + key), null));
    129119      add(this.copyTag);
    130120
    131121      this.edit = new JMenuItem(tr("Edit on website"));
    132       this.edit.addActionListener(new ActionListener() {
    133         @Override
    134         public void actionPerformed(ActionEvent paramActionEvent) {
    135           try {
    136             MapillaryUtils.browse(MapillaryURL.browseEditURL(key));
    137           } catch (IOException e) {
    138             Main.error(e);
    139           }
     122      this.edit.addActionListener(paramActionEvent -> {
     123        try {
     124          MapillaryUtils.browse(MapillaryURL.browseEditURL(key));
     125        } catch (IOException e) {
     126          Main.error(e);
    140127        }
    141128      });
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryChangesetDialog.java

    r32974 r32979  
    1010import java.awt.event.ActionEvent;
    1111import java.awt.event.KeyEvent;
    12 import java.util.Arrays;
     12import java.util.Collections;
    1313import java.util.concurrent.ConcurrentHashMap;
    1414
     
    9797    this.submitButton = new SideButton(new SubmitAction());
    9898
    99     createLayout(treesPanel, true, Arrays.asList(new SideButton[] { this.submitButton }));
     99    createLayout(treesPanel, true, Collections.singletonList(this.submitButton));
    100100    buildTree();
    101101  }
     
    124124
    125125    this.map.clear();
    126     for (MapillaryImage command : changeset) {
    127       if (command != null) {
    128         DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
    129         this.map.put(node, command);
    130         changesetRoot.add(node);
    131       }
    132     }
     126    changeset.parallelStream().filter(command -> command != null).forEach(command -> {
     127      DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
     128      this.map.put(node, command);
     129      changesetRoot.add(node);
     130    });
    133131
    134132    this.spacer.setVisible(changeset.isEmpty());
     
    140138  public void changesetChanged() {
    141139    if (!SwingUtilities.isEventDispatchThread()) {
    142       SwingUtilities.invokeLater(() -> buildTree());
     140      SwingUtilities.invokeLater(this::buildTree);
    143141    } else {
    144142      buildTree();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r32373 r32979  
    8383    // Some options are disabled depending on the circumstances
    8484    if (!(MapillaryLayer.getInstance().getData().getSelectedImage() instanceof MapillaryImage)
    85         || ((MapillaryImage) MapillaryLayer.getInstance().getData().getSelectedImage()).getSequence() == null
     85        || MapillaryLayer.getInstance().getData().getSelectedImage().getSequence() == null
    8686    ) {
    8787      this.sequence.setEnabled(false);
     
    9090      this.selected.setEnabled(false);
    9191    }
    92     this.rewrite.setEnabled(false);
    93     for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData().getImages()) {
    94       if (img instanceof MapillaryImportedImage) {
    95         this.rewrite.setEnabled(true);
    96       }
    97     }
     92    this.rewrite.setEnabled(MapillaryLayer.getInstance().getData().getImages().parallelStream().anyMatch(img -> img instanceof MapillaryImportedImage));
    9893
    9994    this.path = new JLabel(tr("Select a folder"));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r32974 r32979  
    5151
    5252  private static final String[] TIME_LIST = {tr("All"), tr("Years"), tr("Months"), tr("Days")};
     53
     54  private final static long[] TIME_FACTOR = new long[]{
     55    31_536_000_000L, // = 365 * 24 * 60 * 60 * 1000 = number of ms in a year
     56    2_592_000_000L, // = 30 * 24 * 60 * 60 * 1000 = number of ms in a month
     57    86_400_000 // = 24 * 60 * 60 * 1000 = number of ms in a day
     58  };
    5359
    5460  /**
     
    136142    panel.add(signChooserPanel, c);
    137143
    138     createLayout(panel, true, Arrays.asList(new SideButton[]{updateButton, resetButton}));
     144    createLayout(panel, true, Arrays.asList(updateButton, resetButton));
    139145  }
    140146
     
    197203  private boolean checkValidTime(MapillaryAbstractImage img) {
    198204    Long currentTime = currentTime();
    199     long[] timeFactor = new long[]{
    200       31_536_000_000L, // = 365 * 24 * 60 * 60 * 1000 = number of ms in a year
    201       2_592_000_000L, // = 30 * 24 * 60 * 60 * 1000 = number of ms in a month
    202       86_400_000 // = 24 * 60 * 60 * 1000 = number of ms in a day
    203     };
    204205    for (int i = 1; i <= 3; i++) {
    205       if (TIME_LIST[i].equals(time.getSelectedItem())
    206         && img.getCapturedAt() < currentTime - ((Integer) spinner.getValue()).longValue() * timeFactor[i - 1]
    207         ) {
     206      if (TIME_LIST[i].equals(time.getSelectedItem()) &&
     207        img.getCapturedAt() < currentTime - ((Integer) spinner.getValue()).longValue() * TIME_FACTOR[i - 1]) {
    208208        return true;
    209209      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r32690 r32979  
    112112    this.redoButton = new SideButton(new RedoAction());
    113113
    114     createLayout(treesPanel, true, Arrays.asList(new SideButton[] {this.undoButton, this.redoButton}));
     114    createLayout(treesPanel, true, Arrays.asList(this.undoButton, this.redoButton));
    115115  }
    116116
     
    148148
    149149    this.map.clear();
    150     for (MapillaryCommand command : undoCommands) {
    151       if (command != null) {
    152         DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
    153         this.map.put(node, command);
    154         undoRoot.add(node);
    155       }
    156     }
    157     for (MapillaryCommand command : redoCommands) {
    158       if (command != null) {
    159         DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
    160         this.map.put(node, command);
    161         redoRoot.add(node);
    162       }
    163     }
     150    undoCommands.stream().filter(command -> command != null).forEach(command -> {
     151      DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
     152      this.map.put(node, command);
     153      undoRoot.add(node);
     154    });
     155    redoCommands.stream().filter(command -> command != null).forEach(command -> {
     156      DefaultMutableTreeNode node = new DefaultMutableTreeNode(command.toString());
     157      this.map.put(node, command);
     158      redoRoot.add(node);
     159    });
    164160
    165161    this.separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty());
     
    173169  public void recordChanged() {
    174170    if (!SwingUtilities.isEventDispatchThread()) {
    175       SwingUtilities.invokeLater(() -> recordChanged());
     171      SwingUtilities.invokeLater(this::recordChanged);
    176172    } else {
    177173      buildTree();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r32690 r32979  
    8484     * Mode when in walk.
    8585     */
    86     WALK;
     86    WALK
    8787  }
    8888
     
    149149        createLayout(
    150150          this.mapillaryImageDisplay,
    151           Arrays.asList(new SideButton[]{playButton, pauseButton, stopButton})
     151          Arrays.asList(playButton, pauseButton, stopButton)
    152152        );
    153153        break;
     
    156156        createLayout(
    157157          this.mapillaryImageDisplay,
    158           Arrays.asList(new SideButton[]{blueButton, previousButton, nextButton, redButton})
     158          Arrays.asList(blueButton, previousButton, nextButton, redButton)
    159159        );
    160160        break;
     
    190190  public synchronized void updateImage(boolean fullQuality) {
    191191    if (!SwingUtilities.isEventDispatchThread()) {
    192       SwingUtilities.invokeLater(() -> updateImage());
     192      SwingUtilities.invokeLater(this::updateImage);
    193193    } else {
    194194      if (!MapillaryLayer.hasInstance()) {
     
    293293  public synchronized void updateTitle() {
    294294    if (!SwingUtilities.isEventDispatchThread()) {
    295       SwingUtilities.invokeLater(() -> updateTitle());
     295      SwingUtilities.invokeLater(this::updateTitle);
    296296    } else if (this.image != null) {
    297297      StringBuilder title = new StringBuilder(tr(BASE_TITLE));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r32974 r32979  
    4747 */
    4848public class MapillaryPreferenceSetting implements SubPreferenceSetting, MapillaryLoginListener {
     49
    4950  private final JComboBox<String> downloadModeComboBox = new JComboBox<>(new String[]{
    5051      DOWNLOAD_MODE.VISIBLE_AREA.getLabel(),
     
    154155  @Override
    155156  public boolean ok() {
    156     boolean mod = false;
    157 
    158157    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false);
    159158    Main.pref.put(
     
    171170    Main.pref.put("mapillary.move-to-picture", this.moveTo.isSelected());
    172171    Main.pref.put("mapillary.hover-enabled", this.hoverEnabled.isSelected());
    173     return mod;
     172
     173    //Restart is enver required
     174    return false;
    174175  }
    175176
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

    r31987 r32979  
    122122
    123123  private void fireRecordChanged() {
    124     for (MapillaryRecordListener lis : this.listeners) {
    125       if (lis != null)
    126         lis.recordChanged();
    127     }
     124    this.listeners.stream().filter(lis -> lis != null).forEach(MapillaryRecordListener::recordChanged);
    128125  }
    129126
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r32978 r32979  
    22package org.openstreetmap.josm.plugins.mapillary.io.download;
    33
    4 import java.util.ArrayList;
    5 import java.util.List;
    64import java.util.concurrent.ArrayBlockingQueue;
    75import java.util.concurrent.ThreadPoolExecutor;
    86import java.util.concurrent.TimeUnit;
    9 import java.util.stream.IntStream;
    107
    118import javax.swing.JOptionPane;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryImageInfoDownloadThread.java

    r32973 r32979  
    4848      BufferedReader br = new BufferedReader(new InputStreamReader(
    4949        MapillaryURL.searchImageInfoURL(bounds, page, null).openStream(), "UTF-8"
    50       ));
     50      ))
    5151    ) {
    5252      try (JsonReader reader = Json.createReader(br)) {
     
    5959          data = jsonArr.getJsonObject(i);
    6060          String key = data.getString("key");
    61           for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) {
    62             if (
    63               image instanceof MapillaryImage
    64                 && ((MapillaryImage) image).getKey().equals(key)
    65                 && ((MapillaryImage) image).getUser() == null
    66               ) {
    67               ((MapillaryImage) image).setUser(data.getString("user"));
    68               ((MapillaryImage) image).setCapturedAt(data.getJsonNumber("captured_at").longValue());
    69               if (!data.isNull("location")) {
    70                 ((MapillaryImage) image).setLocation(data.getString("location"));
    71               }
     61          MapillaryLayer.getInstance().getData().getImages().stream().filter(image -> image instanceof MapillaryImage
     62            && ((MapillaryImage) image).getKey().equals(key)
     63            && ((MapillaryImage) image).getUser() == null).forEach(image -> {
     64            ((MapillaryImage) image).setUser(data.getString("user"));
     65            image.setCapturedAt(data.getJsonNumber("captured_at").longValue());
     66            if (!data.isNull("location")) {
     67              ((MapillaryImage) image).setLocation(data.getString("location"));
    7268            }
    73           }
     69          });
    7470        }
    7571      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThread.java

    r32383 r32979  
    99import java.util.concurrent.ConcurrentSkipListSet;
    1010import java.util.concurrent.ExecutorService;
     11import java.util.stream.Collectors;
    1112
    1213import javax.json.Json;
     
    4041   * Main constructor.
    4142   *
    42    * @param ex     {@link ExecutorService} executing this thread.
     43   * @param ex {@link ExecutorService} executing this thread.
    4344   * @param bounds The bounds inside which the sequences should be downloaded
    44    * @param page   the pagenumber of the results that should be retrieved
     45   * @param page the pagenumber of the results that should be retrieved
    4546   */
    4647  public MapillarySequenceDownloadThread(ExecutorService ex, Bounds bounds, int page) {
     
    5354  public void run() {
    5455    try (
    55         BufferedReader br = new BufferedReader(new InputStreamReader(
    56             MapillaryURL.searchSequenceURL(bounds, page).openStream(), "UTF-8"
    57         ));
     56      BufferedReader br = new BufferedReader(new InputStreamReader(
     57        MapillaryURL.searchSequenceURL(bounds, page).openStream(), "UTF-8"
     58      ))
    5859    ) {
    5960      JsonObject jsonall = Json.createReader(br).readObject();
     
    7273          try {
    7374            images.add(new MapillaryImage(
    74                 keys.getString(j),
    75                 new LatLon(
    76                     coords.getJsonArray(j).getJsonNumber(1).doubleValue(),
    77                     coords.getJsonArray(j).getJsonNumber(0).doubleValue()
    78                 ),
    79                 cas.getJsonNumber(j).doubleValue()));
     75              keys.getString(j),
     76              new LatLon(
     77                coords.getJsonArray(j).getJsonNumber(1).doubleValue(),
     78                coords.getJsonArray(j).getJsonNumber(0).doubleValue()
     79              ),
     80              cas.getJsonNumber(j).doubleValue()));
    8081          } catch (IndexOutOfBoundsException e) {
    8182            Main.warn("Mapillary bug at " + MapillaryURL.searchSequenceURL(bounds, page));
     
    8687          break;
    8788        MapillarySequence sequence = new MapillarySequence(
    88                 jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at")
    89                 .longValue());
     89          jsonobj.getString("key"), jsonobj.getJsonNumber("captured_at")
     90          .longValue());
    9091        List<MapillaryImage> finalImages = new ArrayList<>(images);
    9192        // Here it gets only those images which are in the downloaded
    9293        // area.
    93         for (MapillaryAbstractImage img : images) {
    94           if (!isInside(img))
    95             finalImages.remove(img);
    96         }
    97         synchronized (this.getClass()) {
     94        finalImages = images.parallelStream().filter(MapillarySequenceDownloadThread::isInside).collect(Collectors.toList());
     95
     96        synchronized (MapillarySequenceDownloadThread.class) {
    9897          synchronized (MapillaryAbstractImage.class) {
    9998            for (MapillaryImage img : finalImages) {
     
    101100                // The image in finalImages is substituted by the one in the
    102101                // database, as they represent the same picture.
    103                 for (MapillaryAbstractImage source : MapillaryLayer.getInstance().getData().getImages()) {
    104                   if (source.equals(img)) {
    105                     img = (MapillaryImage) source;
    106                   }
    107                 }
     102
     103                final MapillaryImage lambdaImg = img;
     104                //noinspection OptionalGetWithoutIsPresent
     105                img = (MapillaryImage) MapillaryLayer.getInstance().getData().getImages().parallelStream().filter(source -> source.equals(lambdaImg)).findAny().get();
     106
    108107                sequence.add(img);
    109108                img.setSequence(sequence);
     
    117116        }
    118117
    119         MapillaryLayer.getInstance().getData().add(new ConcurrentSkipListSet<MapillaryAbstractImage>(finalImages), false);
     118        MapillaryLayer.getInstance().getData().add(new ConcurrentSkipListSet<>(finalImages), false);
    120119      }
    121120    } catch (IOException e) {
    122121      Main.error(String.format(
    123           "Error reading the url %s, this might be a Mapillary problem.",
    124           MapillaryURL.searchSequenceURL(bounds, page)
     122        "Error reading the url %s, this might be a Mapillary problem.",
     123        MapillaryURL.searchSequenceURL(bounds, page)
    125124      ), e);
    126125    }
     
    129128
    130129  private static boolean isInside(MapillaryAbstractImage image) {
    131     for (Bounds b : MapillaryLayer.getInstance().getData().getBounds()) {
    132       if (b.contains(image.getMovingLatLon())) {
    133         return true;
    134       }
    135     }
    136     return false;
     130    return MapillaryLayer.getInstance().getData().getBounds().parallelStream().anyMatch(b -> b.contains(image.getLatLon()));
    137131  }
    138132}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryTrafficSignDownloadThread.java

    r32972 r32979  
    55import java.io.IOException;
    66import java.io.InputStreamReader;
    7 import java.net.MalformedURLException;
    87import java.util.concurrent.ExecutorService;
    98
     
    4948            BufferedReader br = new BufferedReader(new InputStreamReader(
    5049                    MapillaryURL.searchImageInfoURL(bounds, page, IMAGE_SELECTOR.OBJ_REC_ONLY).openStream(), "UTF-8"
    51             ));
     50            ))
    5251    ) {
    5352      JsonObject jsonobj = Json.createReader(br).readObject();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportDownloadThread.java

    r31811 r32979  
    6363      CacheEntryAttributes attributes, LoadResult result) {
    6464    try {
    65       synchronized (this.getClass()) {
     65      synchronized (MapillaryExportDownloadThread.class) {
    6666        this.queue
    6767            .put(ImageIO.read(new ByteArrayInputStream(data.getContent())));
    6868        this.queueImages.put(this.image);
    6969      }
    70     } catch (InterruptedException e) {
    71       Main.error(e);
    72     } catch (IOException e) {
     70    } catch (InterruptedException | IOException e) {
    7371      Main.error(e);
    7472    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportManager.java

    r32373 r32979  
    109109    }
    110110    this.ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS,
    111         new ArrayBlockingQueue<Runnable>(10));
     111      new ArrayBlockingQueue<>(10));
    112112    for (MapillaryAbstractImage image : this.images) {
    113113      if (image instanceof MapillaryImage) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportWriterThread.java

    r32383 r32979  
    129129        if (mimg instanceof MapillaryImportedImage) {
    130130          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    131               ((MapillaryImportedImage) mimg).getDate("yyyy/MM/dd HH:mm:ss"));
     131              mimg.getDate("yyyy/MM/dd HH:mm:ss"));
    132132        } else if (mimg instanceof MapillaryImage) {
    133133          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    134               ((MapillaryImage) mimg).getDate("yyyy/MM/dd HH/mm/ss"));
     134              mimg.getDate("yyyy/MM/dd HH/mm/ss"));
    135135        }
    136136        outputSet.setGPSInDegrees(mimg.getMovingLatLon().lon(), mimg.getMovingLatLon().lat());
     
    142142        Main.info("Mapillary export cancelled");
    143143        return;
    144       } catch (IOException e) {
    145         Main.error(e);
    146       } catch (ImageWriteException e) {
    147         Main.error(e);
    148       } catch (ImageReadException e) {
     144      } catch (IOException | ImageReadException | ImageWriteException e) {
    149145        Main.error(e);
    150146      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r32978 r32979  
    5757   * Paint the dataset using the engine set.
    5858   *
    59    * @param g
     59   * @param g {@link Graphics2D} used for painting
    6060   * @param mv
    6161   *          The object that can translate GeoPoints to screen coordinates.
    62    * @param box
     62   * @param box Area where painting is going to be performed
    6363   */
    6464  public abstract void paint(Graphics2D g, MapView mv, Bounds box);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31976 r32979  
    4343        Socket clientSocket = serverSocket.accept();
    4444        PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true);
    45         Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
     45        Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"))
    4646    ) {
    4747      String s;
    4848      String accessToken = null;
    49       while (in.hasNextLine() && accessToken == null) {
     49      while (in.hasNextLine()) {
    5050        s = in.nextLine();
    5151        Matcher tokenMatcher = Pattern.compile("^.*&access_token=([^&]+)&.*$").matcher('&'+s+'&');
     
    7676    } catch (BindException e) {
    7777      Main.warn(e);
    78       return;
    7978    } catch (IOException e) {
    8079      Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r32974 r32979  
    8585      this.images = images;
    8686      this.uuid = UUID.randomUUID();
    87       this.ex = new ThreadPoolExecutor(8, 8, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(15));
     87      this.ex = new ThreadPoolExecutor(8, 8, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<>(15));
    8888      this.delete = delete;
    8989    }
     
    137137   * tags.
    138138   *
    139    * @param image
     139   * @param image The image to be uploaded
    140140   * @return A File object containing the picture and an updated version of the
    141141   * EXIF tags.
     
    145145   * @throws ImageWriteException if there are errors writing the image in the file.
    146146   */
    147   public static File updateFile(MapillaryImportedImage image)
     147  private static File updateFile(MapillaryImportedImage image)
    148148          throws ImageReadException, IOException, ImageWriteException {
    149149    TiffOutputSet outputSet = null;
     
    153153
    154154    // If the image is imported, loads the rest of the EXIF data.
    155     JpegImageMetadata jpegMetadata = null;
    156     try {
    157       ImageMetadata metadata = Imaging.getMetadata(image.getFile());
    158       jpegMetadata = (JpegImageMetadata) metadata;
    159     } catch (Exception e) {
    160     }
     155    ImageMetadata metadata = Imaging.getMetadata(image.getFile());
     156    JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     157
    161158    if (null != jpegMetadata) {
    162159      final TiffImageMetadata exif = jpegMetadata.getExif();
     
    204201   * Uploads the given MapillaryImportedImage object.
    205202   *
    206    * @param image
     203   * @param image The image to be uploaded
     204   * @throws IllegalStateException If {@link MapillaryUser#getSecrets()} returns null
    207205   */
    208206  public static void upload(MapillaryImportedImage image) {
     
    211209
    212210  /**
    213    * @param image
     211   * @param image The image to be uploaded
    214212   * @param uuid  The UUID used to create the sequence.
    215213   */
    216214  public static void upload(MapillaryImportedImage image, UUID uuid) {
    217     String key = new StringBuilder(MapillaryUser.getUsername())
    218       .append('/').append(uuid)
    219       .append('/').append(image.getMovingLatLon().lat()) // TODO: Make sure, that the double values are not appended as something like "10e-4", "Infinity" or "NaN" (all possible values of Double.toString(double))
    220       .append('_').append(image.getMovingLatLon().lon())
    221       .append('_').append(image.getMovingCa())
    222       .append('_').append(image.getCapturedAt())
    223       .append(".jpg")
    224       .toString();
     215    Map<String, String> secretMap = MapillaryUser.getSecrets();
     216    if (secretMap == null) {
     217      throw new IllegalStateException("Can't obtain secrents from user");
     218    }
     219
     220    String key = MapillaryUser.getUsername() +
     221      '/' + uuid +
     222      '/' + image.getMovingLatLon().lat() + // TODO: Make sure, that the double values are not appended as something like "10e-4", "Infinity" or "NaN" (all possible values of Double.toString(double))
     223      '_' + image.getMovingLatLon().lon() +
     224      '_' + image.getMovingCa() +
     225      '_' + image.getCapturedAt() +
     226      ".jpg";
    225227
    226228    String policy;
    227229    String signature;
    228     policy = MapillaryUser.getSecrets().get("images_policy");
    229     signature = MapillaryUser.getSecrets().get("images_hash");
     230    policy = secretMap.get("images_policy");
     231    signature = secretMap.get("images_hash");
    230232
    231233    Map<String, String> hash = new HashMap<>();
     
    244246
    245247  /**
    246    * @param file
    247    * @param hash
    248    * @throws IOException
     248   * @param file File that is going to be uploaded
     249   * @param hash Information attached to the upload
    249250   * @throws IllegalArgumentException if the hash doesn't contain all the needed keys.
    250251   */
    251   public static void uploadFile(File file, Map<String, String> hash) throws IOException {
     252  private static void uploadFile(File file, Map<String, String> hash) throws IOException {
    252253    HttpClientBuilder builder = HttpClientBuilder.create();
    253254    HttpPost httpPost = new HttpPost(UPLOAD_URL);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java

    r32066 r32979  
    109109      // Create Map for country if not already exists
    110110      if (!signs.containsKey(sign.getCountry())) {
    111         signs.put(sign.getCountry(), new TreeMap<String, TrafficoSign>());
     111        signs.put(sign.getCountry(), new TreeMap<>());
    112112      }
    113113      // Don't overwrite existing sign with same country-name-combination
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryColorScheme.java

    r32717 r32979  
    5959      }
    6060      ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    61       ((Graphics2D) g).fillRoundRect(0, 0, getWidth(), getHeight(), 3, 3);
     61      g.fillRoundRect(0, 0, getWidth(), getHeight(), 3, 3);
    6262      super.paintComponent(g);
    6363    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r32690 r32979  
    1010import java.text.ParseException;
    1111import java.text.SimpleDateFormat;
    12 import java.util.ArrayList;
    1312import java.util.Calendar;
    1413import java.util.Locale;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java

    r32690 r32979  
    111111      dlg.setVisible(true);
    112112    } else {
    113       SwingUtilities.invokeLater(() -> finishedUploadDialog());
     113      SwingUtilities.invokeLater(PluginState::finishedUploadDialog);
    114114    }
    115115  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/ValidationUtil.java

    r32403 r32979  
    5656   * @param nullAllowed this controls the behaviour when the key is <code>null</code>. If this variable is
    5757   *          <code>false</code>, an {@link IllegalArgumentException} is then thrown, otherwise nothing is done.
    58    * @see {@link #validateSequenceKey(String)}
     58   * @see #validateSequenceKey(String)
    5959   */
     60  @SuppressWarnings ("ConstantConditions")
    6061  public static void throwExceptionForInvalidSeqKey(String seqKey, boolean nullAllowed) {
    6162    if (!validateSequenceKey(seqKey)) {
Note: See TracChangeset for help on using the changeset viewer.