Skip to content

Commit 5c90a9a

Browse files
committed
Various errorprone fixes
Signed-off-by: Taylor Smock <tsmock@fb.com>
1 parent 49408f8 commit 5c90a9a

File tree

6 files changed

+71
-70
lines changed

6 files changed

+71
-70
lines changed

src/main/java/org/openstreetmap/josm/plugins/mapillary/cache/Caches.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ public V get(@Nonnull String url, @Nonnull Supplier<V> supplier) {
215215
return newReturnObject;
216216
}
217217

218+
/**
219+
* Given a URL, get and cache the response if not already present in a non-blocking manner
220+
*
221+
* @param url The url to get
222+
* @param pool The ForkJoinPool to use
223+
* @param supplier The supplier to get the object with
224+
* @return A future with the object, when it completes.
225+
*/
226+
public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool, @Nonnull Supplier<V> supplier) {
227+
if (this.cacheAccess.get(url) != null) {
228+
return CompletableFuture.completedFuture(this.cacheAccess.get(url));
229+
}
230+
return pool.submit(() -> get(url, supplier));
231+
}
232+
218233
/**
219234
* Check an object for issues
220235
*
@@ -242,21 +257,6 @@ private String checkReturnObject(V returnObject) {
242257
return UNKNOWN_MAPILLARY_EXCEPTION;
243258
}
244259

245-
/**
246-
* Given a URL, get and cache the response if not already present in a non-blocking manner
247-
*
248-
* @param url The url to get
249-
* @param pool The ForkJoinPool to use
250-
* @param supplier The supplier to get the object with
251-
* @return A future with the object, when it completes.
252-
*/
253-
public Future<V> get(@Nonnull String url, @Nonnull ForkJoinPool pool, @Nonnull Supplier<V> supplier) {
254-
if (this.cacheAccess.get(url) != null) {
255-
return CompletableFuture.completedFuture(this.cacheAccess.get(url));
256-
}
257-
return pool.submit(() -> get(url, supplier));
258-
}
259-
260260
/**
261261
* Get the underlying cache
262262
*

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/DataMouseListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void mouseClicked(MouseEvent e) {
5858
* @param layer The layer we found
5959
* @param searchBBox The bbox to search
6060
*/
61-
private void mouseClickedInner(final MouseEvent e, final MVTLayer layer, final BBox searchBBox) {
61+
private static void mouseClickedInner(final MouseEvent e, final MVTLayer layer, final BBox searchBBox) {
6262
Collection<VectorNode> nodes = layer.getData().searchNodes(searchBBox).stream().distinct()
6363
.filter(AbstractPrimitive::isVisible).collect(Collectors.toList());
6464
if (!nodes.isEmpty()) {

src/main/java/org/openstreetmap/josm/plugins/mapillary/gui/imageinfo/ImageInfoPanel.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ public static synchronized void destroyInstance() {
198198
instance = null;
199199
}
200200

201-
/*
202-
* (non-Javadoc)
203-
* @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#stateChanged()
204-
*/
205201
@Override
206202
protected void stateChanged() {
207203
super.stateChanged();
@@ -210,6 +206,13 @@ protected void stateChanged() {
210206
}
211207
}
212208

209+
@Override
210+
public synchronized void selectionChanged(final DataSelectionListener.SelectionChangeEvent event) {
211+
final Collection<OsmPrimitive> sel = event.getSelection();
212+
Logging.debug(String.format("Selection changed. %d primitives are selected.", sel == null ? 0 : sel.size()));
213+
addMapillaryTagAction.setTarget(sel != null && sel.size() == 1 ? sel.iterator().next() : null);
214+
}
215+
213216
@Override
214217
public synchronized void selectionChanged(
215218
final IDataSelectionListener.SelectionChangeEvent<VectorPrimitive, VectorNode, VectorWay, VectorRelation, VectorDataSet> selectionChanged) {
@@ -298,17 +301,6 @@ private void selectedImageChanged(@Nullable INode oldImage, @Nullable INode newI
298301
}
299302
}
300303

301-
/*
302-
* (non-Javadoc)
303-
* @see org.openstreetmap.josm.data.SelectionChangedListener#selectionChanged(java.util.Collection)
304-
*/
305-
@Override
306-
public synchronized void selectionChanged(final DataSelectionListener.SelectionChangeEvent event) {
307-
final Collection<OsmPrimitive> sel = event.getSelection();
308-
Logging.debug(String.format("Selection changed. %d primitives are selected.", sel == null ? 0 : sel.size()));
309-
addMapillaryTagAction.setTarget(sel != null && sel.size() == 1 ? sel.iterator().next() : null);
310-
}
311-
312304
@Override
313305
public void destroy() {
314306
if (!destroyed) {

src/main/java/org/openstreetmap/josm/plugins/mapillary/model/ImageDetection.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ public enum Options {
7979

8080
private DetectionVerification.TYPE approvalType;
8181

82-
/**
83-
* Get the detections for an image key
84-
*
85-
* @param key The image key
86-
* @param listener The consumer to notify when the detections are downloaded
87-
* @return A ForkJoinTask (just in case it needs to be cancelled)
88-
*/
89-
public static ImageDetectionForkJoinTask getDetections(long key,
90-
BiConsumer<Long, List<ImageDetection<?>>> listener) {
91-
return (ImageDetectionForkJoinTask) MapillaryUtils.getForkJoinPool()
92-
.submit(new ImageDetectionForkJoinTask(key, listener));
93-
}
94-
9582
/**
9683
* Get detections at some later time
9784
*
@@ -120,6 +107,19 @@ public static void getDetectionsLaterOptional(final long key,
120107
}
121108
}
122109

110+
/**
111+
* Get the detections for an image key
112+
*
113+
* @param key The image key
114+
* @param listener The consumer to notify when the detections are downloaded
115+
* @return A ForkJoinTask (just in case it needs to be cancelled)
116+
*/
117+
public static ImageDetectionForkJoinTask getDetections(long key,
118+
BiConsumer<Long, List<ImageDetection<?>>> listener) {
119+
return (ImageDetectionForkJoinTask) MapillaryUtils.getForkJoinPool()
120+
.submit(new ImageDetectionForkJoinTask(key, listener));
121+
}
122+
123123
/**
124124
* Get the detections for an image key
125125
*

src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryImageUtils.java

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javax.swing.SwingUtilities;
2525

2626
import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
27+
import org.openstreetmap.josm.data.cache.CacheEntry;
2728
import org.openstreetmap.josm.data.osm.INode;
2829
import org.openstreetmap.josm.data.osm.IPrimitive;
2930
import org.openstreetmap.josm.data.osm.IWay;
@@ -53,10 +54,7 @@ public final class MapillaryImageUtils {
5354

5455
/**
5556
* A pattern to look for strings that are only numbers -- mostly used during switchover from v3 to v4 API
56-
*
57-
* @deprecated Figure out if this needs to be kept
5857
*/
59-
@Deprecated
6058
private static final Pattern NUMBERS = Pattern.compile("\\d+");
6159

6260
/**
@@ -137,18 +135,7 @@ public static double getAngle(@Nonnull INode img) {
137135
public static Future<BufferedImageCacheEntry> getImage(@Nonnull INode image) {
138136
if (MapillaryImageUtils.IS_DOWNLOADABLE.test(image)) {
139137
CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
140-
CacheUtils.submit(image, (entry, attributes, result) -> {
141-
if (entry instanceof BufferedImageCacheEntry) {
142-
// Using the BufferedImageCacheEntry may speed up processing, if the image is already loaded.
143-
completableFuture.complete((BufferedImageCacheEntry) entry);
144-
} else if (entry != null && entry.getContent() != null) {
145-
// Fall back. More expensive if the image has already been loaded twice.
146-
completableFuture.complete(new BufferedImageCacheEntry(entry.getContent()));
147-
} else {
148-
completableFuture.completeExceptionally(
149-
new NullPointerException("MapillaryImageUtils#getImage did not have required information"));
150-
}
151-
});
138+
CacheUtils.submit(image, (entry, attributes, result) -> cacheImageFuture(completableFuture, entry));
152139
return completableFuture;
153140
} else if (getKey(image) > 0) {
154141
try {
@@ -167,6 +154,26 @@ public static Future<BufferedImageCacheEntry> getImage(@Nonnull INode image) {
167154
return CompletableFuture.completedFuture(null);
168155
}
169156

157+
/**
158+
* Complete a future with an entry. This should be called on a separate thread when the entry is ready.
159+
*
160+
* @param completableFuture The future to complete when the data is downloaded
161+
* @param entry The entry to put in the future
162+
*/
163+
private static void cacheImageFuture(CompletableFuture<BufferedImageCacheEntry> completableFuture,
164+
CacheEntry entry) {
165+
if (entry instanceof BufferedImageCacheEntry) {
166+
// Using the BufferedImageCacheEntry may speed up processing, if the image is already loaded.
167+
completableFuture.complete((BufferedImageCacheEntry) entry);
168+
} else if (entry != null && entry.getContent() != null) {
169+
// Fall back. More expensive if the image has already been loaded twice.
170+
completableFuture.complete(new BufferedImageCacheEntry(entry.getContent()));
171+
} else {
172+
completableFuture.completeExceptionally(
173+
new NullPointerException("MapillaryImageUtils#getImage did not have required information"));
174+
}
175+
}
176+
170177
/**
171178
* Get the captured at time
172179
*
@@ -267,16 +274,6 @@ public static Future<Void> downloadImageDetails(@Nonnull INode... images) {
267274
}, MapillaryUtils.getForkJoinPool());
268275
}
269276

270-
/**
271-
* Check if the node has one of the Mapillary keys
272-
*
273-
* @param node The node to check
274-
* @return {@code true} if the node is for an image
275-
*/
276-
public static boolean isImage(@Nullable IPrimitive node) {
277-
return node instanceof INode && node.hasKey(ImageProperties.ID.toString());
278-
}
279-
280277
/**
281278
* Get image details for some specific keys
282279
*
@@ -295,13 +292,26 @@ private static void downloadImageDetails(long... keys) {
295292
return null;
296293
}
297294
});
295+
if (cacheData == null) {
296+
return;
297+
}
298298
try (JsonReader reader = Json
299299
.createReader(new ByteArrayInputStream(cacheData.getBytes(StandardCharsets.UTF_8)))) {
300300
JsonDecoder.decodeData(reader.readObject(), JsonImageDetailsDecoder::decodeImageInfos);
301301
}
302302
}
303303
}
304304

305+
/**
306+
* Check if the node has one of the Mapillary keys
307+
*
308+
* @param node The node to check
309+
* @return {@code true} if the node is for an image
310+
*/
311+
public static boolean isImage(@Nullable IPrimitive node) {
312+
return node instanceof INode && node.hasKey(ImageProperties.ID.toString());
313+
}
314+
305315
/**
306316
* Get the organization for an image
307317
*

src/main/java/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
*/
4343
public final class MapillaryUtils {
4444

45-
private static final double MIN_ZOOM_SQUARE_SIDE = 0.002;
4645
private static final Map<String, ForkJoinPool> forkJoinPool = new HashMap<>();
4746
private static final long[] EMPTY_LONG = new long[0];
4847

0 commit comments

Comments
 (0)