Skip to content

Commit

Permalink
See #23220: Use jakarta.annotation instead of javax.annotation (JSR305)
Browse files Browse the repository at this point in the history
Some lint issues were also fixed.

Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Oct 25, 2023
1 parent 4af7ac2 commit e796f49
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 175 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
call-workflow:
strategy:
matrix:
josm-revision: ["", "r18723"]
josm-revision: ["", "r18877"]
uses: JOSM/JOSMPluginAction/.github/workflows/ant.yml@v1
with:
java-version: 17
josm-revision: ${{ matrix.josm-revision }}
plugin-jar-name: 'mapwithai'
perform-revision-tagging: ${{ github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' && matrix.josm-revision == 'r18723' }}
perform-revision-tagging: ${{ matrix.josm-revision == 'r18877' && github.repository == 'JOSM/MapWithAI' && github.ref_type == 'branch' && github.ref_name == 'master' && github.event_name != 'schedule' && github.event_name != 'pull_request' }}
secrets: inherit

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# The minimum JOSM version this plugin is compatible with (can be any numeric version
plugin.main.version = 18723
plugin.main.version = 18877
# The JOSM version this plugin is currently compiled against
# Please make sure this version is available at https://josm.openstreetmap.de/download
# The special values "latest" and "tested" are also possible here, but not recommended.
plugin.compile.version = 18724
plugin.compile.version = 18877
plugin.canloadatruntime = true
plugin.author = Taylor Smock
plugin.class = org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class DataAvailability {
static final Map<String, String> POSSIBLE_DATA_POINTS = new TreeMap<>();

private static final String PROVIDES = "provides";
private static final String EMPTY_STRING = "";
private static final int SEVEN_DAYS_IN_SECONDS = 604_800;

/**
Expand Down Expand Up @@ -150,7 +149,7 @@ private static void parseCountriesObject(Map<String, Map<String, Boolean>> count
* @return A string that doesn't have quotes at the beginning or end
*/
public static String stripQuotes(String string) {
return string.replaceAll("((^\")|(\"$))", EMPTY_STRING);
return string.replaceAll("((^\")|(\"$))", "");
}

/**
Expand Down Expand Up @@ -224,7 +223,7 @@ public String getUrl() {
* @return The url or ""
*/
public String getTermsOfUseUrl() {
return EMPTY_STRING;
return "";
}

/**
Expand All @@ -247,11 +246,10 @@ public static List<String> getTermsOfUse() {
DATA_SOURCES.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance().getTermsOfUseUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch (ReflectiveOperationException e) {
Logging.debug(e);
}
return EMPTY_STRING;
return "";
})).filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty())
.collect(Collectors.toList());
}
Expand All @@ -267,11 +265,10 @@ public static List<String> getPrivacyPolicy() {
DATA_SOURCES.stream().map(clazz -> {
try {
return clazz.getConstructor().newInstance().getPrivacyPolicyUrl();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
} catch (ReflectiveOperationException e) {
Logging.debug(e);
}
return EMPTY_STRING;
return "";
}))
.filter(Objects::nonNull).filter(str -> !Utils.removeWhiteSpaces(str).isEmpty()).distinct()
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@

import static org.openstreetmap.josm.tools.I18n.tr;

import javax.annotation.Nullable;

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;
Expand All @@ -17,6 +14,8 @@
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.Way;

import jakarta.annotation.Nullable;

/**
* This is similar to the ReplaceGeometryUtils.buildUpgradeNodeCommand method
*
Expand Down Expand Up @@ -46,19 +45,19 @@ public static Command buildUpgradeNodeCommand(Node subjectNode, OsmPrimitive ref

private static Node getNewOrNoTagNode(OsmPrimitive referenceObject) {
List<Node> 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);
if (referenceObject instanceof Way way) {
nodes = way.getNodes();
} else if (referenceObject instanceof Relation relation) {
nodes = relation.getMemberPrimitives().stream().flatMap(o -> {
if (o instanceof Way way) {
return way.getNodes().stream();
} else if (o instanceof Node node) {
return Stream.of(node);
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
} else if (referenceObject instanceof Node) {
nodes = Collections.singletonList((Node) referenceObject);
}).filter(Objects::nonNull).toList();
} else if (referenceObject instanceof Node node) {
nodes = Collections.singletonList(node);
} else {
throw new IllegalArgumentException(tr("Unknown OsmPrimitive type"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

import static org.openstreetmap.josm.tools.I18n.tr;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
Expand All @@ -34,6 +30,9 @@
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Pair;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

/**
* Merge duplicate ways
*/
Expand Down Expand Up @@ -83,7 +82,7 @@ public MergeDuplicateWays(Way way1, Way way2) {
* @param way2 The second way
*/
public MergeDuplicateWays(DataSet data, Way way1, Way way2) {
this(data, Stream.of(way1, way2).filter(Objects::nonNull).collect(Collectors.toList()));
this(data, Stream.of(way1, way2).filter(Objects::nonNull).toList());
}

/**
Expand All @@ -94,7 +93,7 @@ public MergeDuplicateWays(DataSet data, Way way1, Way way2) {
*/
public MergeDuplicateWays(DataSet data, List<Way> ways) {
super(data);
this.ways = ways.stream().filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
this.ways = ways.stream().filter(MergeDuplicateWays::nonDeletedWay).toList();
this.commands = new ArrayList<>();
}

Expand All @@ -110,20 +109,19 @@ public boolean executeCommand() {
} else if (ways.size() == 1) {
checkForDuplicateWays(ways.get(0), commands);
} else {
Iterator<Way> it = ways.iterator();
Way way1 = it.next();
final var it = ways.iterator();
var way1 = it.next();
while (it.hasNext()) {
Way way2 = it.next();
final Command tCommand = checkForDuplicateWays(way1, way2);
final var way2 = it.next();
final var tCommand = checkForDuplicateWays(way1, way2);
if (tCommand != null) {
commands.add(tCommand);
tCommand.executeCommand();
}
way1 = way2;
}
}
final List<Command> realCommands = commands.stream().filter(Objects::nonNull).distinct()
.collect(Collectors.toList());
final List<Command> realCommands = commands.stream().filter(Objects::nonNull).distinct().toList();
commands.clear();
commands.addAll(realCommands);
if (!commands.isEmpty() && (commands.size() != 1)) {
Expand Down Expand Up @@ -165,14 +163,13 @@ public static void filterDataSet(@Nonnull DataSet dataSet, @Nonnull List<Command
final List<Way> ways = (bound == null ? dataSet.getWays() : dataSet.searchWays(bound.toBBox())).stream()
.filter(prim -> !prim.isIncomplete() && !prim.isDeleted())
.collect(Collectors.toCollection(ArrayList::new));
for (int i = 0; i < ways.size(); i++) {
final Way way1 = ways.get(i);
final Collection<Way> nearbyWays = dataSet.searchWays(way1.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
nearbyWays.remove(way1);
for (var i = 0; i < ways.size(); i++) {
final var way1 = ways.get(i);
final var nearbyWays = dataSet.searchWays(way1.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).filter(w -> !Objects.equals(w, way1)).toList();
for (final Way way2 : nearbyWays) {
final Command command = checkForDuplicateWays(way1, way2);
final Collection<OsmPrimitive> deletedWays = new ArrayList<>();
final var command = checkForDuplicateWays(way1, way2);
final var deletedWays = new ArrayList<OsmPrimitive>();
if (command != null) {
commands.add(command);
command.executeCommand();
Expand All @@ -194,11 +191,10 @@ public static void filterDataSet(@Nonnull DataSet dataSet, @Nonnull List<Command
*/
public static void checkForDuplicateWays(Way way, List<Command> commands) {
final Collection<Way> nearbyWays = way.getDataSet().searchWays(way.getBBox()).stream()
.filter(MergeDuplicateWays::nonDeletedWay).collect(Collectors.toList());
nearbyWays.remove(way);
.filter(MergeDuplicateWays::nonDeletedWay).filter(w -> !Objects.equals(w, way)).toList();
for (final Way way2 : nearbyWays) {
if (!way2.isDeleted()) {
final Command tCommand = checkForDuplicateWays(way, way2);
final var tCommand = checkForDuplicateWays(way, way2);
if (tCommand != null) {
commands.add(tCommand);
tCommand.executeCommand();
Expand Down Expand Up @@ -230,10 +226,8 @@ public static Command checkForDuplicateWays(Way way1, Way way2) {
Logging.error("{0}", way2);
}
if ((compressed.size() > 1) && duplicateEntrySet.stream().noneMatch(entry -> entry.getValue().size() > 1)) {
final List<Integer> initial = compressed.stream().map(entry -> entry.a.a).sorted()
.collect(Collectors.toList());
final List<Integer> after = compressed.stream().map(entry -> entry.b.a).sorted()
.collect(Collectors.toList());
final var initial = compressed.stream().map(entry -> entry.a.a).sorted().toList();
final var after = compressed.stream().map(entry -> entry.b.a).sorted().toList();
if (sorted(initial) && sorted(after)) {
returnCommand = mergeWays(way1, way2, compressed);
}
Expand Down Expand Up @@ -278,12 +272,12 @@ public static Command mergeWays(Way way1, Way way2,
}
}
Collections.reverse(before);
final Way newWay = new Way(way1);
final var newWay = new Way(way1);
List<Command> commands = new ArrayList<>();
before.forEach(node -> newWay.addNode(0, node));
after.forEach(newWay::addNode);
if (newWay.getNodesCount() > 0) {
final ChangeCommand changeCommand = new ChangeCommand(way1, newWay);
final var changeCommand = new ChangeCommand(way1, newWay);
commands.add(changeCommand);
/*
* This must be executed, otherwise the delete command will believe that way2
Expand Down Expand Up @@ -315,8 +309,8 @@ public static Command mergeWays(Way way1, Way way2,
* @return The node that the param {@code node} duplicates
*/
public static Node nodeInCompressed(Node node, Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) {
Node returnNode = node;
for (final Pair<Pair<Integer, Node>, Pair<Integer, Node>> pair : compressed) {
var returnNode = node;
for (final var pair : compressed) {
if (node.equals(pair.a.b)) {
returnNode = pair.b.b;
} else if (node.equals(pair.b.b)) {
Expand All @@ -326,26 +320,26 @@ public static Node nodeInCompressed(Node node, Set<Pair<Pair<Integer, Node>, Pai
break;
}
}
final Node tReturnNode = returnNode;
final var tReturnNode = returnNode;
node.getKeys().forEach(tReturnNode::put);
return returnNode;
}

/**
* Check if the node pairs increment in the same direction (only checks first
* two pairs), ensure that they are sorted with {@link sorted}
* two pairs), ensure that they are sorted with {@link #sorted}
*
* @param compressed The set of duplicate node/placement pairs
* @return true if the node pairs increment in the same direction
*/
public static boolean checkDirection(Set<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> compressed) {
final Iterator<Pair<Pair<Integer, Node>, Pair<Integer, Node>>> iterator = compressed.iterator();
boolean returnValue = false;
final var iterator = compressed.iterator();
var returnValue = false;
if (compressed.size() > 1) {
final Pair<Pair<Integer, Node>, Pair<Integer, Node>> first = iterator.next();
final Pair<Pair<Integer, Node>, Pair<Integer, Node>> second = iterator.next();
final boolean way1Forward = first.a.a < second.a.a;
final boolean way2Forward = first.b.a < second.b.a;
final var first = iterator.next();
final var second = iterator.next();
final var way1Forward = first.a.a < second.a.a;
final var way2Forward = first.b.a < second.b.a;
returnValue = way1Forward == way2Forward;
}
return returnValue;
Expand All @@ -358,10 +352,10 @@ public static boolean checkDirection(Set<Pair<Pair<Integer, Node>, Pair<Integer,
* @return true if there are no gaps and it increases
*/
public static boolean sorted(List<Integer> collection) {
boolean returnValue = true;
var returnValue = true;
if (collection.size() > 1) {
Integer last = collection.get(0);
for (int i = 1; i < collection.size(); i++) {
for (var i = 1; i < collection.size(); i++) {
final Integer next = collection.get(i);
if ((next - last) != 1) {
returnValue = false;
Expand All @@ -381,17 +375,16 @@ public static boolean sorted(List<Integer> collection) {
* @return A map of node -&gt; node(s) duplicates
*/
public static Map<Pair<Integer, Node>, Map<Integer, Node>> getDuplicateNodes(Way way1, Way way2) {
final Map<Pair<Integer, Node>, Map<Integer, Node>> duplicateNodes = new LinkedHashMap<>();
for (int j = 0; j < way1.getNodesCount(); j++) {
final Node origNode = way1.getNode(j);
for (int k = 0; k < way2.getNodesCount(); k++) {
final Node possDupeNode = way2.getNode(k);
final var duplicateNodes = new LinkedHashMap<Pair<Integer, Node>, Map<Integer, Node>>();
for (var j = 0; j < way1.getNodesCount(); j++) {
final var origNode = way1.getNode(j);
for (var k = 0; k < way2.getNodesCount(); k++) {
final var possDupeNode = way2.getNode(k);
if (origNode.equals(possDupeNode) || (origNode
.greatCircleDistance(possDupeNode) < MapWithAIPreferenceHelper.getMaxNodeDistance())) {
final Pair<Integer, Node> origNodePair = new Pair<>(j, origNode);
final Map<Integer, Node> dupeNodeMap = duplicateNodes.getOrDefault(origNodePair, new HashMap<>());
final var origNodePair = new Pair<>(j, origNode);
final var dupeNodeMap = duplicateNodes.computeIfAbsent(origNodePair, ignored -> new HashMap<>());
dupeNodeMap.put(k, possDupeNode);
duplicateNodes.put(origNodePair, dupeNodeMap);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@

import static org.openstreetmap.josm.tools.I18n.marktr;

import javax.annotation.Nonnull;
import javax.swing.ImageIcon;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;

import javax.swing.ImageIcon;

import org.openstreetmap.josm.data.sources.ISourceCategory;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;

import jakarta.annotation.Nonnull;

/**
* The category for a MapWithAI source (i.e., buildings/highways/addresses/etc.)
*
Expand Down Expand Up @@ -98,6 +100,7 @@ public static MapWithAICategory fromString(String s) {
*/
public static class DescriptionComparator implements Comparator<MapWithAICategory>, Serializable {

@Serial
private static final long serialVersionUID = 9131636715279880580L;

@Override
Expand Down
Loading

0 comments on commit e796f49

Please sign in to comment.