From 5d81c2906f91b4ad1980a9a9ad7549619bcb1956 Mon Sep 17 00:00:00 2001 From: Taylor Smock Date: Wed, 1 Jul 2020 12:04:14 -0600 Subject: [PATCH] Fix some compile warnings Signed-off-by: Taylor Smock --- .../plugins/mapwithai/MapWithAIPlugin.java | 9 +-- .../actions/AddMapWithAILayerAction.java | 14 ++++- .../backend/DataConflationSender.java | 6 +- .../mapwithai/backend/GetDataRunnable.java | 4 +- .../mapwithai/backend/MapWithAIDataUtils.java | 2 +- .../backend/MapWithAIUploadHook.java | 3 +- .../conflation/AbstractConflationCommand.java | 8 ++- .../conflation/MergeBuildingNodeCommand.java | 60 ------------------- .../commands/AddNodeToWayCommand.java | 8 +++ .../commands/CreateConnectionsCommand.java | 6 ++ .../commands/MapWithAIAddCommand.java | 6 +- .../commands/MergeDuplicateWays.java | 3 +- .../MapWithAIConflationCategory.java | 4 ++ .../data/mapwithai/MapWithAILayerInfo.java | 2 +- .../plugins/mapwithai/gui/MapWithAIMenu.java | 3 +- .../download/MapWithAIDownloadOptions.java | 2 +- .../download/MapWithAIDownloadSourceType.java | 1 - .../gui/preferences/MapWithAIPreferences.java | 16 ++++- .../mapwithai/MapWithAIParametersPanel.java | 10 +++- .../mapwithai/MapWithAIProvidersPanel.java | 12 ++-- .../io/mapwithai/ESRISourceReader.java | 2 +- .../io/mapwithai/MapWithAISourceReader.java | 2 +- .../mapwithai/MapWithAIPluginTest.java | 4 +- .../backend/MapWithAIUploadHookTest.java | 2 - .../commands/MapWithAIAddComandTest.java | 4 +- .../preferences/MapWithAIPreferencesTest.java | 12 ++-- .../ReplacementPreferenceTableTest.java | 8 ++- .../testutils/MapWithAITestRules.java | 8 +-- 28 files changed, 112 insertions(+), 109 deletions(-) delete mode 100644 src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java index 5aaf536..5901330 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPlugin.java @@ -11,7 +11,6 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Optional; import javax.swing.JMenuItem; @@ -63,9 +62,9 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable { private final List destroyables; - private PreferencesAction preferenceAction; + private final PreferencesAction preferenceAction; - private MapWithAIMenu mapwithaiMenu; + private final MapWithAIMenu mapwithaiMenu; private static final Map, Boolean> MENU_ENTRIES = new LinkedHashMap<>(); static { @@ -86,7 +85,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable { mapwithaiMenu = new MapWithAIMenu(); MainApplication.getMenu().addMenu(mapwithaiMenu, "mapwithai:menu", KeyEvent.VK_M, 9, ht("/Plugin/MapWithAI")); - for (final Entry, Boolean> entry : MENU_ENTRIES.entrySet()) { + for (final Map.Entry, Boolean> entry : MENU_ENTRIES.entrySet()) { if (Arrays.asList(mapwithaiMenu.getMenuComponents()).parallelStream().filter(JMenuItem.class::isInstance) .map(JMenuItem.class::cast) .noneMatch(component -> entry.getKey().equals(component.getAction().getClass()))) { @@ -154,6 +153,8 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable { } /** + * The current version for the plugin + * * @return The version information of the plugin */ public static String getVersionInfo() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/actions/AddMapWithAILayerAction.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/actions/AddMapWithAILayerAction.java index 0ef099a..1383814 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/actions/AddMapWithAILayerAction.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/actions/AddMapWithAILayerAction.java @@ -4,6 +4,8 @@ package org.openstreetmap.josm.plugins.mapwithai.actions; import static org.openstreetmap.josm.gui.help.HelpUtil.ht; import java.awt.event.ActionEvent; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import org.openstreetmap.josm.actions.AdaptableAction; import org.openstreetmap.josm.actions.AddImageryLayerAction; @@ -50,11 +52,19 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi // change toolbar icon from if specified String icon = info.getIcon(); if (icon != null) { - new ImageProvider(icon).setOptional(true).getResourceAsync(result -> { + Future future = new ImageProvider(icon).setOptional(true).getResourceAsync(result -> { if (result != null) { GuiHelper.runInEDT(() -> result.attachImageIcon(this)); } }); + try { + future.get(); + } catch (InterruptedException e) { + Logging.error(e); + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + Logging.error(e); + } } else { try { ImageResource resource = new ImageResource( @@ -104,7 +114,7 @@ public class AddMapWithAILayerAction extends JosmAction implements AdaptableActi } } - private OsmDataLayer getDataLayer() { + private static OsmDataLayer getDataLayer() { return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream() .filter(i -> !(i instanceof MapWithAILayer)).findFirst().orElse(null); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataConflationSender.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataConflationSender.java index ed74745..bc1762a 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataConflationSender.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/DataConflationSender.java @@ -40,9 +40,9 @@ import org.openstreetmap.josm.tools.Logging; public class DataConflationSender implements RunnableFuture { private static final int MAX_POLLS = 100; - private DataSet external; - private DataSet osm; - private MapWithAICategory category; + private final DataSet external; + private final DataSet osm; + private final MapWithAICategory category; private DataSet conflatedData; private CloseableHttpClient client; private boolean done; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java index c9b7da0..fc8543e 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/GetDataRunnable.java @@ -303,8 +303,8 @@ public class GetDataRunnable extends RecursiveTask { /** * Replace tags in a dataset with a set of replacement tags * - * @param dataSet The dataset with primitives to change - * @param map The tags to replace + * @param dataSet The dataset with primitives to change + * @param replaceTags The tags to replace */ public static void replaceTags(DataSet dataSet, Map replaceTags) { replaceTags.forEach((orig, replace) -> dataSet.allNonDeletedPrimitives().parallelStream() diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java index 650e7ce..6c4a47d 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIDataUtils.java @@ -60,7 +60,7 @@ public final class MapWithAIDataUtils { public static final String DEFAULT_PAINT_STYLE_RESOURCE_URL = "https://josm.openstreetmap.de/josmfile?page=Styles/MapWithAI&zip=1"; private static String paintStyleResourceUrl = DEFAULT_PAINT_STYLE_RESOURCE_URL; - private static Pattern TEST_PATTERN = Pattern + private static final Pattern TEST_PATTERN = Pattern .compile("^https?:\\/\\/(www\\.)?localhost[:0-9]*\\/josmfile\\?page=Styles\\/MapWithAI&zip=1$"); private MapWithAIDataUtils() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHook.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHook.java index 59d8a3a..4e1df18 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHook.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHook.java @@ -11,8 +11,9 @@ import org.openstreetmap.josm.plugins.PluginInformation; import org.openstreetmap.josm.tools.Destroyable; /** - * @author Taylor Smock + * Add information that is useful for QC/debugging to OSM changesets. * + * @author Taylor Smock */ public class MapWithAIUploadHook implements UploadHook, Destroyable { private final String version; diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/AbstractConflationCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/AbstractConflationCommand.java index f6fd6d9..a17cf96 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/AbstractConflationCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/AbstractConflationCommand.java @@ -39,7 +39,13 @@ import org.openstreetmap.josm.tools.Pair; public abstract class AbstractConflationCommand extends Command { protected Collection possiblyAffectedPrimitives; - public AbstractConflationCommand(DataSet data) { + /** + * Creates a new command in the context of a specific data set, without data + * layer + * + * @param data the data set. Must not be null. + */ + protected AbstractConflationCommand(DataSet data) { super(data); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java deleted file mode 100644 index a558112..0000000 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/backend/commands/conflation/MergeBuildingNodeCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -// License: GPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation; - -import static org.openstreetmap.josm.tools.I18n.tr; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.openstreetmap.josm.command.Command; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.data.osm.OsmPrimitive; -import org.openstreetmap.josm.data.osm.Relation; -import org.openstreetmap.josm.data.osm.Way; - -/** - * This is similar to the ReplaceGeometryUtils.buildUpgradeNodeCommand method - * - * @author Taylor Smock - * - */ -public class MergeBuildingNodeCommand { - /** - * Upgrade a node to a way or multipolygon - * - * @param subjectNode node to be replaced - * @param referenceObject object with greater spatial quality - */ - public static Command buildUpgradeNodeCommand(Node subjectNode, OsmPrimitive referenceObject) { - boolean keepNode = !subjectNode.isNew(); - if (keepNode) { - getNewOrNoTagNode(referenceObject); - } - return null; - } - - private static Node getNewOrNoTagNode(OsmPrimitive referenceObject) { - List nodes; - if (referenceObject instanceof Way) { - nodes = ((Way) referenceObject).getNodes(); - } else if (referenceObject instanceof Relation) { - nodes = ((Relation) referenceObject).getMemberPrimitives().stream().flatMap(o -> { - if (o instanceof Way) { - return ((Way) o).getNodes().stream(); - } else if (o instanceof Node) { - return Stream.of((Node) o); - } - return null; - }).filter(Objects::nonNull).collect(Collectors.toList()); - } else if (referenceObject instanceof Node) { - nodes = Collections.singletonList((Node) referenceObject); - } else { - throw new IllegalArgumentException(tr("Unknown OsmPrimitive type")); - } - return nodes.stream().filter(OsmPrimitive::isNew).findAny() - .orElse(nodes.stream().filter(p -> !p.isTagged()).findAny().orElse(nodes.get(0))); - } -} diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/AddNodeToWayCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/AddNodeToWayCommand.java index c42439e..1af8e6a 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/AddNodeToWayCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/AddNodeToWayCommand.java @@ -93,6 +93,8 @@ public class AddNodeToWayCommand extends Command { } /** + * Get the node that will be added to a way + * * @return {@link Node} to add to {@link Way} */ public Node getToAddNode() { @@ -100,6 +102,8 @@ public class AddNodeToWayCommand extends Command { } /** + * Get the way that we are modifying + * * @return {@link Way} that we are adding a {@link Node} to */ public Way getWay() { @@ -107,6 +111,8 @@ public class AddNodeToWayCommand extends Command { } /** + * Get the node that we are adding our node after + * * @return {@link Node} that we are adding another {@link Node} after. */ public Node getFirstNode() { @@ -114,6 +120,8 @@ public class AddNodeToWayCommand extends Command { } /** + * Get the node that we are adding our node before + * * @return {@link Node} that we are adding another {@link Node} before. */ public Node getSecondNode() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/CreateConnectionsCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/CreateConnectionsCommand.java index e56f058..d9c9eb2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/CreateConnectionsCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/CreateConnectionsCommand.java @@ -148,6 +148,8 @@ public class CreateConnectionsCommand extends Command { } /** + * Add third-party commands that are run when conflating data. + * * @param command A command to run when copying data from the MapWithAI layer */ public static void addConflationCommand(Class command) { @@ -155,6 +157,8 @@ public class CreateConnectionsCommand extends Command { } /** + * Get the commands to run when conflating data. + * * @return A set of commands to run when copying data from the MapWithAI layer */ public static Set> getConflationCommands() { @@ -162,6 +166,8 @@ public class CreateConnectionsCommand extends Command { } /** + * Remove a command that runs when conflating data. + * * @param command The command class to remove * @return {@code true} if the conflation command was removed and was present * @see List#remove diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java index d7e6b79..f9e3531 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddCommand.java @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.concurrent.locks.Lock; import java.util.stream.Collectors; @@ -154,6 +153,9 @@ public class MapWithAIAddCommand extends Command implements Runnable { } /** + * Calculate the number of objects added in this command that are not deleted + * (may not count significantly modified objects as well). + * * @return The number of MapWithAI objects added in this command that are not * deleted */ @@ -170,7 +172,7 @@ public class MapWithAIAddCommand extends Command implements Runnable { public Collection getSourceTags() { return sources.entrySet().parallelStream() - .filter(entry -> validPrimitive(editable.getPrimitiveById(entry.getKey()))).map(Entry::getValue) + .filter(entry -> validPrimitive(editable.getPrimitiveById(entry.getKey()))).map(Map.Entry::getValue) .filter(Objects::nonNull).distinct().sorted().collect(Collectors.toList()); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java index f82bc92..6dcd970 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/commands/MergeDuplicateWays.java @@ -12,7 +12,6 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -179,7 +178,7 @@ public class MergeDuplicateWays extends Command { public static Command checkForDuplicateWays(Way way1, Way way2) { Command returnCommand = null; final Map, Map> duplicateNodes = getDuplicateNodes(way1, way2); - final Set, Map>> duplicateEntrySet = duplicateNodes.entrySet(); + final Set, Map>> duplicateEntrySet = duplicateNodes.entrySet(); final Set, Pair>> compressed = duplicateNodes.entrySet().stream() .map(entry -> new Pair, Pair>(entry.getKey(), new Pair(entry.getValue().entrySet().iterator().next().getKey(), diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIConflationCategory.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIConflationCategory.java index 6ff4812..3306d81 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIConflationCategory.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIConflationCategory.java @@ -30,6 +30,10 @@ public class MapWithAIConflationCategory { } } + private MapWithAIConflationCategory() { + // Hide the constructor + } + /** * Get a conflation URL for a specific category * diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java index 6f35cfb..99453f9 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAILayerInfo.java @@ -51,7 +51,7 @@ public class MapWithAILayerInfo { private final List layers = Collections.synchronizedList(new ArrayList<>()); /** List of layer ids of all usable layers */ private final Map layerIds = new HashMap<>(); - private ListenerList listeners = ListenerList.create(); + private final ListenerList listeners = ListenerList.create(); /** List of all available default layers */ static final List defaultLayers = new ArrayList<>(); /** List of all available default layers (including mirrors) */ diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/MapWithAIMenu.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/MapWithAIMenu.java index 5b31dc3..1c1623d 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/MapWithAIMenu.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/MapWithAIMenu.java @@ -16,7 +16,6 @@ import java.util.EnumMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.stream.Collectors; import javax.swing.Action; @@ -147,7 +146,7 @@ public class MapWithAIMenu extends JMenu { } if (!dynamicNonPhotoItems.isEmpty()) { addDynamicSeparator(); - for (Entry> e : dynamicNonPhotoItems.entrySet()) { + for (Map.Entry> e : dynamicNonPhotoItems.entrySet()) { MapWithAICategory cat = e.getKey(); List list = e.getValue(); if (list.size() > 1) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java index 7029a09..b581f25 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java @@ -66,7 +66,7 @@ public class MapWithAIDownloadOptions extends JPanel implements DownloadSelectio } } - private JComponent[] getJComponents(Component[] components) { + private static JComponent[] getJComponents(Component[] components) { return Stream.of(components).filter(JComponent.class::isInstance).map(JComponent.class::cast) .toArray(JComponent[]::new); } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadSourceType.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadSourceType.java index cc09fac..0cea7c2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadSourceType.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadSourceType.java @@ -22,7 +22,6 @@ import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInf public class MapWithAIDownloadSourceType implements IDownloadSourceType, LayerChangeListener { static final BooleanProperty IS_ENABLED = new BooleanProperty("download.mapwithai.data", false); JCheckBox cbDownloadMapWithAIData; - private static MapWithAIDownloadSourceType INSTANCE; @Override public JCheckBox getCheckBox(ChangeListener checkboxChangeListener) { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferences.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferences.java index 85c122c..cd9ebe7 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferences.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferences.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.TreeMap; import javax.swing.Box; @@ -64,7 +63,7 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting { private static void fillReplacementTagDisplayData(List list) { final Map current = new TreeMap<>(MapWithAIPreferenceHelper.getReplacementTags()); - for (final Entry entry : current.entrySet()) { + for (final Map.Entry entry : current.entrySet()) { list.add( new PrefEntry(entry.getKey(), new StringSetting(entry.getValue()), new StringSetting(null), false)); } @@ -81,7 +80,7 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting { p.add(panel, GBC.std().fill(GBC.BOTH)); } - private Component getServerList(PreferenceTabbedPane gui) { + private static Component getServerList(PreferenceTabbedPane gui) { return new MapWithAIProvidersPanel(gui, MapWithAIProvidersPanel.Options.SHOW_ACTIVE); } @@ -235,17 +234,28 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting { } /** + * This method returns the checkbox used for deciding if layers should be + * switched. + * * @return The {@code JCheckBox} for whether or not we are switching layers. */ public JCheckBox getSwitchLayerCheckBox() { return switchLayerCheckBox; } + /** + * Get the checkbox for merging buildings/addresses + * + * @return The checkbox + */ public JCheckBox getMergeBuildingAddressCheckBox() { return mergeBuildingAddressCheckBox; } /** + * This is the spinner used to determine maximum additions (and maximum + * selections). + * * @return {@code JSpinner} for the maximum additions */ public JSpinner getMaximumAdditionSpinner() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java index 7d9247a..492cb79 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIParametersPanel.java @@ -148,7 +148,9 @@ class MapWithAIParametersPanel extends JPanel { } /** - * @return headers provided by user + * HTTP parameters (so {@code ?param1=value1¶m2=value2}) + * + * @return parameters provided by user */ public Map> getParameters() { return headers.stream().distinct() @@ -156,6 +158,8 @@ class MapWithAIParametersPanel extends JPanel { } /** + * These are the current parameters for the info object. + * * @param parameters The initial parameters to show in the dialog */ public void setParameters(JsonArray parameters) { @@ -175,6 +179,8 @@ class MapWithAIParametersPanel extends JPanel { } /** + * Add a listener to the model ({@code model.addTableModelListener}) + * * @param l A TableModelListener for the backing model */ public void addListener(TableModelListener l) { @@ -182,6 +188,8 @@ class MapWithAIParametersPanel extends JPanel { } /** + * Get the model that is displayed in the panel. + * * @return The table model used to display parameters */ public TableModel getModel() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java index 2730e4a..b8f40d5 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/mapwithai/MapWithAIProvidersPanel.java @@ -331,7 +331,7 @@ public class MapWithAIProvidersPanel extends JPanel { defaultModel.addTableModelListener(e -> activeTable.repaint()); activeModel.addTableModelListener(e -> defaultTable.repaint()); - setupDefaultTable(this, defaultTable, options, areaListeners); + setupDefaultTable(defaultTable, options, areaListeners); TableColumnModel mod = activeTable.getColumnModel(); mod.getColumn(1).setPreferredWidth(800); @@ -436,7 +436,7 @@ public class MapWithAIProvidersPanel extends JPanel { } } - private static void setupDefaultTable(MapWithAIProvidersPanel panel, JTable defaultTable, Options[] options, + private static void setupDefaultTable(JTable defaultTable, Options[] options, ListenerList areaListeners) { boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals); int tenXWidth = defaultTable.getFontMetrics(defaultTable.getFont()).stringWidth("XXXXXXXXXX"); @@ -507,7 +507,9 @@ public class MapWithAIProvidersPanel extends JPanel { } /** - * @param The current area to highlight data from + * Set the current bounds of the map and the area to select + * + * @param area The current area to highlight data from */ public void setCurrentBounds(Bounds area) { this.defaultMap.setBoundingBox(area); @@ -613,12 +615,14 @@ public class MapWithAIProvidersPanel extends JPanel { } private void doCleanupResidualBounds(Map map, Consumer removalEffect) { + List toRemove = new ArrayList<>(); for (Integer i : map.keySet()) { int viewIndex = defaultTable.convertRowIndexToView(i); if (!defaultTable.getSelectionModel().isSelectedIndex(viewIndex)) { - removalEffect.accept(map.remove(i)); + toRemove.add(i); } } + toRemove.forEach(i -> removalEffect.accept(map.remove(i))); } private void cleanupResidualBounds() { diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java index 1041a3e..f56f1e0 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/ESRISourceReader.java @@ -37,7 +37,7 @@ public class ESRISourceReader implements Closeable { private final MapWithAIInfo source; private CachedFile cachedFile; private boolean fastFail; - private List ignoreConflationCategories; + private final List ignoreConflationCategories; private static final String JSON_QUERY_PARAM = "?f=json"; /** diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java index 1f50b8d..ffd49e2 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/io/mapwithai/MapWithAISourceReader.java @@ -184,7 +184,7 @@ public class MapWithAISourceReader implements Closeable { } } - return Collections.emptyList(); + return new ArrayList<>(); } private static Collection areaToShapes(java.awt.Shape shape) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java index 1396e88..1ec5626 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/MapWithAIPluginTest.java @@ -45,7 +45,9 @@ public class MapWithAIPluginTest { private static final String VERSION = "no-such-version"; /** - * @throws java.lang.Exception + * Set up the tests + * + * @throws java.lang.Exception if something goes wrong */ @Before public void setUp() throws Exception { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHookTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHookTest.java index cd2e80e..168b42c 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHookTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/backend/MapWithAIUploadHookTest.java @@ -77,8 +77,6 @@ public class MapWithAIUploadHookTest { /** * Test method for {@link MapWithAIUploadHook#modifyChangesetTags(Map)}. - * - * @throws PluginException */ @Test public void testModifyChangesetTags() { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java index 6e3aeb8..bd3a2f2 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/commands/MapWithAIAddComandTest.java @@ -216,8 +216,8 @@ public class MapWithAIAddComandTest { /** * https://josm.openstreetmap.de/ticket/18351 * - * @throws InterruptedException - * @throws InvocationTargetException + * @throws InterruptedException if the thread is interrupted + * @throws InvocationTargetException if some checked exception occurs */ @Test public void testRegression18351() throws InvocationTargetException, InterruptedException { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferencesTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferencesTest.java index 199d4fc..d5c0706 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferencesTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/MapWithAIPreferencesTest.java @@ -32,7 +32,9 @@ public class MapWithAIPreferencesTest { private MapWithAIPreferences preferences; /** - * @throws Exception + * Set up the test + * + * @throws Exception if something goes wrong with set up */ @Before public void setUp() throws Exception { @@ -42,10 +44,10 @@ public class MapWithAIPreferencesTest { /** * Test method for {@link MapWithAIPreferences#addGui(PreferenceTabbedPane)}. * - * @throws SecurityException - * @throws NoSuchFieldException - * @throws IllegalAccessException - * @throws IllegalArgumentException + * @throws SecurityException see {@link java.lang.Class#getDeclaredField} + * @throws NoSuchFieldException see {@link java.lang.Class#getDeclaredField} + * @throws IllegalAccessException see {@link java.lang.reflect.Field#get} + * @throws IllegalArgumentException see {@link java.lang.reflect.Field#get} */ @Test public void testAddGui() diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java index 2e00ca8..48da98c 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/gui/preferences/ReplacementPreferenceTableTest.java @@ -31,10 +31,12 @@ public class ReplacementPreferenceTableTest { public JOSMTestRules rule = new JOSMTestRules().preferences(); ReplacementPreferenceTable test; - protected static final class ReplacementPreferenceTableMock extends MockUp { + static class ReplacementPreferenceTableMock extends MockUp { private boolean set; /** + * Initialize the mock with a preset return value + * * @param set the return value for * {@link ReplacementPreferenceTableMock#askAddSetting} */ @@ -48,7 +50,9 @@ public class ReplacementPreferenceTableTest { } /** - * @param set the return value for + * Set the return value + * + * @param set the new return value for * {@link ReplacementPreferenceTableMock#askAddSetting} */ public void setAskAddSetting(boolean set) { diff --git a/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java b/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java index 7a8a00b..c6088e9 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapwithai/testutils/MapWithAITestRules.java @@ -194,14 +194,14 @@ public class MapWithAITestRules extends JOSMTestRules { /** * Replace URL servers with wiremock * - * @param wireMock The wiremock to point to - * @param url The URL to fix + * @param wireMockServer The wiremock to point to + * @param url The URL to fix * @return A url that points at the wiremock server */ - private static String replaceUrl(WireMockServer wireMock, String url) { + private static String replaceUrl(WireMockServer wireMockServer, String url) { try { URL temp = new URL(url); - return wireMock.baseUrl() + temp.getFile(); + return wireMockServer.baseUrl() + temp.getFile(); } catch (MalformedURLException error) { Logging.error(error); }