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

Static code analysis using PMD #483

Merged
merged 12 commits into from
Nov 23, 2022
Merged
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package btools.codec;

import java.util.Map;
import java.util.TreeMap;

import btools.util.BitCoderContext;

public final class StatCoderContext extends BitCoderContext {
private static TreeMap<String, long[]> statsPerName;
private static Map<String, long[]> statsPerName;
private long lastbitpos = 0;


Expand Down
3 changes: 2 additions & 1 deletion brouter-codec/src/main/java/btools/codec/TagValueCoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

import btools.util.BitCoderContext;
Expand All @@ -16,7 +17,7 @@
* but doesn't do anything at pass1
*/
public final class TagValueCoder {
private HashMap<TagValueSet, TagValueSet> identityMap;
private Map<TagValueSet, TagValueSet> identityMap;
private Object tree;
private BitCoderContext bc;
private int pass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ public interface TagValueValidator {
* @param tagValueSet the way description to check
* @return 0 = nothing, 1=no matching, 2=normal
*/
public int accessType(byte[] tagValueSet);
int accessType(byte[] tagValueSet);

public byte[] unify(byte[] tagValueSet, int offset, int len);
byte[] unify(byte[] tagValueSet, int offset, int len);

public boolean isLookupIdxUsed(int idx);
boolean isLookupIdxUsed(int idx);

public void setDecodeForbidden(boolean decodeForbidden);
void setDecodeForbidden(boolean decodeForbidden);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ public void linkedListTest1() {

for (int ln = 0; ln < nlists; ln++) {
int cnt = llc.initList(ln);
Assert.assertTrue("list size test", cnt == 20);
Assert.assertEquals("list size test", 20, cnt);

for (int i = 19; i >= 0; i--) {
int data = llc.getDataElement();
Assert.assertTrue("data value test", data == ln * (i % 10));
Assert.assertEquals("data value test", ln * (i % 10), data);
}
}

try {
llc.getDataElement();
Assert.fail("no more elements expected");
} catch (IllegalArgumentException e) {
}
Assert.assertThrows("no more elements expected", IllegalArgumentException.class, () -> llc.getDataElement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public void calcBoundingCircle() {
ilon = cx;
ilat = cy;
radius = rad * 1.001 + 1.0; // ensure the outside-of-enclosing-circle test in RoutingContext.calcDistance() is not passed by segments ending very close to the radius due to limited numerical precision
return;
}

/**
Expand Down
1 change: 0 additions & 1 deletion brouter-core/src/main/java/btools/router/OsmPrePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import btools.mapaccess.OsmLink;
import btools.mapaccess.OsmNode;
import btools.mapaccess.OsmTransferNode;

public abstract class OsmPrePath {
protected OsmNode sourceNode;
Expand Down
10 changes: 5 additions & 5 deletions brouter-core/src/main/java/btools/router/OsmTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static class OsmPathElementHolder {
public OsmPathElementHolder nextHolder;
}

public ArrayList<OsmPathElement> nodes = new ArrayList<OsmPathElement>();
public List<OsmPathElement> nodes = new ArrayList<OsmPathElement>();

private CompactLongMap<OsmPathElementHolder> nodesMap;

Expand All @@ -62,7 +62,7 @@ private static class OsmPathElementHolder {
private VoiceHintList voiceHints;

public String message = null;
public ArrayList<String> messageList = null;
public List<String> messageList = null;

public String name = "unset";

Expand Down Expand Up @@ -113,7 +113,7 @@ public void buildMap() {
nodesMap = new FrozenLongMap<OsmPathElementHolder>(nodesMap);
}

private ArrayList<String> aggregateMessages() {
private List<String> aggregateMessages() {
ArrayList<String> res = new ArrayList<String>();
MessageData current = null;
for (OsmPathElement n : nodes) {
Expand All @@ -135,7 +135,7 @@ private ArrayList<String> aggregateMessages() {
return res;
}

private ArrayList<String> aggregateSpeedProfile() {
private List<String> aggregateSpeedProfile() {
ArrayList<String> res = new ArrayList<String>();
int vmax = -1;
int vmaxe = -1;
Expand Down Expand Up @@ -673,7 +673,7 @@ public String formatAsGeoJson() {
}
if (showSpeedProfile) // set in profile
{
ArrayList<String> sp = aggregateSpeedProfile();
List<String> sp = aggregateSpeedProfile();
if (sp.size() > 0) {
sb.append(" \"speedprofile\": [\n");
for (int i = sp.size() - 1; i >= 0; i--) {
Expand Down
4 changes: 2 additions & 2 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
}
if (hasInfo()) {
boolean found = nearbyTrack != null;
boolean dirty = found ? nearbyTrack.isDirty : false;
boolean dirty = found && nearbyTrack.isDirty;
logInfo("read referenceTrack, found=" + found + " dirty=" + dirty + " " + debugInfo);
}
}
Expand Down Expand Up @@ -1078,7 +1078,7 @@ public int[] getOpenSet() {

synchronized (openSet) {
if (guideTrack != null) {
ArrayList<OsmPathElement> nodes = guideTrack.nodes;
List<OsmPathElement> nodes = guideTrack.nodes;
int[] res = new int[nodes.size() * 2];
int i = 0;
for (OsmPathElement n : nodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class VoiceHintList {
private String transportMode;
int turnInstructionMode;
ArrayList<VoiceHint> list = new ArrayList<VoiceHint>();
List<VoiceHint> list = new ArrayList<VoiceHint>();

public void setTransportMode(boolean isCar, boolean isBike) {
transportMode = isCar ? "car" : (isBike ? "bike" : "foot");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package btools.router;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import btools.util.CheapRuler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public String _modelClass;

private Map<String, Integer> lookupNumbers = new HashMap<String, Integer>();
private ArrayList<BExpressionLookupValue[]> lookupValues = new ArrayList<BExpressionLookupValue[]>();
private ArrayList<String> lookupNames = new ArrayList<String>();
private ArrayList<int[]> lookupHistograms = new ArrayList<int[]>();
private List<BExpressionLookupValue[]> lookupValues = new ArrayList<BExpressionLookupValue[]>();
private List<String> lookupNames = new ArrayList<String>();
private List<int[]> lookupHistograms = new ArrayList<int[]>();
private boolean[] lookupIdxUsed;

private boolean lookupDataFrozen = false;
Expand Down Expand Up @@ -805,10 +805,9 @@ public void parseFile(File file, String readOnlyContext) {
for (int i = 0; i < minWriteIdx; i++) {
variableData[i] = readOnlyData[i];
}
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("ParseException " + file + " at line " + linenr + ": " + e.getMessage());
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
throw new IllegalArgumentException("ParseException " + file + " at line " + linenr + ": " + e.getMessage());
}
throw new RuntimeException(e);
}
if (expressionList.size() == 0) {
Expand Down Expand Up @@ -883,7 +882,7 @@ public final void markLookupIdxUsed(int idx) {
}

public final boolean isLookupIdxUsed(int idx) {
return idx < lookupIdxUsed.length ? lookupIdxUsed[idx] : false;
return idx < lookupIdxUsed.length && lookupIdxUsed[idx];
}

public final void setAllTagsUsed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
package btools.expressions;

import java.util.ArrayList;
import java.util.List;

final class BExpressionLookupValue {
String value;
ArrayList<String> aliases;
List<String> aliases;

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,8 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

import btools.util.BitCoderContext;
import btools.util.Crc32;


public final class BExpressionMetaData {
Expand All @@ -30,7 +22,7 @@ public final class BExpressionMetaData {
public short lookupVersion = -1;
public short lookupMinorVersion = -1;

private HashMap<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>();
private Map<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>();

public void registerListener(String context, BExpressionContext ctx) {
listeners.put(context, ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package btools.expressions;

import java.io.File;
import java.io.IOException;

public class IntegrityCheckProfile {

public static void main(final java.lang.String[] args) {
public static void main(final String[] args) {
if (args.length != 2) {
System.out.println("usage: java IntegrityCheckProfile <lookup-file> <profile-folder>");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package btools.expressions;

import java.util.*;
import java.io.*;
import java.net.URL;

import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.net.URL;

public class EncodeDecodeTest {
@Test
public void encodeDecodeTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package btools.mapcreator;

import java.util.ArrayList;
import java.util.List;

import btools.util.CheapRuler;

Expand All @@ -15,7 +15,7 @@ public class DPFilter {
/*
* for each node (except first+last), eventually set the DP_SURVIVOR_BIT
*/
public static void doDPFilter(ArrayList<OsmNodeP> nodes) {
public static void doDPFilter(List<OsmNodeP> nodes) {
int first = 0;
int last = nodes.size() - 1;
while (first < last && (nodes.get(first + 1).bits & OsmNodeP.DP_SURVIVOR_BIT) != 0) {
Expand All @@ -30,7 +30,7 @@ public static void doDPFilter(ArrayList<OsmNodeP> nodes) {
}


public static void doDPFilter(ArrayList<OsmNodeP> nodes, int first, int last) {
public static void doDPFilter(List<OsmNodeP> nodes, int first, int last) {
double maxSqDist = -1.;
int index = -1;
OsmNodeP p1 = nodes.get(first);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import btools.util.DiffCoderDataOutputStream;

public abstract class MapCreatorBase implements WayListener, NodeListener, RelationListener {
private DiffCoderDataOutputStream[] tileOutStreams;
protected File outTileDir;

protected HashMap<String, String> tags;
protected Map<String, String> tags;

public void putTag(String key, String value) {
if (tags == null) tags = new HashMap<String, String>();
Expand All @@ -32,11 +33,11 @@ public String getTag(String key) {
return tags == null ? null : tags.get(key);
}

public HashMap<String, String> getTagsOrNull() {
public Map<String, String> getTagsOrNull() {
return tags;
}

public void setTags(HashMap<String, String> tags) {
public void setTags(Map<String, String> tags) {
this.tags = tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.io.IOException;
import java.util.Map;

import btools.expressions.BExpressionContextNode;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void nextNode(NodeData n) throws Exception {
}


private void generatePseudoTags(HashMap<String, String> map) {
private void generatePseudoTags(Map<String, String> map) {
// add pseudo.tags for concrete:lanes and concrete:plates

String concrete = null;
Expand Down Expand Up @@ -204,7 +204,7 @@ public void nextWay(WayData w) throws Exception {
}

@Override
public void nextRelation(RelationData r) throws Exception {
public void nextRelation(RelationData r) throws IOException {
relsParsed++;
checkStats();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import btools.expressions.BExpressionContextWay;
import btools.util.CheapRuler;
Expand Down Expand Up @@ -188,7 +188,7 @@ public OsmTrafficElement getElement(long n) {
return map.get(n);
}

public byte[] addTrafficClass(ArrayList<OsmNodeP> linkNodes, byte[] description) throws IOException {
public byte[] addTrafficClass(List<OsmNodeP> linkNodes, byte[] description) throws IOException {
double distance = 0.;
double sum = 0.;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import btools.util.CompactLongSet;
import btools.util.DiffCoderDataOutputStream;
Expand All @@ -26,7 +27,7 @@ public class PosUnifier extends MapCreatorBase {
private File nodeTilesOut;
private CompactLongSet[] positionSets;

private HashMap<String, SrtmRaster> srtmmap;
private Map<String, SrtmRaster> srtmmap;
private int lastSrtmLonIdx;
private int lastSrtmLatIdx;
private SrtmRaster lastSrtmRaster;
Expand Down
Loading