Fix newly detected violations from PMD 7

This commit is contained in:
Manuel Fuhr 2024-04-03 14:41:06 +02:00
parent 2f7ce42480
commit dd896347a2
28 changed files with 65 additions and 57 deletions

View file

@ -1,6 +1,7 @@
package btools.codec; package btools.codec;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import btools.util.ByteDataReader; import btools.util.ByteDataReader;
import btools.util.IByteArrayUnifier; import btools.util.IByteArrayUnifier;
@ -287,7 +288,7 @@ public final class MicroCache2 extends MicroCache {
@Override @Override
public int encodeMicroCache(byte[] buffer) { 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 for (int n = 0; n < size; n++) { // loop over nodes
idMap.put(expandId(faid[n]), n); idMap.put(expandId(faid[n]), n);
} }

View file

@ -4,6 +4,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.Queue;
import btools.util.BitCoderContext; import btools.util.BitCoderContext;
@ -58,7 +59,7 @@ public final class TagValueCoder {
TagValueSet dummy = new TagValueSet(nextTagValueSetId++); TagValueSet dummy = new TagValueSet(nextTagValueSetId++);
identityMap.put(dummy, dummy); 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()); queue.addAll(identityMap.values());
while (queue.size() > 1) { while (queue.size() > 1) {
TagValueSet node = new TagValueSet(nextTagValueSetId++); TagValueSet node = new TagValueSet(nextTagValueSetId++);

View file

@ -168,7 +168,7 @@ public class OsmNogoPolygon extends OsmNodeNamed {
Point p1 = points.get(0); Point p1 = points.get(0);
for (int i = 1; i <= i_last; i++) { for (int i = 1; i <= i_last; i++) {
final Point p2 = points.get(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; return true;
} }
p1 = p2; p1 = p2;
@ -234,7 +234,7 @@ public class OsmNogoPolygon extends OsmNodeNamed {
final long p1x = p1.x; final long p1x = p1.x;
final long p1y = p1.y; final long p1y = p1.y;
if (OsmNogoPolygon.isOnLine(px, py, p0x, p0y, p1x, p1y)) { if (isOnLine(px, py, p0x, p0y, p1x, p1y)) {
return true; return true;
} }

View file

@ -166,7 +166,7 @@ public final class OsmTrack {
} }
public List<String> aggregateMessages() { public List<String> aggregateMessages() {
ArrayList<String> res = new ArrayList<>(); List<String> res = new ArrayList<>();
MessageData current = null; MessageData current = null;
for (OsmPathElement n : nodes) { for (OsmPathElement n : nodes) {
if (n.message != null && n.message.wayKeyValues != null) { if (n.message != null && n.message.wayKeyValues != null) {
@ -188,7 +188,7 @@ public final class OsmTrack {
} }
public List<String> aggregateSpeedProfile() { public List<String> aggregateSpeedProfile() {
ArrayList<String> res = new ArrayList<>(); List<String> res = new ArrayList<>();
int vmax = -1; int vmax = -1;
int vmaxe = -1; int vmaxe = -1;
int vmin = -1; int vmin = -1;

View file

@ -187,7 +187,7 @@ public class RoutingEngine extends Thread {
OsmTrack[] refTracks = new OsmTrack[nsections]; // used ways for alternatives OsmTrack[] refTracks = new OsmTrack[nsections]; // used ways for alternatives
OsmTrack[] lastTracks = new OsmTrack[nsections]; OsmTrack[] lastTracks = new OsmTrack[nsections];
OsmTrack track = null; OsmTrack track = null;
ArrayList<String> messageList = new ArrayList<>(); List<String> messageList = new ArrayList<>();
for (int i = 0; ; i++) { for (int i = 0; ; i++) {
track = findTrack(refTracks, lastTracks); track = findTrack(refTracks, lastTracks);
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
@ -690,9 +690,9 @@ public class RoutingEngine extends Thread {
return false; return false;
} }
} }
ArrayList<OsmPathElement> removeBackList = new ArrayList<>(); List<OsmPathElement> removeBackList = new ArrayList<>();
ArrayList<OsmPathElement> removeForeList = new ArrayList<>(); List<OsmPathElement> removeForeList = new ArrayList<>();
ArrayList<Integer> removeVoiceHintList = new ArrayList<>(); List<Integer> removeVoiceHintList = new ArrayList<>();
OsmPathElement last = null; OsmPathElement last = null;
OsmPathElement lastJunction = null; OsmPathElement lastJunction = null;
CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>(); CompactLongMap<OsmTrack.OsmPathElementHolder> lastJunctions = new CompactLongMap<>();
@ -1246,7 +1246,7 @@ public class RoutingEngine extends Thread {
addToOpenset(startPath1); addToOpenset(startPath1);
addToOpenset(startPath2); addToOpenset(startPath2);
} }
ArrayList<OsmPath> openBorderList = new ArrayList<>(4096); List<OsmPath> openBorderList = new ArrayList<>(4096);
boolean memoryPanicMode = false; boolean memoryPanicMode = false;
boolean needNonPanicProcessing = false; boolean needNonPanicProcessing = false;

View file

@ -101,7 +101,7 @@ public class RoutingParamCollector {
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public Map<String, String> getUrlParams(String url) 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"); String decoded = URLDecoder.decode(url, "UTF-8");
StringTokenizer tk = new StringTokenizer(decoded, "?&"); StringTokenizer tk = new StringTokenizer(decoded, "?&");
while (tk.hasMoreTokens()) { while (tk.hasMoreTokens()) {

View file

@ -242,15 +242,15 @@ final class BExpression {
} }
// parse operands // parse operands
if (nops > 0) { 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 (nops > 1) {
if (ifThenElse) checkExpectedToken(ctx, "then"); if (ifThenElse) checkExpectedToken(ctx, "then");
exp.op2 = BExpression.parse(ctx, level + 1, null); exp.op2 = parse(ctx, level + 1, null);
} }
if (nops > 2) { if (nops > 2) {
if (ifThenElse) checkExpectedToken(ctx, "else"); if (ifThenElse) checkExpectedToken(ctx, "else");
exp.op3 = BExpression.parse(ctx, level + 1, null); exp.op3 = parse(ctx, level + 1, null);
} }
if (brackets) { if (brackets) {
checkExpectedToken(ctx, ")"); checkExpectedToken(ctx, ")");

View file

@ -14,6 +14,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.TreeMap; import java.util.TreeMap;
@ -227,7 +228,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
} }
public List<String> getKeyValueList(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); decode(lookupData, inverseDirection, ab);
for (int inum = 0; inum < lookupValues.size(); inum++) { // loop over lookup names for (int inum = 0; inum < lookupValues.size(); inum++) { // loop over lookup names
BExpressionLookupValue[] va = lookupValues.get(inum); BExpressionLookupValue[] va = lookupValues.get(inum);
@ -433,7 +434,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public void dumpStatistics() { public void dumpStatistics() {
TreeMap<String, String> counts = new TreeMap<>(); NavigableMap<String, String> counts = new TreeMap<>();
// first count // first count
for (String name : lookupNumbers.keySet()) { for (String name : lookupNumbers.keySet()) {
int cnt = 0; int cnt = 0;

View file

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

View file

@ -90,7 +90,6 @@ public class ElevationRasterTileConverter {
} else { } else {
System.out.println("usage: java <srtm-filename> <hgt-data-dir> <srtm-output-dir> [arc seconds (1 or 3,default=3)] [hgt-fallback-data-dir]"); System.out.println("usage: java <srtm-filename> <hgt-data-dir> <srtm-output-dir> [arc seconds (1 or 3,default=3)] [hgt-fallback-data-dir]");
System.out.println("or java all <hgt-data-dir> <srtm-output-dir> [arc seconds (1 or 3, default=3)] [hgt-fallback-data-dir]"); System.out.println("or java all <hgt-data-dir> <srtm-output-dir> [arc seconds (1 or 3, default=3)] [hgt-fallback-data-dir]");
return;
} }
} }

View file

@ -8,6 +8,8 @@ package btools.mapcreator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import btools.codec.MicroCache; import btools.codec.MicroCache;
import btools.codec.MicroCache2; import btools.codec.MicroCache2;
@ -105,7 +107,7 @@ public class OsmNodeP extends OsmLinkP {
} }
public void checkDuplicateTargets() { public void checkDuplicateTargets() {
HashMap<OsmNodeP, OsmLinkP> targets = new HashMap<>(); Map<OsmNodeP, OsmLinkP> targets = new HashMap<>();
for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) { for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) {
OsmLinkP link = link0; OsmLinkP link = link0;
@ -165,14 +167,14 @@ public class OsmNodeP extends OsmLinkP {
mc.writeVarBytes(getNodeDecsription()); mc.writeVarBytes(getNodeDecsription());
// buffer internal reverse links // buffer internal reverse links
ArrayList<OsmNodeP> internalReverse = new ArrayList<>(); List<OsmNodeP> internalReverse = new ArrayList<>();
for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) { for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) {
OsmLinkP link = link0; OsmLinkP link = link0;
OsmNodeP origin = this; OsmNodeP origin = this;
OsmNodeP target = null; OsmNodeP target = null;
ArrayList<OsmNodeP> linkNodes = new ArrayList<>(); List<OsmNodeP> linkNodes = new ArrayList<>();
linkNodes.add(this); linkNodes.add(this);
// first pass just to see if that link is consistent // first pass just to see if that link is consistent
@ -226,7 +228,7 @@ public class OsmNodeP extends OsmLinkP {
origin = this; origin = this;
for (int i = 1; i < linkNodes.size() - 1; i++) { for (int i = 1; i < linkNodes.size() - 1; i++) {
OsmNodeP tranferNode = linkNodes.get(i); OsmNodeP tranferNode = linkNodes.get(i);
if ((tranferNode.bits & OsmNodeP.DP_SURVIVOR_BIT) != 0) { if ((tranferNode.bits & DP_SURVIVOR_BIT) != 0) {
mc.writeVarLengthSigned(tranferNode.ilon - origin.ilon); mc.writeVarLengthSigned(tranferNode.ilon - origin.ilon);
mc.writeVarLengthSigned(tranferNode.ilat - origin.ilat); mc.writeVarLengthSigned(tranferNode.ilat - origin.ilat);
mc.writeVarLengthSigned(tranferNode.getSElev() - origin.getSElev()); mc.writeVarLengthSigned(tranferNode.getSElev() - origin.getSElev());

View file

@ -4,6 +4,7 @@ import java.io.DataInputStream;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
/** /**
* WayCutter does 2 step in map-processing: * WayCutter does 2 step in map-processing:
@ -25,7 +26,7 @@ public class RelationStatistics extends MapCreatorBase {
} }
public void process(File relationFileIn) throws Exception { public void process(File relationFileIn) throws Exception {
HashMap<String, long[]> relstats = new HashMap<>(); Map<String, long[]> relstats = new HashMap<>();
DataInputStream dis = createInStream(relationFileIn); DataInputStream dis = createInStream(relationFileIn);
try { try {

View file

@ -9,6 +9,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import btools.codec.DataBuffers; import btools.codec.DataBuffers;
@ -481,7 +482,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
MicroCache mc = new MicroCache2(size, abBuf2, lonIdxDiv, latIdxDiv, divisor); MicroCache mc = new MicroCache2(size, abBuf2, lonIdxDiv, latIdxDiv, divisor);
// sort via treemap // sort via treemap
TreeMap<Integer, OsmNodeP> sortedList = new TreeMap<>(); Map<Integer, OsmNodeP> sortedList = new TreeMap<>();
for (OsmNodeP n : subList) { for (OsmNodeP n : subList) {
long longId = n.getIdFromPos(); long longId = n.getIdFromPos();
int shrinkid = mc.shrinkId(longId); int shrinkid = mc.shrinkId(longId);

View file

@ -31,7 +31,6 @@ final class OsmFile {
private int divisor; private int divisor;
private int cellsize; private int cellsize;
private int ncaches;
private int indexsize; private int indexsize;
protected byte elevationType = 3; protected byte elevationType = 3;
@ -47,7 +46,7 @@ final class OsmFile {
elevationType = rafile.elevationType; elevationType = rafile.elevationType;
cellsize = 1000000 / divisor; cellsize = 1000000 / divisor;
ncaches = divisor * divisor; int ncaches = divisor * divisor;
indexsize = ncaches * 4; indexsize = ncaches * 4;
byte[] iobuffer = dataBuffers.iobuffer; byte[] iobuffer = dataBuffers.iobuffer;

View file

@ -21,7 +21,7 @@ public class OsmNodePairSet {
n2a = new long[maxTempNodes]; n2a = new long[maxTempNodes];
} }
private static class OsmNodePair { private static final class OsmNodePair {
public long node2; public long node2;
public OsmNodePair next; public OsmNodePair next;
} }

View file

@ -51,7 +51,7 @@ public final class WaypointMatcherImpl implements WaypointMatcher {
} }
// sort result list // sort result list
comparator = new Comparator<MatchedWaypoint>() { comparator = new Comparator<>() {
@Override @Override
public int compare(MatchedWaypoint mw1, MatchedWaypoint mw2) { public int compare(MatchedWaypoint mw1, MatchedWaypoint mw2) {
int cmpDist = Double.compare(mw1.radius, mw2.radius); int cmpDist = Double.compare(mw1.radius, mw2.radius);

View file

@ -31,7 +31,7 @@ public class IpAccessMonitor {
} }
private static void cleanup(long t) { private static void cleanup(long t) {
HashMap<String, Long> newMap = new HashMap<>(ipAccess.size()); Map<String, Long> newMap = new HashMap<>(ipAccess.size());
for (Map.Entry<String, Long> e : ipAccess.entrySet()) { for (Map.Entry<String, Long> e : ipAccess.entrySet()) {
if (t - e.getValue().longValue() <= MAX_IDLE) { if (t - e.getValue().longValue() <= MAX_IDLE) {
newMap.put(e.getKey(), e.getValue()); newMap.put(e.getKey(), e.getValue());

View file

@ -3,6 +3,7 @@ package btools.server;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
public class Polygon { public class Polygon {
@ -15,7 +16,7 @@ public class Polygon {
private int maxy = Integer.MIN_VALUE; private int maxy = Integer.MIN_VALUE;
public Polygon(BufferedReader br) throws IOException { public Polygon(BufferedReader br) throws IOException {
ArrayList<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
for (; ; ) { for (; ; ) {
String line = br.readLine(); String line = br.readLine();

View file

@ -21,6 +21,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
@ -299,7 +300,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
ProfileCache.setSize(2 * maxthreads); ProfileCache.setSize(2 * maxthreads);
PriorityQueue<RouteServer> threadQueue = new PriorityQueue<>(); Queue<RouteServer> threadQueue = new PriorityQueue<>();
ServerSocket serverSocket = args.length > 5 ? new ServerSocket(Integer.parseInt(args[3]), 100, InetAddress.getByName(args[5])) : new ServerSocket(Integer.parseInt(args[3])); ServerSocket serverSocket = args.length > 5 ? new ServerSocket(Integer.parseInt(args[3]), 100, InetAddress.getByName(args[5])) : new ServerSocket(Integer.parseInt(args[3]));
@ -364,7 +365,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
private static Map<String, String> getUrlParams(String url) throws UnsupportedEncodingException { private static 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"); String decoded = URLDecoder.decode(url, "UTF-8");
StringTokenizer tk = new StringTokenizer(decoded, "?&"); StringTokenizer tk = new StringTokenizer(decoded, "?&");
while (tk.hasMoreTokens()) { while (tk.hasMoreTokens()) {
@ -417,7 +418,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
bw.write("\n"); bw.write("\n");
} }
private static void cleanupThreadQueue(PriorityQueue<RouteServer> threadQueue) { private static void cleanupThreadQueue(Queue<RouteServer> threadQueue) {
for (; ; ) { for (; ; ) {
boolean removedItem = false; boolean removedItem = false;
for (RouteServer t : threadQueue) { for (RouteServer t : threadQueue) {

View file

@ -9,6 +9,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.TreeSet; import java.util.TreeSet;
@ -244,7 +245,7 @@ public class SuspectManager extends Thread {
bw.write("<table>\n"); bw.write("<table>\n");
File countryParent = new File("worldpolys" + country); File countryParent = new File("worldpolys" + country);
File[] files = countryParent.listFiles(); File[] files = countryParent.listFiles();
TreeSet<String> names = new TreeSet<>(); Set<String> names = new TreeSet<>();
for (File f : files) { for (File f : files) {
String name = f.getName(); String name = f.getName();
if (name.endsWith(".poly")) { if (name.endsWith(".poly")) {

View file

@ -37,7 +37,7 @@ public class ProfileUploadHandler {
String id; String id;
if (profileId != null) { if (profileId != null) {
// update existing file when id appended // update existing file when id appended
id = profileId.substring(ProfileUploadHandler.CUSTOM_PREFIX.length()); id = profileId.substring(CUSTOM_PREFIX.length());
} else { } else {
id = "" + System.currentTimeMillis(); id = "" + System.currentTimeMillis();
} }

View file

@ -5,6 +5,7 @@ import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import btools.router.RoutingContext; import btools.router.RoutingContext;
import btools.server.request.ServerHandler; import btools.server.request.ServerHandler;
@ -13,7 +14,7 @@ public class RequestHandlerTest {
@Test @Test
@Ignore("Parameters are currently handled by RouteServer, not RequestHandler") @Ignore("Parameters are currently handled by RouteServer, not RequestHandler")
public void parseParameters() { public void parseParameters() {
HashMap<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("lonlats", "8.799297,49.565883|8.811764,49.563606"); params.put("lonlats", "8.799297,49.565883|8.811764,49.563606");
params.put("profile", "trekking"); params.put("profile", "trekking");
params.put("alternativeidx", "0"); params.put("alternativeidx", "0");

View file

@ -9,6 +9,7 @@ import java.util.List;
* *
* @author ab * @author ab
*/ */
@SuppressWarnings("PMD.LooseCoupling")
public class LazyArrayOfLists<E> { public class LazyArrayOfLists<E> {
private List<ArrayList<E>> lists; private List<ArrayList<E>> lists;

View file

@ -51,12 +51,12 @@ public class StackSampler extends Thread {
try { try {
int wait1 = rand.nextInt(interval); int wait1 = rand.nextInt(interval);
int wait2 = interval - wait1; int wait2 = interval - wait1;
Thread.sleep(wait1); sleep(wait1);
StringBuilder sb = new StringBuilder(df.format(new Date()) + " THREADDUMP\n"); StringBuilder sb = new StringBuilder(df.format(new Date()) + " THREADDUMP\n");
Map<Thread, StackTraceElement[]> allThreads = Thread.getAllStackTraces(); Map<Thread, StackTraceElement[]> allThreads = getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> e : allThreads.entrySet()) { for (Map.Entry<Thread, StackTraceElement[]> e : allThreads.entrySet()) {
Thread t = e.getKey(); Thread t = e.getKey();
if (t == Thread.currentThread()) { if (t == currentThread()) {
continue; // not me continue; // not me
} }
@ -76,7 +76,7 @@ public class StackSampler extends Thread {
flushCnt = 0; flushCnt = 0;
bw.flush(); bw.flush();
} }
Thread.sleep(wait2); sleep(wait2);
} catch (Exception e) { } catch (Exception e) {
// ignore // ignore
} }

View file

@ -4,6 +4,7 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import java.util.Random; import java.util.Random;
public class CompactMapTest { public class CompactMapTest {
@ -22,7 +23,7 @@ public class CompactMapTest {
private void hashMapComparison(int mapsize, int trycount) { private void hashMapComparison(int mapsize, int trycount) {
Random rand = new Random(12345); Random rand = new Random(12345);
HashMap<Long, String> hmap = new HashMap<>(); Map<Long, String> hmap = new HashMap<>();
CompactLongMap<String> cmap_slow = new CompactLongMap<>(); CompactLongMap<String> cmap_slow = new CompactLongMap<>();
CompactLongMap<String> cmap_fast = new CompactLongMap<>(); CompactLongMap<String> cmap_fast = new CompactLongMap<>();

View file

@ -5,6 +5,7 @@ import org.junit.Test;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Set;
public class CompactSetTest { public class CompactSetTest {
@Test @Test
@ -22,7 +23,7 @@ public class CompactSetTest {
private void hashSetComparison(int setsize, int trycount) { private void hashSetComparison(int setsize, int trycount) {
Random rand = new Random(12345); Random rand = new Random(12345);
HashSet<Long> hset = new HashSet<>(); Set<Long> hset = new HashSet<>();
CompactLongSet cset_slow = new CompactLongSet(); CompactLongSet cset_slow = new CompactLongSet();
CompactLongSet cset_fast = new CompactLongSet(); CompactLongSet cset_fast = new CompactLongSet();

View file

@ -5,7 +5,9 @@ import org.junit.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
public class DenseLongMapTest { public class DenseLongMapTest {
@Test @Test
@ -16,7 +18,7 @@ public class DenseLongMapTest {
private void hashMapComparison(int mapsize, int trycount, long keyrange) { private void hashMapComparison(int mapsize, int trycount, long keyrange) {
Random rand = new Random(12345); Random rand = new Random(12345);
HashMap<Long, Integer> hmap = new HashMap<>(); Map<Long, Integer> hmap = new HashMap<>();
DenseLongMap dmap = new DenseLongMap(512); DenseLongMap dmap = new DenseLongMap(512);
for (int i = 0; i < mapsize; i++) { for (int i = 0; i < mapsize; i++) {
@ -48,7 +50,7 @@ public class DenseLongMapTest {
int trycount = 100000; int trycount = 100000;
Random rand = new Random(12345); Random rand = new Random(12345);
HashSet<Long> hset = new HashSet<>(); Set<Long> hset = new HashSet<>();
DenseLongMap dmap = new DenseLongMap(512); DenseLongMap dmap = new DenseLongMap(512);
for (int i = 0; i < mapputs; i++) { for (int i = 0; i < mapputs; i++) {

View file

@ -29,6 +29,7 @@
<exclude name="OverrideBothEqualsAndHashcode" /> <exclude name="OverrideBothEqualsAndHashcode" />
<exclude name="PreserveStackTrace" /> <exclude name="PreserveStackTrace" />
<exclude name="ReturnEmptyCollectionRatherThanNull" /> <exclude name="ReturnEmptyCollectionRatherThanNull" />
<exclude name="SimplifyBooleanReturns" />
<exclude name="UncommentedEmptyConstructor" /> <exclude name="UncommentedEmptyConstructor" />
<exclude name="UncommentedEmptyMethodBody" /> <exclude name="UncommentedEmptyMethodBody" />
<exclude name="UnusedFormalParameter" /> <exclude name="UnusedFormalParameter" />
@ -45,18 +46,11 @@
<exclude name="FormalParameterNamingConventions" /> <exclude name="FormalParameterNamingConventions" />
<exclude name="LocalVariableNamingConventions" /> <exclude name="LocalVariableNamingConventions" />
<exclude name="MethodNamingConventions" /> <exclude name="MethodNamingConventions" />
<!-- Temporary -->
<exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal" />
<exclude name="LooseCoupling" />
<exclude name="SimplifyBooleanReturns" />
<exclude name="SingularField" />
<exclude name="UnnecessaryFullyQualifiedName" />
</rule> </rule>
<!-- Rules similar to Android Studio code inspection default settings --> <!-- Rules similar to Android Studio code inspection default settings -->
<!-- <rule ref="category/java/bestpractices.xml/UnusedAssignment" /> --> <!-- <rule ref="category/java/bestpractices.xml/UnusedAssignment" /> -->
<!-- <rule ref="category/java/codestyle.xml/UseDiamondOperator" /> --> <rule ref="category/java/codestyle.xml/UseDiamondOperator" />
<!-- <rule ref="category/java/design.xml/ImmutableField" /> --> <!-- <rule ref="category/java/design.xml/ImmutableField" /> -->
<!-- Will be added in PMD 7 --> <!-- Will be added in PMD 7 -->
<!-- <rule ref="category/java/codestyle.xml/UnnecessaryBoxing" /> --> <!-- <rule ref="category/java/codestyle.xml/UnnecessaryBoxing" /> -->