Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PMD to 7.0.0 #689

Merged
merged 14 commits into from Apr 17, 2024
4 changes: 2 additions & 2 deletions .github/workflows/gradle-publish.yml
Expand Up @@ -20,10 +20,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Expand Up @@ -16,10 +16,10 @@ jobs:
environment: BRouter
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remark only, the BRouter server still uses JDK 11.
Therefore, the output lib cannot be used directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to compile for older Java releases we should target a specific java version. It seems reasonable to target Java 11 but use JDK 17 to build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For maximum compatibility with old Android versions (that do not contain newer Java API),
in the open source libraries I maintain, we may use Java 17 to compile,
but have sourceCompatibility and targetCompatibility with JavaVersion.VERSION_1_8.

For example:
https://github.com/mapsforge/mapsforge/blob/master/build.gradle#L32-L33
https://github.com/mapsforge/vtm/blob/master/build.gradle#L34-L35

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine, I could try sourceCompatibility and targetCompatibility next week with the test server.

uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Create local.properties
Expand Down
3 changes: 0 additions & 3 deletions brouter-codec/src/main/AndroidManifest.xml

This file was deleted.

5 changes: 3 additions & 2 deletions brouter-codec/src/main/java/btools/codec/MicroCache2.java
@@ -1,6 +1,7 @@
package btools.codec;

import java.util.HashMap;
import java.util.Map;

