Merge pull request #550 from zod/pmd-fixes

@zod 
Ok, I didn't control that.

More PMD rules & fixes
This commit is contained in:
afischerdev 2023-05-15 17:19:12 +02:00 committed by GitHub
commit 8bf0125fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 130 additions and 124 deletions

View file

@ -287,9 +287,9 @@ public final class MicroCache2 extends MicroCache {
@Override
public int encodeMicroCache(byte[] buffer) {
HashMap<Long, Integer> idMap = new HashMap<Long, Integer>();
HashMap<Long, Integer> idMap = new HashMap<>();
for (int n = 0; n < size; n++) { // loop over nodes
idMap.put(Long.valueOf(expandId(faid[n])), Integer.valueOf(n));
idMap.put(expandId(faid[n]), n);
}
IntegerFifo3Pass linkCounts = new IntegerFifo3Pass(256);
@ -404,7 +404,7 @@ public final class MicroCache2 extends MicroCache {
}
long link64 = ((long) ilonlink) << 32 | ilatlink;
Integer idx = idMap.get(Long.valueOf(link64));
Integer idx = idMap.get(link64);
boolean isInternal = idx != null;
if (isReverse && isInternal) {

View file

@ -39,7 +39,7 @@ public final class StatCoderContext extends BitCoderContext {
public void assignBits(String name) {
long bitpos = getWritingBitPosition();
if (statsPerName == null) {
statsPerName = new TreeMap<String, long[]>();
statsPerName = new TreeMap<>();
}
long[] stats = statsPerName.get(name);
if (stats == null) {

View file

@ -58,7 +58,7 @@ public final class TagValueCoder {
TagValueSet dummy = new TagValueSet(nextTagValueSetId++);
identityMap.put(dummy, dummy);
}
PriorityQueue<TagValueSet> queue = new PriorityQueue<TagValueSet>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
PriorityQueue<TagValueSet> queue = new PriorityQueue<>(2 * identityMap.size(), new TagValueSet.FrequencyComparator());
queue.addAll(identityMap.values());
while (queue.size() > 1) {
TagValueSet node = new TagValueSet(nextTagValueSetId++);
@ -79,7 +79,7 @@ public final class TagValueCoder {
}
public TagValueCoder() {
identityMap = new HashMap<TagValueSet, TagValueSet>();
identityMap = new HashMap<>();
}
private Object decodeTree(BitCoderContext bc, DataBuffers buffers, TagValueValidator validator) {

View file

@ -24,7 +24,7 @@ public class OsmNogoPolygon extends OsmNodeNamed {
}
}
public final List<Point> points = new ArrayList<Point>();
public final List<Point> points = new ArrayList<>();
public final boolean isClosed;

View file

@ -53,14 +53,14 @@ public final class OsmTrack {
public Map<String, String> params;
public List<OsmNodeNamed> pois = new ArrayList<OsmNodeNamed>();
public List<OsmNodeNamed> pois = new ArrayList<>();
public static class OsmPathElementHolder {
public OsmPathElement node;
public OsmPathElementHolder nextHolder;
}
public List<OsmPathElement> nodes = new ArrayList<OsmPathElement>();
public List<OsmPathElement> nodes = new ArrayList<>();
private CompactLongMap<OsmPathElementHolder> nodesMap;
@ -82,7 +82,7 @@ public final class OsmTrack {
public void registerDetourForId(long id, OsmPathElement detour) {
if (detourMap == null) {
detourMap = new CompactLongMap<OsmPathElementHolder>();
detourMap = new CompactLongMap<>();
}
OsmPathElementHolder nh = new OsmPathElementHolder();
nh.node = detour;
@ -98,12 +98,12 @@ public final class OsmTrack {
}
public void copyDetours(OsmTrack source) {
detourMap = source.detourMap == null ? null : new FrozenLongMap<OsmPathElementHolder>(source.detourMap);
detourMap = source.detourMap == null ? null : new FrozenLongMap<>(source.detourMap);
}
public void addDetours(OsmTrack source) {
if (detourMap != null) {
CompactLongMap<OsmPathElementHolder> tmpDetourMap = new CompactLongMap<OsmPathElementHolder>();
CompactLongMap<OsmPathElementHolder> tmpDetourMap = new CompactLongMap<>();
List oldlist = ((FrozenLongMap) detourMap).getValueList();
long[] oldidlist = ((FrozenLongMap) detourMap).getKeyArray();
@ -124,7 +124,7 @@ public final class OsmTrack {
}
}
}
detourMap = new FrozenLongMap<OsmPathElementHolder>(tmpDetourMap);
detourMap = new FrozenLongMap<>(tmpDetourMap);
}
}
@ -132,7 +132,7 @@ public final class OsmTrack {
public void appendDetours(OsmTrack source) {
if (detourMap == null) {
detourMap = source.detourMap == null ? null : new CompactLongMap<OsmPathElementHolder>();
detourMap = source.detourMap == null ? null : new CompactLongMap<>();
}
if (source.detourMap != null) {
int pos = nodes.size() - source.nodes.size() + 1;
@ -160,7 +160,7 @@ public final class OsmTrack {
}
public void buildMap() {
nodesMap = new CompactLongMap<OsmPathElementHolder>();
nodesMap = new CompactLongMap<>();
for (OsmPathElement node : nodes) {
long id = node.getIdFromPos();
OsmPathElementHolder nh = new OsmPathElementHolder();
@ -175,11 +175,11 @@ public final class OsmTrack {
nodesMap.fastPut(id, nh);
}
}
nodesMap = new FrozenLongMap<OsmPathElementHolder>(nodesMap);
nodesMap = new FrozenLongMap<>(nodesMap);
}
private List<String> aggregateMessages() {
ArrayList<String> res = new ArrayList<String>();
ArrayList<String> res = new ArrayList<>();
MessageData current = null;
for (OsmPathElement n : nodes) {
if (n.message != null && n.message.wayKeyValues != null) {
@ -201,7 +201,7 @@ public final class OsmTrack {
}
private List<String> aggregateSpeedProfile() {
ArrayList<String> res = new ArrayList<String>();
ArrayList<String> res = new ArrayList<>();
int vmax = -1;
int vmaxe = -1;
int vmin = -1;
@ -1289,7 +1289,7 @@ public final class OsmTrack {
i = 0;
node = nodes.get(nodeNr);
List<VoiceHint> inputs = new ArrayList<VoiceHint>();
List<VoiceHint> inputs = new ArrayList<>();
while (node != null) {
if (node.origin != null) {
VoiceHint input = new VoiceHint();

View file

@ -274,7 +274,7 @@ public final class RoutingContext {
public void cleanNogoList(List<OsmNode> waypoints) {
nogopoints_all = nogopoints;
if (nogopoints == null) return;
List<OsmNodeNamed> nogos = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> nogos = new ArrayList<>();
for (OsmNodeNamed nogo : nogopoints) {
boolean goodGuy = true;
for (OsmNode wp : waypoints) {
@ -386,7 +386,7 @@ public final class RoutingContext {
public void setWaypoint(OsmNodeNamed wp, OsmNodeNamed pendingEndpoint, boolean endpoint) {
keepnogopoints = nogopoints;
nogopoints = new ArrayList<OsmNodeNamed>();
nogopoints = new ArrayList<>();
nogopoints.add(wp);
if (keepnogopoints != null) nogopoints.addAll(keepnogopoints);
isEndpoint = endpoint;

View file

@ -26,7 +26,7 @@ import btools.util.StackSampler;
public class RoutingEngine extends Thread {
private NodesCache nodesCache;
private SortedHeap<OsmPath> openSet = new SortedHeap<OsmPath>();
private SortedHeap<OsmPath> openSet = new SortedHeap<>();
private boolean finished = false;
protected List<OsmNodeNamed> waypoints = null;
@ -146,7 +146,7 @@ public class RoutingEngine extends Thread {
OsmTrack[] refTracks = new OsmTrack[nsections]; // used ways for alternatives
OsmTrack[] lastTracks = new OsmTrack[nsections];
OsmTrack track = null;
ArrayList<String> messageList = new ArrayList<String>();
ArrayList<String> messageList = new ArrayList<>();
for (int i = 0; ; i++) {
track = findTrack(refTracks, lastTracks);
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
@ -362,7 +362,7 @@ public class RoutingEngine extends Thread {
try {
MatchedWaypoint seedPoint = new MatchedWaypoint();
seedPoint.waypoint = waypoints.get(0);
List<MatchedWaypoint> listOne = new ArrayList<MatchedWaypoint>();
List<MatchedWaypoint> listOne = new ArrayList<>();
listOne.add(seedPoint);
matchWaypointsToNodes(listOne);
@ -437,7 +437,7 @@ public class RoutingEngine extends Thread {
}
if (matchedWaypoints == null) { // could exist from the previous alternative level
matchedWaypoints = new ArrayList<MatchedWaypoint>();
matchedWaypoints = new ArrayList<>();
for (int i = 0; i < nUnmatched; i++) {
MatchedWaypoint mwp = new MatchedWaypoint();
mwp.waypoint = waypoints.get(i);
@ -993,7 +993,7 @@ public class RoutingEngine extends Thread {
private OsmTrack findTrack(String operationName, MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack costCuttingTrack, OsmTrack refTrack, boolean fastPartialRecalc) {
try {
List<OsmNode> wpts2 = new ArrayList<OsmNode>();
List<OsmNode> wpts2 = new ArrayList<>();
if (startWp != null) wpts2.add(startWp.waypoint);
if (endWp != null) wpts2.add(endWp.waypoint);
routingContext.cleanNogoList(wpts2);
@ -1086,7 +1086,7 @@ public class RoutingEngine extends Thread {
addToOpenset(startPath1);
addToOpenset(startPath2);
}
ArrayList<OsmPath> openBorderList = new ArrayList<OsmPath>(4096);
ArrayList<OsmPath> openBorderList = new ArrayList<>(4096);
boolean memoryPanicMode = false;
boolean needNonPanicProcessing = false;

View file

@ -17,7 +17,7 @@ public class SuspectInfo {
public int triggers;
public static void addSuspect(Map<Long, SuspectInfo> map, long id, int prio, int trigger) {
Long iD = Long.valueOf(id);
Long iD = id;
SuspectInfo info = map.get(iD);
if (info == null) {
info = new SuspectInfo();

View file

@ -56,7 +56,7 @@ public class VoiceHint {
return;
}
if (badWays == null) {
badWays = new ArrayList<MessageData>();
badWays = new ArrayList<>();
}
badWays.add(badWay);
}

View file

@ -12,7 +12,7 @@ import java.util.List;
public class VoiceHintList {
private String transportMode;
int turnInstructionMode;
List<VoiceHint> list = new ArrayList<VoiceHint>();
List<VoiceHint> list = new ArrayList<>();
public void setTransportMode(boolean isCar, boolean isBike) {
transportMode = isCar ? "car" : (isBike ? "bike" : "foot");

View file

@ -55,7 +55,7 @@ public final class VoiceHintProcessor {
* @return voice hints, in forward order
*/
public List<VoiceHint> process(List<VoiceHint> inputs) {
List<VoiceHint> results = new ArrayList<VoiceHint>();
List<VoiceHint> results = new ArrayList<>();
double distance = 0.;
float roundAboutTurnAngle = 0.f; // sums up angles in roundabout
@ -202,7 +202,7 @@ public final class VoiceHintProcessor {
// go through the hint list again in reverse order (=travel direction)
// and filter out non-significant hints and hints too close to its predecessor
List<VoiceHint> results2 = new ArrayList<VoiceHint>();
List<VoiceHint> results2 = new ArrayList<>();
int i = results.size();
while (i > 0) {
VoiceHint hint = results.get(--i);
@ -241,7 +241,7 @@ public final class VoiceHintProcessor {
}
public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange, double minRange) {
List<VoiceHint> results = new ArrayList<VoiceHint>();
List<VoiceHint> results = new ArrayList<>();
double distance = 0;
VoiceHint inputLast = null;
ArrayList<VoiceHint> tmpList = new ArrayList<>();

View file

@ -36,10 +36,10 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public String _modelClass;
private Map<String, Integer> lookupNumbers = new HashMap<String, Integer>();
private List<BExpressionLookupValue[]> lookupValues = new ArrayList<BExpressionLookupValue[]>();
private List<String> lookupNames = new ArrayList<String>();
private List<int[]> lookupHistograms = new ArrayList<int[]>();
private Map<String, Integer> lookupNumbers = new HashMap<>();
private List<BExpressionLookupValue[]> lookupValues = new ArrayList<>();
private List<String> lookupNames = new ArrayList<>();
private List<int[]> lookupHistograms = new ArrayList<>();
private boolean[] lookupIdxUsed;
private boolean lookupDataFrozen = false;
@ -50,7 +50,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
private BitCoderContext ctxEndode = new BitCoderContext(abBuf);
private BitCoderContext ctxDecode = new BitCoderContext(new byte[0]);
private Map<String, Integer> variableNumbers = new HashMap<String, Integer>();
private Map<String, Integer> variableNumbers = new HashMap<>();
private float[] variableData;
@ -223,7 +223,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
public List<String> getKeyValueList(boolean inverseDirection, byte[] ab) {
ArrayList<String> res = new ArrayList<String>();
ArrayList<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);
@ -429,7 +429,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
public void dumpStatistics() {
TreeMap<String, String> counts = new TreeMap<String, String>();
TreeMap<String, String> counts = new TreeMap<>();
// first count
for (String name : lookupNumbers.keySet()) {
int cnt = 0;
@ -528,7 +528,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
}
// unknown name, create
num = Integer.valueOf(lookupValues.size());
num = lookupValues.size();
lookupNumbers.put(name, num);
lookupNames.add(name);
lookupValues.add(new BExpressionLookupValue[]{new BExpressionLookupValue("")
@ -815,7 +815,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
private List<BExpression> _parseFile(File file) throws Exception {
_br = new BufferedReader(new FileReader(file));
_readerDone = false;
List<BExpression> result = new ArrayList<BExpression>();
List<BExpression> result = new ArrayList<>();
for (; ; ) {
BExpression exp = BExpression.parse(this, 0);
if (exp == null) break;
@ -855,7 +855,7 @@ public abstract class BExpressionContext implements IByteArrayUnifier {
Integer num = variableNumbers.get(name);
if (num == null) {
if (create) {
num = Integer.valueOf(variableNumbers.size());
num = variableNumbers.size();
variableNumbers.put(name, num);
} else {
return -1;

View file

@ -26,7 +26,7 @@ final class BExpressionLookupValue {
}
public void addAlias(String alias) {
if (aliases == null) aliases = new ArrayList<String>();
if (aliases == null) aliases = new ArrayList<>();
aliases.add(alias);
}

View file

@ -24,7 +24,7 @@ public final class BExpressionMetaData {
public short lookupMinorVersion = -1;
public short minAppVersion = -1;
private Map<String, BExpressionContext> listeners = new HashMap<String, BExpressionContext>();
private Map<String, BExpressionContext> listeners = new HashMap<>();
public void registerListener(String context, BExpressionContext ctx) {
listeners.put(context, ctx);

View file

@ -25,7 +25,7 @@ public abstract class MapCreatorBase implements WayListener, NodeListener, Relat
protected Map<String, String> tags;
public void putTag(String key, String value) {
if (tags == null) tags = new HashMap<String, String>();
if (tags == null) tags = new HashMap<>();
tags.put(key, value);
}

View file

@ -105,7 +105,7 @@ public class OsmNodeP extends OsmLinkP {
}
public void checkDuplicateTargets() {
HashMap<OsmNodeP, OsmLinkP> targets = new HashMap<OsmNodeP, OsmLinkP>();
HashMap<OsmNodeP, OsmLinkP> targets = new HashMap<>();
for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) {
OsmLinkP link = link0;
@ -165,14 +165,14 @@ public class OsmNodeP extends OsmLinkP {
mc.writeVarBytes(getNodeDecsription());
// buffer internal reverse links
ArrayList<OsmNodeP> internalReverse = new ArrayList<OsmNodeP>();
ArrayList<OsmNodeP> internalReverse = new ArrayList<>();
for (OsmLinkP link0 = getFirstLink(); link0 != null; link0 = link0.getNext(this)) {
OsmLinkP link = link0;
OsmNodeP origin = this;
OsmNodeP target = null;
ArrayList<OsmNodeP> linkNodes = new ArrayList<OsmNodeP>();
ArrayList<OsmNodeP> linkNodes = new ArrayList<>();
linkNodes.add(this);
// first pass just to see if that link is consistent

View file

@ -52,7 +52,7 @@ public class OsmTrafficMap {
public OsmTrafficElement next;
}
private CompactLongMap<OsmTrafficElement> map = new CompactLongMap<OsmTrafficElement>();
private CompactLongMap<OsmTrafficElement> map = new CompactLongMap<>();
public void loadAll(File file, int minLon, int minLat, int maxLon, int maxLat, boolean includeMotorways) throws Exception {
load(file, minLon, minLat, maxLon, maxLat, includeMotorways);
@ -107,7 +107,7 @@ public class OsmTrafficMap {
is.close();
}
map = new FrozenLongMap<OsmTrafficElement>(map);
map = new FrozenLongMap<>(map);
System.out.println("read traffic-elements: " + trafficElements);
}

View file

@ -53,7 +53,7 @@ public class RelationMerger extends MapCreatorBase {
// expctxStat = new BExpressionContext("way");
// *** read the relation file into sets for each processed tag
routesets = new HashMap<String, CompactLongSet>();
routesets = new HashMap<>();
routesetall = new CompactLongSet();
DataInputStream dis = createInStream(relationFileIn);
try {
@ -130,7 +130,7 @@ public class RelationMerger extends MapCreatorBase {
if (routeset.contains(data.wid)) {
int sepIdx = key.lastIndexOf('_');
String tagname = key.substring(0, sepIdx);
int val = Integer.valueOf(key.substring(sepIdx + 1));
int val = Integer.parseInt(key.substring(sepIdx + 1));
expctxReport.addSmallestLookupValue(tagname, val);
}
}

View file

@ -25,7 +25,7 @@ public class RelationStatistics extends MapCreatorBase {
}
public void process(File relationFileIn) throws Exception {
HashMap<String, long[]> relstats = new HashMap<String, long[]>();
HashMap<String, long[]> relstats = new HashMap<>();
DataInputStream dis = createInStream(relationFileIn);
try {

View file

@ -108,7 +108,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
private void reset() {
minLon = -1;
minLat = -1;
nodesMap = new CompactLongMap<OsmNodeP>();
nodesMap = new CompactLongMap<>();
borderSet = new CompactLongSet();
}
@ -231,7 +231,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
new NodeIterator(this, true).processFile(nodeFile);
// freeze the nodes-map
FrozenLongMap<OsmNodeP> nodesMapFrozen = new FrozenLongMap<OsmNodeP>(nodesMap);
FrozenLongMap<OsmNodeP> nodesMapFrozen = new FrozenLongMap<>(nodesMap);
nodesMap = nodesMapFrozen;
File restrictionFile = fileFromTemplate(wayfile, new File(nodeTilesIn.getParentFile(), "restrictions55"), "rt5");
@ -415,7 +415,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
int nLatSegs = (maxLat - minLat) / 1000000;
// sort the nodes into segments
LazyArrayOfLists<OsmNodeP> seglists = new LazyArrayOfLists<OsmNodeP>(nLonSegs * nLatSegs);
LazyArrayOfLists<OsmNodeP> seglists = new LazyArrayOfLists<>(nLonSegs * nLatSegs);
for (OsmNodeP n : nodesList) {
if (n == null || n.getFirstLink() == null || n.isTransferNode())
continue;
@ -450,7 +450,7 @@ public class WayLinker extends MapCreatorBase implements Runnable {
if (seglists.getSize(tileIndex) > 0) {
List<OsmNodeP> nlist = seglists.getList(tileIndex);
LazyArrayOfLists<OsmNodeP> subs = new LazyArrayOfLists<OsmNodeP>(ncaches);
LazyArrayOfLists<OsmNodeP> subs = new LazyArrayOfLists<>(ncaches);
byte[][] subByteArrays = new byte[ncaches][];
for (int ni = 0; ni < nlist.size(); ni++) {
OsmNodeP n = nlist.get(ni);
@ -473,14 +473,14 @@ public class WayLinker extends MapCreatorBase implements Runnable {
MicroCache mc = new MicroCache2(size, abBuf2, lonIdxDiv, latIdxDiv, divisor);
// sort via treemap
TreeMap<Integer, OsmNodeP> sortedList = new TreeMap<Integer, OsmNodeP>();
TreeMap<Integer, OsmNodeP> sortedList = new TreeMap<>();
for (OsmNodeP n : subList) {
long longId = n.getIdFromPos();
int shrinkid = mc.shrinkId(longId);
if (mc.expandId(shrinkid) != longId) {
throw new IllegalArgumentException("inconstistent shrinking: " + longId);
}
sortedList.put(Integer.valueOf(shrinkid), n);
sortedList.put(shrinkid, n);
}
for (OsmNodeP n : sortedList.values()) {

View file

@ -95,7 +95,7 @@ public final class NodesCache {
fileRows = new OsmFile[180][];
}
} else {
fileCache = new HashMap<String, PhysicalFile>(4);
fileCache = new HashMap<>(4);
fileRows = new OsmFile[180][];
dataBuffers = new DataBuffers();
secondarySegmentsDir = StorageConfigHelper.getSecondarySegmentDir(segmentDir);

View file

@ -50,7 +50,7 @@ public class OsmNodePairSet {
private void addPair(long n1, long n2) {
if (map == null) {
map = new CompactLongMap<OsmNodePair>();
map = new CompactLongMap<>();
}
npairs++;

View file

@ -13,7 +13,7 @@ import java.util.Map;
import btools.util.ByteArrayUnifier;
public final class OsmNodesMap {
private Map<OsmNode, OsmNode> hmap = new HashMap<OsmNode, OsmNode>(4096);
private Map<OsmNode, OsmNode> hmap = new HashMap<>(4096);
private ByteArrayUnifier abUnifier = new ByteArrayUnifier(16384, false);
@ -176,7 +176,7 @@ public final class OsmNodesMap {
}
public void collectOutreachers() {
nodes2check = new ArrayList<OsmNode>(nodesCreated);
nodes2check = new ArrayList<>(nodesCreated);
nodesCreated = 0;
for (OsmNode n : hmap.values()) {
addActiveNode(nodes2check, n);

View file

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

View file

@ -488,11 +488,11 @@ public class BInstallerActivity extends AppCompatActivity {
}
private void downloadDiffVersionTiles() {
downloadAll(new ArrayList<Integer>(), DownloadWorker.VALUE_SEGMENT_DIFFS);
downloadAll(new ArrayList<>(), DownloadWorker.VALUE_SEGMENT_DIFFS);
}
private void dropDiffVersionTiles() {
downloadAll(new ArrayList<Integer>(), DownloadWorker.VALUE_SEGMENT_DROPDIFFS);
downloadAll(new ArrayList<>(), DownloadWorker.VALUE_SEGMENT_DROPDIFFS);
}
private boolean isDownloadRunning(Class<?> serviceClass) {

View file

@ -199,8 +199,8 @@ public class BRouterService extends Service {
private void readNogos(BRouterWorker worker, String baseDir) throws Exception {
// add nogos from waypoint database
CoordinateReader cor = CoordinateReader.obtainValidReader(baseDir, true);
worker.nogoList = new ArrayList<OsmNodeNamed>(cor.nogopoints);
worker.nogoPolygonsList = new ArrayList<OsmNodeNamed>();
worker.nogoList = new ArrayList<>(cor.nogopoints);
worker.nogoPolygonsList = new ArrayList<>();
}
private boolean fileEqual(byte[] fileBytes, File file) throws Exception {

View file

@ -107,7 +107,7 @@ public class BRouterWorker {
String straight = params.getString("straight");
String[] sa = straight.split(",");
for (int i = 0; i < sa.length; i++) {
int v = Integer.valueOf(sa[i]);
int v = Integer.parseInt(sa[i]);
if (waypoints.size() > v) waypoints.get(v).direct = true;
}
} catch (NumberFormatException e) {
@ -126,7 +126,7 @@ public class BRouterWorker {
}
if (params.containsKey("extraParams")) { // add user params
if (rc.keyValues == null) rc.keyValues = new HashMap<String, String>();
if (rc.keyValues == null) rc.keyValues = new HashMap<>();
StringTokenizer tk = new StringTokenizer(extraParams, "?&");
while (tk.hasMoreTokens()) {
String t = tk.nextToken();
@ -212,7 +212,7 @@ public class BRouterWorker {
}
private List<OsmNodeNamed> readPositions(Bundle params) {
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> wplist = new ArrayList<>();
double[] lats = params.getDoubleArray("lats");
double[] lons = params.getDoubleArray("lons");
@ -235,7 +235,7 @@ public class BRouterWorker {
}
private List<OsmNodeNamed> readLonlats(Bundle params) {
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> wplist = new ArrayList<>();
String lonLats = params.getString("lonlats");
if (lonLats == null) throw new IllegalArgumentException("lonlats parameter not set");
@ -315,7 +315,7 @@ public class BRouterWorker {
String[] lonLatRadList = nogos.split("\\|");
List<OsmNodeNamed> nogoList = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> nogoList = new ArrayList<>();
for (int i = 0; i < lonLatRadList.length; i++) {
String[] lonLatRad = lonLatRadList[i].split(",");
String nogoWeight = "NaN";
@ -344,7 +344,7 @@ public class BRouterWorker {
}
private List<OsmNodeNamed> readNogoPolygons(Bundle params) {
List<OsmNodeNamed> result = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> result = new ArrayList<>();
parseNogoPolygons(params.getString("polylines"), result, false);
parseNogoPolygons(params.getString("polygons"), result, true);
return result.size() > 0 ? result : null;
@ -389,7 +389,7 @@ public class BRouterWorker {
String[] lonLatNameList = pois.split("\\|");
List<OsmNodeNamed> poisList = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> poisList = new ArrayList<>();
for (int i = 0; i < lonLatNameList.length; i++) {
String[] lonLatName = lonLatNameList[i].split(",");

View file

@ -33,7 +33,7 @@ public class ConfigMigration {
}
br.close();
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
br = new BufferedReader(new FileReader(dstFile));
for (; ; ) {
String line = br.readLine();
@ -76,7 +76,7 @@ public class ConfigMigration {
BufferedReader br = null;
BufferedWriter bw = null;
File configFile = new File(segmentDir, "storageconfig.txt");
List<String> lines = new ArrayList<String>();
List<String> lines = new ArrayList<>();
try {
br = new BufferedReader(new FileReader(configFile));
for (; ; ) {

View file

@ -19,7 +19,7 @@ public class ServiceModeConfig {
profile = tk.nextToken();
if (tk.hasMoreTokens()) params = tk.nextToken();
else params = "noparams";
nogoVetos = new TreeSet<String>();
nogoVetos = new TreeSet<>();
while (tk.hasMoreTokens()) {
nogoVetos.add(tk.nextToken());
}
@ -29,7 +29,7 @@ public class ServiceModeConfig {
this.mode = mode;
this.profile = profile;
this.params = params;
nogoVetos = new TreeSet<String>();
nogoVetos = new TreeSet<>();
}
public String toLine() {

View file

@ -8,8 +8,8 @@ import java.util.ArrayList;
import java.util.List;
public class Area {
private List<Polygon> poslist = new ArrayList<Polygon>();
private List<Polygon> neglist = new ArrayList<Polygon>();
private List<Polygon> poslist = new ArrayList<>();
private List<Polygon> neglist = new ArrayList<>();
public static void main(String[] args) throws IOException {
Area a = new Area(new File(args[0]));

View file

@ -63,7 +63,7 @@ public class BRouter {
maxRunningTime = Integer.parseInt(sMaxRunningTime) * 1000;
}
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> wplist = new ArrayList<>();
wplist.add(from);
wplist.add(to);
@ -83,7 +83,7 @@ public class BRouter {
System.out.println("usage: java -jar brouter.jar <segmentdir> <lon-from> <lat-from> <lon-to> <lat-to> <profile>");
return;
}
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> wplist = new ArrayList<>();
wplist.add(readPosition(args, 1, "from"));
RoutingEngine re = null;
if ("seed".equals(args[3])) {

View file

@ -5,7 +5,7 @@ import java.util.Map;
public class IpAccessMonitor {
private static Object sync = new Object();
private static Map<String, Long> ipAccess = new HashMap<String, Long>();
private static Map<String, Long> ipAccess = new HashMap<>();
private static long MAX_IDLE = 900000; // 15 minutes
private static long CLEANUP_INTERVAL = 10000; // 10 seconds
private static long lastCleanup;
@ -14,7 +14,7 @@ public class IpAccessMonitor {
long t = System.currentTimeMillis();
synchronized (sync) {
Long lastTime = ipAccess.get(ip);
ipAccess.put(ip, Long.valueOf(t));
ipAccess.put(ip, t);
return lastTime == null || t - lastTime.longValue() > MAX_IDLE;
}
}
@ -31,7 +31,7 @@ public class IpAccessMonitor {
}
private static void cleanup(long t) {
HashMap<String, Long> newMap = new HashMap<String, Long>(ipAccess.size());
HashMap<String, Long> newMap = new HashMap<>(ipAccess.size());
for (Map.Entry<String, Long> e : ipAccess.entrySet()) {
if (t - e.getValue().longValue() <= MAX_IDLE) {
newMap.put(e.getKey(), e.getValue());

View file

@ -15,7 +15,7 @@ public class Polygon {
private int maxy = Integer.MIN_VALUE;
public Polygon(BufferedReader br) throws IOException {
ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> lines = new ArrayList<>();
for (; ; ) {
String line = br.readLine();

View file

@ -195,17 +195,17 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
if ("timode".equals(e.getKey())) {
rc.turnInstructionMode = Integer.parseInt(e.getValue());
} else if ("heading".equals(e.getKey())) {
rc.startDirection = Integer.valueOf(Integer.parseInt(e.getValue()));
rc.startDirection = Integer.parseInt(e.getValue());
rc.forceUseStartDirection = true;
} else if (e.getKey().startsWith("profile:")) {
if (rc.keyValues == null) {
rc.keyValues = new HashMap<String, String>();
rc.keyValues = new HashMap<>();
}
rc.keyValues.put(e.getKey().substring(8), e.getValue());
} else if (e.getKey().equals("straight")) {
String[] sa = e.getValue().split(",");
for (int i = 0; i < sa.length; i++) {
int v = Integer.valueOf(sa[i]);
int v = Integer.parseInt(sa[i]);
if (wplist.size() > v) wplist.get(v).direct = true;
}
}
@ -294,7 +294,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
ProfileCache.setSize(2 * maxthreads);
PriorityQueue<RouteServer> threadQueue = new PriorityQueue<RouteServer>();
PriorityQueue<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]));
@ -359,7 +359,7 @@ public class RouteServer extends Thread implements Comparable<RouteServer> {
private static Map<String, String> getUrlParams(String url) throws UnsupportedEncodingException {
HashMap<String, String> params = new HashMap<String, String>();
HashMap<String, String> params = new HashMap<>();
String decoded = URLDecoder.decode(url, "UTF-8");
StringTokenizer tk = new StringTokenizer(decoded, "?&");
while (tk.hasMoreTokens()) {

View file

@ -244,7 +244,7 @@ public class SuspectManager extends Thread {
bw.write("<table>\n");
File countryParent = new File("worldpolys" + country);
File[] files = countryParent.listFiles();
TreeSet<String> names = new TreeSet<String>();
TreeSet<String> names = new TreeSet<>();
for (File f : files) {
String name = f.getName();
if (name.endsWith(".poly")) {
@ -580,7 +580,7 @@ public class SuspectManager extends Thread {
}
}
private static Map<String, SuspectList> allSuspectsMap = new HashMap<String, SuspectList>();
private static Map<String, SuspectList> allSuspectsMap = new HashMap<>();
private static SuspectList getDailySuspectsIfLoaded() throws IOException {
synchronized (allSuspectsMap) {

View file

@ -51,7 +51,7 @@ public class ProfileUploadHandler {
fileWriter.flush();
//System.out.println("data: |" + sw.toString() + "|");
Map<String, String> responseData = new HashMap<String, String>();
Map<String, String> responseData = new HashMap<>();
responseData.put("profileid", CUSTOM_PREFIX + id);
validateProfile(id, responseData);

View file

@ -94,7 +94,7 @@ public class ServerHandler extends RequestHandler {
if (coords.length < 2)
throw new IllegalArgumentException("we need two lat/lon points at least!");
List<OsmNodeNamed> wplist = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> wplist = new ArrayList<>();
for (int i = 0; i < coords.length; i++) {
String[] lonLat = coords[i].split(",");
if (lonLat.length < 2)
@ -213,7 +213,7 @@ public class ServerHandler extends RequestHandler {
String[] lonLatNameList = pois.split("\\|");
List<OsmNodeNamed> poisList = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> poisList = new ArrayList<>();
for (int i = 0; i < lonLatNameList.length; i++) {
String[] lonLatName = lonLatNameList[i].split(",");
@ -237,7 +237,7 @@ public class ServerHandler extends RequestHandler {
String[] lonLatRadList = nogos.split("\\|");
List<OsmNodeNamed> nogoList = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> nogoList = new ArrayList<>();
for (int i = 0; i < lonLatRadList.length; i++) {
String[] lonLatRad = lonLatRadList[i].split(",");
String nogoWeight = "NaN";
@ -266,7 +266,7 @@ public class ServerHandler extends RequestHandler {
}
private List<OsmNodeNamed> readNogoPolygons() {
List<OsmNodeNamed> result = new ArrayList<OsmNodeNamed>();
List<OsmNodeNamed> result = new ArrayList<>();
parseNogoPolygons(params.get("polylines"), result, false);
parseNogoPolygons(params.get("polygons"), result, true);
return result.size() > 0 ? result : null;

View file

@ -17,7 +17,7 @@ import java.util.List;
* @author ab
*/
public class DenseLongMap {
private List<byte[]> blocklist = new ArrayList<byte[]>(4096);
private List<byte[]> blocklist = new ArrayList<>(4096);
private int blocksize; // bytes per bitplane in one block
private int blocksizeBits;

View file

@ -20,7 +20,7 @@ public class FrozenLongMap<V> extends CompactLongMap<V> {
size = map.size();
faid = new long[size];
flv = new ArrayList<V>(size);
flv = new ArrayList<>(size);
map.moveToFrozenArrays(faid, flv);

View file

@ -13,7 +13,7 @@ public class LazyArrayOfLists<E> {
private List<ArrayList<E>> lists;
public LazyArrayOfLists(int size) {
lists = new ArrayList<ArrayList<E>>(size);
lists = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
lists.add(null);
}
@ -22,7 +22,7 @@ public class LazyArrayOfLists<E> {
public List<E> getList(int idx) {
ArrayList<E> list = lists.get(idx);
if (list == null) {
list = new ArrayList<E>();
list = new ArrayList<>();
lists.set(idx, list);
}
return list;

View file

@ -22,14 +22,14 @@ public class CompactMapTest {
private void hashMapComparison(int mapsize, int trycount) {
Random rand = new Random(12345);
HashMap<Long, String> hmap = new HashMap<Long, String>();
CompactLongMap<String> cmap_slow = new CompactLongMap<String>();
CompactLongMap<String> cmap_fast = new CompactLongMap<String>();
HashMap<Long, String> hmap = new HashMap<>();
CompactLongMap<String> cmap_slow = new CompactLongMap<>();
CompactLongMap<String> cmap_fast = new CompactLongMap<>();
for (int i = 0; i < mapsize; i++) {
String s = "" + i;
long k = mapsize < 10 ? i : rand.nextInt(20000);
Long KK = new Long(k);
Long KK = k;
if (!hmap.containsKey(KK)) {
hmap.put(KK, s);
@ -40,11 +40,11 @@ public class CompactMapTest {
for (int i = 0; i < trycount * 2; i++) {
if (i == trycount) {
cmap_slow = new FrozenLongMap<String>(cmap_slow);
cmap_fast = new FrozenLongMap<String>(cmap_fast);
cmap_slow = new FrozenLongMap<>(cmap_slow);
cmap_fast = new FrozenLongMap<>(cmap_fast);
}
long k = mapsize < 10 ? i : rand.nextInt(20000);
Long KK = new Long(k);
Long KK = k;
String s = hmap.get(KK);
boolean contained = hmap.containsKey(KK);

View file

@ -22,13 +22,13 @@ public class CompactSetTest {
private void hashSetComparison(int setsize, int trycount) {
Random rand = new Random(12345);
HashSet<Long> hset = new HashSet<Long>();
HashSet<Long> hset = new HashSet<>();
CompactLongSet cset_slow = new CompactLongSet();
CompactLongSet cset_fast = new CompactLongSet();
for (int i = 0; i < setsize; i++) {
long k = setsize < 10 ? i : rand.nextInt(20000);
Long KK = new Long(k);
Long KK = k;
if (!hset.contains(KK)) {
hset.add(KK);
@ -43,7 +43,7 @@ public class CompactSetTest {
cset_fast = new FrozenLongSet(cset_fast);
}
long k = setsize < 10 ? i : rand.nextInt(20000);
Long KK = new Long(k);
Long KK = k;
boolean contained = hset.contains(KK);
Assert.assertEquals("contains missmatch (slow)", contained, cset_slow.contains(k));

View file

@ -16,21 +16,21 @@ public class DenseLongMapTest {
private void hashMapComparison(int mapsize, int trycount, long keyrange) {
Random rand = new Random(12345);
HashMap<Long, Integer> hmap = new HashMap<Long, Integer>();
HashMap<Long, Integer> hmap = new HashMap<>();
DenseLongMap dmap = new DenseLongMap(512);
for (int i = 0; i < mapsize; i++) {
int value = i % 255;
long k = (long) (rand.nextDouble() * keyrange);
Long KK = new Long(k);
Long KK = k;
hmap.put(KK, new Integer(value));
hmap.put(KK, value);
dmap.put(k, value); // duplicate puts allowed!
}
for (int i = 0; i < trycount; i++) {
long k = (long) (rand.nextDouble() * keyrange);
Long KK = new Long(k);
Long KK = k;
Integer VV = hmap.get(KK);
int hvalue = VV == null ? -1 : VV.intValue();
int dvalue = dmap.getInt(k);
@ -48,17 +48,17 @@ public class DenseLongMapTest {
int trycount = 100000;
Random rand = new Random(12345);
HashSet<Long> hset = new HashSet<Long>();
HashSet<Long> hset = new HashSet<>();
DenseLongMap dmap = new DenseLongMap(512);
for (int i = 0; i < mapputs; i++) {
long k = (long) (rand.nextDouble() * keyrange);
hset.add(new Long(k));
hset.add(k);
dmap.put(k, 0);
}
for (int i = 0; i < trycount; i++) {
long k = (long) (rand.nextDouble() * keyrange);
boolean hcontains = hset.contains(new Long(k));
boolean hcontains = hset.contains(k);
boolean dcontains = dmap.getInt(k) == 0;
if (hcontains != dcontains) {

View file

@ -8,7 +8,7 @@ import java.util.Random;
public class SortedHeapTest {
@Test
public void sortedHeapTest1() {
SortedHeap<String> sh = new SortedHeap<String>();
SortedHeap<String> sh = new SortedHeap<>();
Random rnd = new Random();
for (int i = 0; i < 100000; i++) {
int val = rnd.nextInt(1000000);
@ -34,7 +34,7 @@ public class SortedHeapTest {
@Test
public void sortedHeapTest2() {
SortedHeap<String> sh = new SortedHeap<String>();
SortedHeap<String> sh = new SortedHeap<>();
Random rnd = new Random();
for (int i = 0; i < 100000; i++) {
sh.add(i, "" + i);

View file

@ -28,7 +28,6 @@
<exclude name="OneDeclarationPerLine" />
<exclude name="OverrideBothEqualsAndHashcode" />
<exclude name="PreserveStackTrace" />
<exclude name="PrimitiveWrapperInstantiation" />
<exclude name="ReturnEmptyCollectionRatherThanNull" />
<exclude name="UncommentedEmptyConstructor" />
<exclude name="UncommentedEmptyMethodBody" />
@ -48,4 +47,11 @@
<exclude name="MethodNamingConventions" />
</rule>
<!-- Rules similar to Android Studio code inspection default settings -->
<!-- <rule ref="category/java/bestpractices.xml/UnusedAssignment" /> -->
<rule ref="category/java/codestyle.xml/UseDiamondOperator" />
<!-- <rule ref="category/java/design.xml/ImmutableField" /> -->
<!-- Will be added in PMD 7 -->
<!-- <rule ref="category/java/codestyle.xml/UnnecessaryBoxing" /> -->
</ruleset>