Lint: Cleanup warnings on build

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2021-09-30 13:38:20 -06:00
rodzic 5cb5262128
commit 849f571837
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
8 zmienionych plików z 149 dodań i 138 usunięć

Wyświetl plik

@ -30,11 +30,11 @@ import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Pair;
public class MapWithAIAddCommand extends Command implements Runnable {
DataSet editable;
DataSet mapWithAI;
Collection<OsmPrimitive> primitives;
private final DataSet editable;
private final DataSet mapWithAI;
private final Collection<OsmPrimitive> primitives;
Command command;
Lock lock;
private Lock lock;
final Map<OsmPrimitive, String> sources;
/**
@ -67,7 +67,7 @@ public class MapWithAIAddCommand extends Command implements Runnable {
this.primitives = new HashSet<>(selection);
this.primitives.addAll(nodeReferrers);
sources = selection.parallelStream()
.map(prim -> new Pair<OsmPrimitive, String>(prim,
.map(prim -> new Pair<>(prim,
prim.hasKey("source") ? prim.get("source")
: prim.get(GetDataRunnable.MAPWITHAI_SOURCE_TAG_KEY)))
.filter(pair -> pair.b != null).collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));
@ -75,7 +75,7 @@ public class MapWithAIAddCommand extends Command implements Runnable {
@Override
public boolean executeCommand() {
GuiHelper.runInEDTAndWait(this::run);
GuiHelper.runInEDTAndWait(this);
return true;
}
@ -159,10 +159,10 @@ public class MapWithAIAddCommand extends Command implements Runnable {
* @return The number of MapWithAI objects added in this command that are not
* deleted
*/
public Long getAddedObjects() {
Long returnLong;
public long getAddedObjects() {
long returnLong;
if (this.equals(UndoRedoHandler.getInstance().getLastCommand())) {
returnLong = Long.valueOf(primitives.size());
returnLong = primitives.size();
} else {
returnLong = primitives.stream().map(editable::getPrimitiveById).filter(Objects::nonNull)
.filter(MapWithAIAddCommand::validPrimitive).count();
@ -182,11 +182,13 @@ public class MapWithAIAddCommand extends Command implements Runnable {
@Override
public boolean equals(Object other) {
boolean returnBoolean = false;
if (other instanceof MapWithAIAddCommand && hashCode() == other.hashCode()) {
returnBoolean = true;
if (other instanceof MapWithAIAddCommand) {
MapWithAIAddCommand o = (MapWithAIAddCommand) other;
return Objects.equals(this.editable, o.editable) && Objects.equals(this.mapWithAI, o.mapWithAI)
&& Objects.equals(this.lock, o.lock) && o.primitives.containsAll(this.primitives)
&& this.primitives.containsAll(o.primitives);
}
return returnBoolean;
return false;
}
@Override

Wyświetl plik

@ -21,7 +21,11 @@ import org.openstreetmap.josm.data.osm.Way;
* @author Taylor Smock
*
*/
public class MergeBuildingNodeCommand {
public final class MergeBuildingNodeCommand {
private MergeBuildingNodeCommand() {
// Hide constructor
}
/**
* Upgrade a node to a way or multipolygon
*

Wyświetl plik

@ -3,6 +3,8 @@ package org.openstreetmap.josm.plugins.mapwithai.commands.cleanup;
import static org.openstreetmap.josm.tools.I18n.tr;
import javax.swing.JOptionPane;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
@ -14,14 +16,13 @@ import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.swing.JOptionPane;
import org.openstreetmap.josm.actions.AutoScaleAction;
import org.openstreetmap.josm.command.ChangePropertyCommand;
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.data.osm.BBox;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.INode;
import org.openstreetmap.josm.data.osm.IPrimitive;
import org.openstreetmap.josm.data.osm.IWaySegment;
import org.openstreetmap.josm.data.osm.Node;
@ -83,11 +84,9 @@ public class MissingConnectionTags extends AbstractConflationCommand {
Collection<Way> ways = Utils.filteredCollection(possiblyAffectedPrimitives, Way.class);
if (!ways.isEmpty()) {
DataSet ds = this.getAffectedDataSet();
Layer toSwitch = MainApplication.getLayerManager().getLayersOfType(AbstractOsmDataLayer.class).stream()
.filter(d -> ds.equals(d.getDataSet())).findAny().orElse(null);
if (toSwitch != null) {
MainApplication.getLayerManager().setActiveLayer(toSwitch);
}
MainApplication.getLayerManager().getLayersOfType(AbstractOsmDataLayer.class).stream()
.filter(d -> ds.equals(d.getDataSet())).findAny()
.ifPresent(toSwitch -> MainApplication.getLayerManager().setActiveLayer(toSwitch));
}
String prefKey = "mapwithai.conflation.missingconflationtags";
@ -213,9 +212,10 @@ public class MissingConnectionTags extends AbstractConflationCommand {
Collection<Node> nodes = Geometry.addIntersections(error.getPrimitives().stream().filter(Way.class::isInstance)
.map(Way.class::cast).filter(w -> w.hasKey(HIGHWAY)).collect(Collectors.toList()), false,
new ArrayList<>());
if (nodes.stream().filter(MissingConnectionTags::noConflationKey)
.anyMatch(n -> way.getNodes().stream().filter(MissingConnectionTags::noConflationKey)
.anyMatch(wn -> n.getCoor().greatCircleDistance(wn.getCoor()) < precision))) {
if (nodes.stream().filter(MissingConnectionTags::noConflationKey).map(INode::getCoor).filter(Objects::nonNull)
.anyMatch(
n -> way.getNodes().stream().filter(MissingConnectionTags::noConflationKey).map(INode::getCoor)
.filter(Objects::nonNull).anyMatch(wn -> n.greatCircleDistance(wn) < precision))) {
return () -> createIntersectionCommand(way,
way.getNodes().stream().filter(MissingConnectionTags::noConflationKey)
.filter(n1 -> nodes.stream().anyMatch(n2 -> Geometry.getDistance(n1, n2) < precision))
@ -253,8 +253,8 @@ public class MissingConnectionTags extends AbstractConflationCommand {
IWaySegment<?, ?> seg = Geometry.getClosestWaySegment(way, node);
List<IPrimitive> prims = Arrays.asList(way, seg.getFirstNode(), seg.getSecondNode());
if (prims.stream().allMatch(p -> p.getOsmId() > 0)) {
return new ChangePropertyCommand(node, "conn", String.join(",",
prims.stream().map(p -> p.getPrimitiveId().toString()).collect(Collectors.toList())));
return new ChangePropertyCommand(node, "conn",
prims.stream().map(p -> p.getPrimitiveId().toString()).collect(Collectors.joining(",")));
}
}
return null;
@ -321,17 +321,17 @@ public class MissingConnectionTags extends AbstractConflationCommand {
}
@Override
public boolean equals(Object o) {
if (o instanceof MissingConnectionTags) {
MissingConnectionTags omct = (MissingConnectionTags) o;
return Objects.equals(omct.precision, this.precision) && super.equals(o);
public boolean equals(Object other) {
if (other instanceof MissingConnectionTags) {
MissingConnectionTags o = (MissingConnectionTags) other;
return o.precision == this.precision && super.equals(other);
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(precision);
return Objects.hash(super.hashCode(), precision);
}
}

Wyświetl plik

@ -269,6 +269,7 @@ public class MapWithAILayerInfo {
Utils.close(reader);
}
@Override
public void run() {
if (this.clearCache) {
ESRISourceReader.SOURCE_CACHE.clear();
@ -351,7 +352,7 @@ public class MapWithAILayerInfo {
allDefaultLayers.sort(Comparator.comparing(TileSourceInfo::getName));
allDefaultLayers.sort(Comparator.comparing(info -> info.getCategory().getDescription()));
allDefaultLayers.sort(Comparator
.comparingInt(info -> (-1) * info.getAdditionalCategories().indexOf(MapWithAICategory.FEATURED)));
.comparingInt(info -> -info.getAdditionalCategories().indexOf(MapWithAICategory.FEATURED)));
defaultLayerIds.clear();
buildIdMap(allDefaultLayers, defaultLayerIds);
updateEntriesFromDefaults(!loadError);

Wyświetl plik

@ -4,6 +4,22 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai;
import static org.openstreetmap.josm.tools.I18n.marktr;
import static org.openstreetmap.josm.tools.I18n.tr;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
@ -26,22 +42,6 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;
import org.openstreetmap.gui.jmapviewer.Coordinate;
import org.openstreetmap.gui.jmapviewer.MapPolygonImpl;
import org.openstreetmap.gui.jmapviewer.MapRectangleImpl;
@ -189,7 +189,7 @@ public class MapWithAIProvidersPanel extends JPanel {
Color t = IMAGERY_BACKGROUND_COLOR.get();
GuiHelper.setBackgroundReadable(label, isSelected ? t.darker() : t);
} else if (this.area != null && info.getBounds() != null
&& (this.area.intersects(info.getBounds()) || (info.getBounds().intersects(this.area)))) {
&& (this.area.intersects(info.getBounds()) || info.getBounds().intersects(this.area))) {
Color t = MAPWITHAI_AREA_BACKGROUND_COLOR.get();
GuiHelper.setBackgroundReadable(label, isSelected ? t.darker() : t);
} else {
@ -304,7 +304,7 @@ public class MapWithAIProvidersPanel extends JPanel {
super(new GridBagLayout());
this.gui = gui;
this.options = options;
boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals);
boolean showActive = Arrays.asList(options).contains(Options.SHOW_ACTIVE);
activeTable = new JTable(ACTIVE_MODEL) {
@ -360,7 +360,6 @@ public class MapWithAIProvidersPanel extends JPanel {
defaultMap = new SlippyMapBBoxChooser();
defaultMap.setTileSource(SlippyMapBBoxChooser.DefaultOsmTileSourceProvider.get()); // for attribution
defaultMap.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
@ -437,7 +436,7 @@ public class MapWithAIProvidersPanel extends JPanel {
private static void setupDefaultTable(JTable defaultTable, Options[] options,
ListenerList<AreaListener> areaListeners) {
boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals);
boolean showActive = Arrays.asList(options).contains(Options.SHOW_ACTIVE);
int tenXWidth = defaultTable.getFontMetrics(defaultTable.getFont()).stringWidth("XXXXXXXXXX");
TableColumnModel mod = defaultTable.getColumnModel();
int urlWidth = (showActive ? 3 : 0) * tenXWidth;
@ -741,7 +740,7 @@ public class MapWithAIProvidersPanel extends JPanel {
@Override
public void actionPerformed(ActionEvent e) {
Integer i;
int i;
while ((i = activeTable.getSelectedRow()) != -1) {
ACTIVE_MODEL.removeRow(i);
}
@ -846,17 +845,16 @@ public class MapWithAIProvidersPanel extends JPanel {
@Override
public void actionPerformed(ActionEvent evt) {
this.setEnabled(false);
MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false, () -> {
// This needs to be run in a block to avoid race conditions.
GuiHelper.runInEDT(() -> {
defaultTable.getSelectionModel().clearSelection();
defaultTableListener.clearMap();
DEFAULT_MODEL.fireTableDataChanged();
/* loading new file may change active layers */
ACTIVE_MODEL.fireTableDataChanged();
this.setEnabled(true);
});
});
MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false, () ->
// This needs to be run in a block to avoid race conditions.
GuiHelper.runInEDT(() -> {
defaultTable.getSelectionModel().clearSelection();
defaultTableListener.clearMap();
DEFAULT_MODEL.fireTableDataChanged();
/* loading new file may change active layers */
ACTIVE_MODEL.fireTableDataChanged();
this.setEnabled(true);
}));
}
}
}