import btools.util.ByteDataReader;
import btools.util.IByteArrayUnifier;
Expand Down Expand Up @@ -287,7 +288,7 @@ public boolean isInternal(int ilon, int ilat) {

@Override
public int encodeMicroCache(byte[] buffer) {
HashMap<Long, Integer> idMap = new HashMap<>();
Map<Long, Integer> idMap = new HashMap<>();
for (int n = 0; n < size; n++) { // loop over nodes
idMap.put(expandId(faid[n]), n);
}
Expand Down Expand Up @@ -418,7 +419,7 @@ public int encodeMicroCache(byte[] buffer) {
nlinks++;

if (isInternal) {
int nodeIdx = idx.intValue();
int nodeIdx = idx;
if (dodebug) System.out.println("*** target nodeIdx=" + nodeIdx);
if (nodeIdx == n) throw new RuntimeException("ups: self ref?");
nodeIdxDiff.encodeSignedValue(nodeIdx - n);
Expand Down
3 changes: 2 additions & 1 deletion brouter-codec/src/main/java/btools/codec/TagValueCoder.java
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;

import btools.util.BitCoderContext;

Expand Down Expand Up @@ -58,7 +59,7 @@ public void encodeDictionary(BitCoderContext bc) {
TagValueSet dummy = new TagValueSet(nextTagValueSetId++);
identityMap.put(dummy, dummy);
}
PriorityQueue<TagValueSet> queue = new PriorityQueue<>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
Queue<TagValueSet> queue = new PriorityQueue<>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
queue.addAll(identityMap.values());
while (queue.size() > 1) {
TagValueSet node = new TagValueSet(nextTagValueSetId++);
Expand Down
3 changes: 0 additions & 3 deletions brouter-core/src/main/AndroidManifest.xml

This file was deleted.

4 changes: 2 additions & 2 deletions brouter-core/src/main/java/btools/router/OsmNogoPolygon.java
Expand Up @@ -168,7 +168,7 @@ public boolean isOnPolyline(long px, long py) {
Point p1 = points.get(0);
for (int i = 1; i <= i_last; i++) {
final Point p2 = points.get(i);
if (OsmNogoPolygon.isOnLine(px, py, p1.x, p1.y, p2.x, p2.y)) {
if (isOnLine(px, py, p1.x, p1.y, p2.x, p2.y)) {
return true;
}
p1 = p2;
Expand Down Expand Up @@ -234,7 +234,7 @@ public boolean isWithin(final long px, final long py) {
final long p1x = p1.x;
final long p1y = p1.y;

if (OsmNogoPolygon.isOnLine(px, py, p0x, p0y, p1x, p1y)) {
if (isOnLine(px, py, p0x, p0y, p1x, p1y)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion brouter-core/src/main/java/btools/router/OsmPath.java
Expand Up @@ -296,7 +296,7 @@ protected void addAddionalPenalty(OsmTrack refTrack, boolean detailMode, OsmPath
// apply a start-direction if appropriate (by faking the origin position)
if (isStartpoint) {
if (rc.startDirectionValid) {
double dir = rc.startDirection.intValue() * CheapRuler.DEG_TO_RAD;
double dir = rc.startDirection * CheapRuler.DEG_TO_RAD;
double[] lonlat2m = CheapRuler.getLonLatToMeterScales((lon0 + lat1) >> 1);
lon0 = lon1 - (int) (1000. * Math.sin(dir) / lonlat2m[0]);
lat0 = lat1 - (int) (1000. * Math.cos(dir) / lonlat2m[1]);
Expand Down
4 changes: 2 additions & 2 deletions brouter-core/src/main/java/btools/router/OsmTrack.java
Expand Up @@ -166,7 +166,7 @@ public void buildMap() {
}

public List<String> aggregateMessages() {
ArrayList<String> res = new ArrayList<>();
List<String> res = new ArrayList<>();
MessageData current = null;
for (OsmPathElement n : nodes) {
if (n.message != null && n.message.wayKeyValues != null) {
Expand All @@ -188,7 +188,7 @@ public List<String> aggregateMessages() {
}

public List<String> aggregateSpeedProfile() {
ArrayList<String> res = new ArrayList<>();
List<String> res = new ArrayList<>();
int vmax = -1;
int vmaxe = -1;
int vmin = -1;
Expand Down
10 changes: 5 additions & 5 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Expand Up @@ -187,7 +187,7 @@ public void doRouting(long maxRunningTime) {
OsmTrack[] refTracks = new OsmTrack[nsections]; // used ways for alternatives
OsmTrack[] lastTracks = new OsmTrack[nsections];
OsmTrack track = null;
ArrayList<String> messageList = new ArrayList<>();
List<String> messageList = new ArrayList<>();
for (int i = 0; ; i++) {
track = findTrack(refTracks, lastTracks);
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
Expand Down Expand Up @@ -690,9 +690,9 @@ private boolean snappPathConnection(OsmTrack tt, OsmTrack t, MatchedWaypoint sta
return false;
}
}
ArrayList<OsmPathElement> removeBackList = new ArrayList<>();
ArrayList<OsmPathElement> removeForeList = new ArrayList<>();
ArrayList<Integer> removeVoiceHintList = new ArrayList<>();
List<OsmPathElement> removeBackList = new ArrayList<>();
List<OsmPathElement> removeForeList = new ArrayList<>();
List<Integer> removeVoiceHintList = new ArrayList<>();
OsmPathElement last = null;
OsmPathElement lastJunction = null;
CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>();
Expand Down Expand Up @@ -1246,7 +1246,7 @@ private OsmTrack _findTrack(String operationName, MatchedWaypoint startWp, Match
addToOpenset(startPath1);
addToOpenset(startPath2);
}
ArrayList<OsmPath> openBorderList = new ArrayList<>(4096);
List<OsmPath> openBorderList = new ArrayList<>(4096);
boolean memoryPanicMode = false;
boolean needNonPanicProcessing = false;

Expand Down
Expand Up @@ -101,7 +101,7 @@ private OsmNodeNamed readPosition(double lon, double lat, String name) {
* @throws UnsupportedEncodingException
*/
public Map<String, String> getUrlParams(String url) throws UnsupportedEncodingException {
HashMap<String, String> params = new HashMap<>();
Map<String, String> params = new HashMap<>();
String decoded = URLDecoder.decode(url, "UTF-8");
StringTokenizer tk = new StringTokenizer(decoded, "?&");
while (tk.hasMoreTokens()) {
Expand Down
3 changes: 0 additions & 3 deletions brouter-expressions/src/main/AndroidManifest.xml

This file was deleted.

Expand Up @@ -242,15 +242,15 @@ private static BExpression parseRaw(BExpressionContext ctx, int level, String op
}
// parse operands
if (nops > 0) {
exp.op1 = BExpression.parse(ctx, level + 1, exp.typ == ASSIGN_EXP ? "=" : null);
exp.op1 = parse(ctx, level + 1, exp.typ == ASSIGN_EXP ? "=" : null);
}
if (nops > 1) {
if (ifThenElse) checkExpectedToken(ctx, "then");
exp.op2 = BExpression.parse(ctx, level + 1, null);
exp.op2 = parse(ctx, level + 1, null);
}
if (nops > 2) {
if (ifThenElse) checkExpectedToken(ctx, "else");
exp.op3 = BExpression.parse(ctx, level + 1, null);
exp.op3 = parse(ctx, level + 1, null);
}
if (brackets) {
checkExpectedToken(ctx, ")");
Expand Down
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
Expand Down Expand Up @@ -227,7 +228,7 @@ public String getKeyValueDescription(boolean inverseDirection, byte[] ab) {
}

public List<String> getKeyValueList(boolean inverseDirection, byte[] ab) {
ArrayList<String> res = new ArrayList<>();
List<String> res = new ArrayList<>();
decode(lookupData, inverseDirection, ab);
for (int inum = 0; inum < lookupValues.size(); inum++) { // loop over lookup names
BExpressionLookupValue[] va = lookupValues.get(inum);
Expand All @@ -245,7 +246,7 @@ public List<String> getKeyValueList(boolean inverseDirection, byte[] ab) {
public int getLookupKey(String name) {
int res = -1;
try {
res = lookupNumbers.get(name).intValue();
res = lookupNumbers.get(name);
} catch (Exception e) {
}
return res;
Expand Down Expand Up @@ -433,11 +434,11 @@ private void evaluateInto(float[] vars, int offset) {


public void dumpStatistics() {
TreeMap<String, String> counts = new TreeMap<>();
NavigableMap<String, String> counts = new TreeMap<>();
// first count
for (String name : lookupNumbers.keySet()) {
int cnt = 0;
int inum = lookupNumbers.get(name).intValue();
int inum = lookupNumbers.get(name);
int[] histo = lookupHistograms.get(inum);
// if ( histo.length == 500 ) continue;
for (int i = 2; i < histo.length; i++) {
Expand All @@ -450,7 +451,7 @@ public void dumpStatistics() {
String key = counts.lastEntry().getKey();
String name = counts.get(key);
counts.remove(key);
int inum = lookupNumbers.get(name).intValue();
int inum = lookupNumbers.get(name);
BExpressionLookupValue[] values = lookupValues.get(inum);
int[] histo = lookupHistograms.get(inum);
if (values.length == 1000) continue;
Expand Down Expand Up @@ -507,7 +508,7 @@ public void assertAllVariablesEqual(BExpressionContext other) {

public String variableName(int idx) {
for (Map.Entry<String, Integer> e : variableNumbers.entrySet()) {
if (e.getValue().intValue() == idx) {
if (e.getValue() == idx) {
return e.getKey();
}
}
Expand Down Expand Up @@ -544,9 +545,8 @@ public BExpressionLookupValue addLookupValue(String name, String value, int[] lo
}

// look for that value
int inum = num.intValue();
BExpressionLookupValue[] values = lookupValues.get(inum);
int[] histo = lookupHistograms.get(inum);
BExpressionLookupValue[] values = lookupValues.get(num);
int[] histo = lookupHistograms.get(num);
int i = 0;
boolean bFoundAsterix = false;
for (; i < values.length; i++) {
Expand All @@ -558,7 +558,7 @@ public BExpressionLookupValue addLookupValue(String name, String value, int[] lo
if (lookupData2 != null) {
// do not create unknown value for external data array,
// record as 'unknown' instead
lookupData2[inum] = 1; // 1 == unknown
lookupData2[num] = 1; // 1 == unknown
if (bFoundAsterix) {
// found value for lookup *
//System.out.println( "add unknown " + name + " " + value );
Expand Down Expand Up @@ -652,11 +652,11 @@ public BExpressionLookupValue addLookupValue(String name, String value, int[] lo
// found negative maxdraft values
// no negative values
// values are float with 2 decimals
lookupData2[inum] = 1000 + (int) (Math.abs(Float.parseFloat(value)) * 100f);
lookupData2[num] = 1000 + (int) (Math.abs(Float.parseFloat(value)) * 100f);
} catch (Exception e) {
// ignore errors
System.err.println("error for " + name + " " + org + " trans " + value + " " + e.getMessage());
lookupData2[inum] = 0;
lookupData2[num] = 0;
}
}
return newValue;
Expand All @@ -677,15 +677,15 @@ public BExpressionLookupValue addLookupValue(String name, String value, int[] lo
histo = nhisto;
newValue = new BExpressionLookupValue(value);
values[i] = newValue;
lookupHistograms.set(inum, histo);
lookupValues.set(inum, values);
lookupHistograms.set(num, histo);
lookupValues.set(num, values);
}

histo[i]++;

// finally remember the actual data
if (lookupData2 != null) lookupData2[inum] = i;
else lookupData[inum] = i;
if (lookupData2 != null) lookupData2[num] = i;
else lookupData[num] = i;
return newValue;
}

Expand All @@ -700,11 +700,10 @@ public void addLookupValue(String name, int valueIndex) {
}

// look for that value
int inum = num.intValue();
int nvalues = lookupValues.get(inum).length;
int nvalues = lookupValues.get(num).length;
if (valueIndex < 0 || valueIndex >= nvalues)
throw new IllegalArgumentException("value index out of range for name " + name + ": " + valueIndex);
lookupData[inum] = valueIndex;
lookupData[num] = valueIndex;
}


Expand All @@ -721,9 +720,8 @@ public void addSmallestLookupValue(String name, int valueIndex) {
}

// look for that value
int inum = num.intValue();
int nvalues = lookupValues.get(inum).length;
int oldValueIndex = lookupData[inum];
int nvalues = lookupValues.get(num).length;
int oldValueIndex = lookupData[num];
if (oldValueIndex > 1 && oldValueIndex < valueIndex) {
return;
}
Expand All @@ -732,12 +730,12 @@ public void addSmallestLookupValue(String name, int valueIndex) {
}
if (valueIndex < 0)
throw new IllegalArgumentException("value index out of range for name " + name + ": " + valueIndex);
lookupData[inum] = valueIndex;
lookupData[num] = valueIndex;
}

public boolean getBooleanLookupValue(String name) {
Integer num = lookupNumbers.get(name);
return num != null && lookupData[num.intValue()] == 2;
return num != null && lookupData[num] == 2;
}

public int getOutputVariableIndex(String name, boolean mustExist) {
Expand Down Expand Up @@ -849,7 +847,7 @@ private List<BExpression> _parseFile(File file, Map<String, String> keyValues) t
public void setVariableValue(String name, float value, boolean create) {
Integer num = variableNumbers.get(name);
if (num != null) {
variableData[num.intValue()] = value;
variableData[num] = value;
} else if (create) {
num = getVariableIdx(name, create);
float[] readOnlyData = variableData;
Expand All @@ -858,13 +856,13 @@ public void setVariableValue(String name, float value, boolean create) {
for (int i = 0; i < minWriteIdx; i++) {
variableData[i] = readOnlyData[i];
}
variableData[num.intValue()] = value;
variableData[num] = value;
}
}

public float getVariableValue(String name, float defaultValue) {
Integer num = variableNumbers.get(name);
return num == null ? defaultValue : getVariableValue(num.intValue());
return num == null ? defaultValue : getVariableValue(num);
}

float getVariableValue(int variableIdx) {
Expand All @@ -882,7 +880,7 @@ int getVariableIdx(String name, boolean create) {
return -1;
}
}
return num.intValue();
return num;
}

int getMinWriteIdx() {
Expand All @@ -900,7 +898,7 @@ float getLookupMatch(int nameIdx, int[] valueIdxArray) {

public int getLookupNameIdx(String name) {
Integer num = lookupNumbers.get(name);
return num == null ? -1 : num.intValue();
return num == null ? -1 : num;
}

public final void markLookupIdxUsed(int idx) {
Expand Down
Expand Up @@ -184,10 +184,10 @@ private void loadColors(String colors) {
if (DEBUG) System.out.println(line);
String[] sa = line.split(",");
if (!line.startsWith("#") && sa.length == 4) {
short e = Short.valueOf(sa[0].trim());
short r = Short.valueOf(sa[1].trim());
short g = Short.valueOf(sa[2].trim());
short b = Short.valueOf(sa[3].trim());
short e = Short.parseShort(sa[0].trim());
short r = Short.parseShort(sa[1].trim());
short g = Short.parseShort(sa[2].trim());
short b = Short.parseShort(sa[3].trim());
colorMap.put(e, new Color(r, g, b));
}
// read next line
Expand Down