Wyświetl plik

@ -44,6 +44,7 @@ public class ConflationSourceReader extends CommonSourceReader<Map<MapWithAICate
* @param jsonObject The json of the data sources
* @return The parsed entries
*/
@Override
public Map<MapWithAICategory, List<String>> parseJson(JsonObject jsonObject) {
return jsonObject.entrySet().stream().flatMap(i -> parse(i).stream())
.collect(Collectors.groupingBy(p -> p.a, Collectors.mapping(p -> p.b, Collectors.toList())));

Wyświetl plik

@ -145,58 +145,6 @@ public class ESRISourceReader {
return information;
}
/**
* Get the json string for a URL
*
* @param url The URL to get
* @param fastFail Fail fast (1 second)
* @return The json string, or {@code null}.
*/
@Nullable
private static String getJsonString(@Nonnull final String url, final long defaultMaxAge, final boolean fastFail) {
String jsonString = SOURCE_CACHE.get(url);
// TODO FIXME remove sometime after January 2022 (give it a chance to cleanup
// directories)
CachedFile.cleanup(url);
if (jsonString == null) {
synchronized (SOURCE_CACHE) {
jsonString = SOURCE_CACHE.get(url);
if (jsonString == null) {
HttpClient client = null;
try {
client = HttpClient.create(new URL(url));
if (fastFail) {
client.setReadTimeout(1000);
}
final HttpClient.Response response = client.connect();
jsonString = response.fetchContent();
if (jsonString != null && response.getResponseCode() < 400
&& response.getResponseCode() >= 200) {
final IElementAttributes elementAttributes = SOURCE_CACHE.getDefaultElementAttributes();
// getExpiration returns milliseconds
final long expirationTime = response.getExpiration();
if (expirationTime > 0) {
elementAttributes.setMaxLife(response.getExpiration());
} else {
elementAttributes.setMaxLife(defaultMaxAge);
}
SOURCE_CACHE.put(url, jsonString, elementAttributes);
} else {
jsonString = null;
}
} catch (final IOException e) {
Logging.error(e);
} finally {
if (client != null) {
client.disconnect();
}
}
}
}
}
return jsonString;
}
private MapWithAIInfo parse(JsonObject feature) {
// Use the initial esri server information to keep conflation info
MapWithAIInfo newInfo = new MapWithAIInfo(source);
@ -250,6 +198,58 @@ public class ESRISourceReader {
return (newInfo);
}
/**
* Get the json string for a URL
*
* @param url The URL to get
* @param fastFail Fail fast (1 second)
* @return The json string, or {@code null}.
*/
@Nullable
private static String getJsonString(@Nonnull final String url, final long defaultMaxAge, final boolean fastFail) {
String jsonString = SOURCE_CACHE.get(url);
// TODO FIXME remove sometime after January 2022 (give it a chance to cleanup
// directories)
CachedFile.cleanup(url);
if (jsonString == null) {
synchronized (SOURCE_CACHE) {
jsonString = SOURCE_CACHE.get(url);
if (jsonString == null) {
HttpClient client = null;
try {
client = HttpClient.create(new URL(url));
if (fastFail) {
client.setReadTimeout(1000);
}
final HttpClient.Response response = client.connect();
jsonString = response.fetchContent();
if (jsonString != null && response.getResponseCode() < 400
&& response.getResponseCode() >= 200) {
final IElementAttributes elementAttributes = SOURCE_CACHE.getDefaultElementAttributes();
// getExpiration returns milliseconds
final long expirationTime = response.getExpiration();
if (expirationTime > 0) {
elementAttributes.setMaxLife(response.getExpiration());
} else {
elementAttributes.setMaxLife(defaultMaxAge);
}
SOURCE_CACHE.put(url, jsonString, elementAttributes);
} else {
jsonString = null;
}
} catch (final IOException e) {
Logging.error(e);
} finally {
if (client != null) {
client.disconnect();
}
}
}
}
}
return jsonString;
}
/**
* Get feature service information
*

Wyświetl plik

@ -66,32 +66,37 @@ class MapWithAICopyProhibitTest {
new WindowMocker();
new BlacklistUtilsMock();
MainLayerManager layerManager = MainApplication.getLayerManager();
OsmDataLayer osmDataLayer = new OsmDataLayer(new DataSet(), "TEST", null);
MapWithAILayer mapWithAILayer = new MapWithAILayer(new DataSet(), "TEST", null);
layerManager.addLayer(osmDataLayer);
layerManager.addLayer(mapWithAILayer);
DataSet mapWithAIDataSet = mapWithAILayer.getDataSet();
Node testNode = new Node(LatLon.ZERO);
mapWithAIDataSet.addPrimitive(testNode);
mapWithAIDataSet.setSelected(testNode);
layerManager.setActiveLayer(mapWithAILayer);
MapWithAICopyProhibit mapWithAICopyProhibit = new MapWithAICopyProhibit();
try {
MainLayerManager layerManager = MainApplication.getLayerManager();
OsmDataLayer osmDataLayer = new OsmDataLayer(new DataSet(), "TEST", null);
MapWithAILayer mapWithAILayer = new MapWithAILayer(new DataSet(), "TEST", null);
layerManager.addLayer(osmDataLayer);
layerManager.addLayer(mapWithAILayer);
DataSet mapWithAIDataSet = mapWithAILayer.getDataSet();
Node testNode = new Node(LatLon.ZERO);
mapWithAIDataSet.addPrimitive(testNode);
mapWithAIDataSet.setSelected(testNode);
layerManager.setActiveLayer(mapWithAILayer);
CopyAction copyAction = new CopyAction();
copyAction.actionPerformed(null);
PasteAction pasteAction = new PasteAction();
CopyAction copyAction = new CopyAction();
copyAction.actionPerformed(null);
PasteAction pasteAction = new PasteAction();
assertEquals(1, mapWithAIDataSet.allPrimitives().size());
pasteAction.actionPerformed(null);
assertEquals(2, mapWithAIDataSet.allPrimitives().size());
pasteAction.actionPerformed(null);
assertEquals(3, mapWithAIDataSet.allPrimitives().size());
layerManager.setActiveLayer(osmDataLayer);
assertEquals(0, osmDataLayer.getDataSet().allPrimitives().size());
for (int i = 0; i < 10; i++) {
assertEquals(1, mapWithAIDataSet.allPrimitives().size());
pasteAction.actionPerformed(null);
assertEquals(2, mapWithAIDataSet.allPrimitives().size());
pasteAction.actionPerformed(null);
assertEquals(3, mapWithAIDataSet.allPrimitives().size());
layerManager.setActiveLayer(osmDataLayer);
assertEquals(0, osmDataLayer.getDataSet().allPrimitives().size());
for (int i = 0; i < 10; i++) {
pasteAction.actionPerformed(null);
assertEquals(0, osmDataLayer.getDataSet().allPrimitives().size());
}
} finally {
mapWithAICopyProhibit.destroy();
}
}
}