Skip to content

Commit

Permalink
fix some pmd warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rtroilo authored and joker234 committed May 4, 2021
1 parent da0ed1b commit 112d2d3
Show file tree
Hide file tree
Showing 51 changed files with 274 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public Iterator<KeyValueFrequency> iterator() {
try {
dataInput.close();
} catch (Exception e2) {
// Exceptions should be ignored
e.addSuppressed(e2);
}
}
throw new RuntimeException(e.getMessage());
Expand Down Expand Up @@ -238,7 +238,7 @@ public ValueFrequency next() {
final String value = vf.value;
int freq = vf.freq;

while (!queue.isEmpty() && (comparator.compare(vf, queue.peek().peek()) == 0)) {
while (!queue.isEmpty() && comparator.compare(vf, queue.peek().peek()) == 0) {
vf = poll();
freq += vf.freq;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ public static class RoleMapReader implements Iterator<Role> {

private final ObjectBidirectionalIterator<Entry<String>> roleIterator;

public static RoleMapReader of(Object2IntAVLTreeMap<String> role2Frequency, boolean remove) {
public static RoleMapReader of(Object2IntAVLTreeMap<String> role2Frequency) {
final ObjectBidirectionalIterator<Entry<String>> roleIterator =
role2Frequency.object2IntEntrySet().iterator();
return new RoleMapReader(roleIterator, remove);
return new RoleMapReader(roleIterator);
}

private RoleMapReader(ObjectBidirectionalIterator<Entry<String>> roleIterator, boolean remove) {
private RoleMapReader(ObjectBidirectionalIterator<Entry<String>> roleIterator) {
this.roleIterator = roleIterator;
}

Expand Down Expand Up @@ -202,14 +202,14 @@ public Iterator<Role> iterator() {
try {
dataInput.close();
} catch (Exception e2) {
// Exceptions should be ignored
e.addSuppressed(e2);
}
}
throw new RuntimeException(e.getMessage());
}
}).forEach(iters::add);
if (role2Frequency.size() > 0) {
iters.add(RoleMapReader.of(role2Frequency, true));
iters.add(RoleMapReader.of(role2Frequency));
}

return MergeIterator.of(iters, (a, b) -> a.role.compareTo(b.role), list -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

public class LoaderKeyTables {

public static interface Handler {
public void loadKeyValues(int id, String key, List<String> values);
public interface Handler {
void loadKeyValues(int id, String key, List<String> values);

public void loadRole(int id, String role);
void loadRole(int id, String role);
}

Path workDirectory;
Expand Down Expand Up @@ -78,16 +78,14 @@ public void loadRoles() {
final Function<InputStream, InputStream> input = Functions.identity();
try (DataInputStream roleIn = new DataInputStream(input.apply(new BufferedInputStream(
new FileInputStream(workDirectory.resolve("extract_roles").toFile()))))) {
try {
for (int id = 0; true; id++) {
final Role role = Role.read(roleIn);
handler.loadRole(id, role.role);
}
} catch (EOFException e) {
// we reached end of file!
for (int id = 0; true; id++) {
final Role role = Role.read(roleIn);
handler.loadRole(id, role.role);
}
} catch (IOException e) {
e.printStackTrace();
if (!(e instanceof EOFException)) {
e.printStackTrace();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public class LoaderNode extends Loader {

public static interface Handler {
public interface Handler {
void handleNodeGrid(long cellId, Collection<TransformOSHNode> nodes);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ public void load(long cellId2, boolean all) {
}

while (reader.hasNext()
&& (all || (ZGrid.ORDER_DFS_TOP_DOWN.compare(reader.getCellId(), cellId2) <= 0))) {
&& (all || ZGrid.ORDER_DFS_TOP_DOWN.compare(reader.getCellId(), cellId2) <= 0)) {
final long cellId = reader.getCellId();
final int zoom = ZGrid.getZoom(cellId);
final Set<TransformOSHNode> nodes = reader.next();
Expand Down Expand Up @@ -113,11 +113,11 @@ public void load(long cellId2, boolean all) {
private void store(int zoom) {
for (int i = maxZoom; i >= zoom; i--) {
Grid grid = zoomLevel.get(i);
if ((grid == null) || (grid.entities == null)) {
if (grid == null || grid.entities == null) {
continue;
}

if ((i > maxZoomLevel) || ((grid.entities.size() < minEntitiesPerCell) && (i > 0))) {
if (i > maxZoomLevel || grid.entities.size() < minEntitiesPerCell && i > 0) {
Grid parent = zoomLevel.get(i - 1);
if (parent.entities == null) {
parent.cellId = ZGrid.getParent(grid.cellId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class LoaderRelation extends Loader {

public static interface Handler {
public interface Handler {
public void handleRelationGrid(long cellId, Collection<TransfomRelation> entities,
Collection<TransformOSHNode> nodes, Collection<TransformOSHWay> ways);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ private void store(int zoom) {
continue;
}

if (i > maxZoomLevel || (grid.entities.size() < minEntitiesPerCell && i > 0)) {
if (i > maxZoomLevel || grid.entities.size() < minEntitiesPerCell && i > 0) {
Grid parent = zoomLevel.get(i - 1);

if (parent.entities == null) {
Expand Down Expand Up @@ -215,7 +215,7 @@ public void visitNode(TransformOSHNode osh) {
final Grid g = zoomLevel.get(i);
if (g.nodesSet.contains(id)) {
g.nodeforGrid.add(osh);
g.nodesSet.remove(id);;
g.nodesSet.remove(id);
break;
}
}
Expand All @@ -233,7 +233,7 @@ public void visitWay(TransformOSHWay osh) {
final Grid g = zoomLevel.get(i);
if (g.waysSet.contains(id)) {
g.wayforGrid.add(osh);
g.waysSet.remove(id);;
g.waysSet.remove(id);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class LoaderWay extends Loader {

public static interface Handler {
public interface Handler {
public void handleWayGrid(long cellId, Collection<TransformOSHWay> ways,
Collection<TransformOSHNode> nodes);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ private void store(int zoom) {
continue;
}

if (i > maxZoomLevel || (grid.entities.size() < minEntitiesPerCell && i > 0)) {
if (i > maxZoomLevel || grid.entities.size() < minEntitiesPerCell && i > 0) {
Grid parent = zoomLevel.get(i - 1);

if (parent.entities == null) {
Expand Down Expand Up @@ -205,7 +205,7 @@ public void visitNode(TransformOSHNode node) {
final Grid g = zoomLevel.get(i);
if (g.nodesSet.contains(id)) {
g.forGrid.add(node);
g.nodesSet.remove(id);;
g.nodesSet.remove(id);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void transform(TransformArgs config) throws Exception {
if (worker >= workerTotal) {
throw new IllegalArgumentException("worker must be lesser than totalWorker!");
}
if ((workerTotal > 1) && (step.startsWith("a"))) {
if (workerTotal > 1 && step.startsWith("a")) {
throw new IllegalArgumentException(
"step all with totalWorker > 1 is not allwod use step (node,way or relation)");
}
Expand All @@ -124,24 +124,24 @@ public static void transform(TransformArgs config) throws Exception {
final long availableMemory = availableHeapMemory - Math.max(1 * GB, availableHeapMemory / 3);

System.out.println("Transform:");
System.out.println("avaliable memory: " + (availableMemory / 1024L / 1024L) + " mb");
System.out.println("avaliable memory: " + availableMemory / 1024L / 1024L + " mb");

final OsmPbfMeta pbfMeta = Extract.pbfMetaData(pbf);

final TagToIdMapper tag2Id = Transform.getTagToIdMapper(workDir);

if (step.startsWith("a") || step.startsWith("n")) {
long maxMemory = availableMemory - tag2Id.estimatedSize();
if (maxMemory < (100 * MB)) {
if (maxMemory < 100 * MB) {
System.out.println("warning: only 100MB memory left for transformation! "
+ "Increase heapsize -Xmx if possible");
}
if (maxMemory < (1 * MB)) {
if (maxMemory < 1 * MB) {
throw new Exception("to few memory left for transformation. "
+ "You need to increase JVM heapsize -Xmx for transforming");
}

System.out.println("maxMemory for transformation: " + (maxMemory / 1024L / 1024L) + " mb");
System.out.println("maxMemory for transformation: " + maxMemory / 1024L / 1024L + " mb");
System.out.print("start transforming nodes ...");
Transform.withMaxMemory(maxMemory).withWorkDirectory(workDir).transformNodes(pbfMeta, maxZoom,
tag2Id, worker, workerTotal);
Expand All @@ -150,19 +150,19 @@ public static void transform(TransformArgs config) throws Exception {

if (step.startsWith("a") || step.startsWith("w")) {
final long mapMemory = availableMemory / 2L;
try (final SortedLong2LongMap node2Cell =
try (SortedLong2LongMap node2Cell =
new SortedLong2LongMap(workDir.resolve("transform_idToCell_" + "node"), mapMemory);) {
long maxMemory = availableMemory - tag2Id.estimatedSize() - mapMemory;
if (maxMemory < (100 * MB)) {
if (maxMemory < 100 * MB) {
System.out.println("warning: only 100MB memory left for transformation! "
+ "Increase heapsize -Xmx if possible");
}
if (maxMemory < (1 * MB)) {
if (maxMemory < 1 * MB) {
throw new Exception("to few memory left for transformation. "
+ "You need to increase JVM heapsize -Xmx for transforming");
}

System.out.println("maxMemory for transformation: " + (maxMemory / 1024L / 1024L) + " mb");
System.out.println("maxMemory for transformation: " + maxMemory / 1024L / 1024L + " mb");
System.out.print("start transforming ways ...");
Transform.withMaxMemory(maxMemory).withWorkDirectory(workDir).transformWays(pbfMeta,
maxZoom, tag2Id, node2Cell, worker, workerTotal);
Expand All @@ -175,22 +175,22 @@ public static void transform(TransformArgs config) throws Exception {
final long mapMemory = availableMemory / 2L;
final long mapMemoryNode = mapMemory / 3L;
try (
final SortedLong2LongMap node2Cell = new SortedLong2LongMap(
SortedLong2LongMap node2Cell = new SortedLong2LongMap(
workDir.resolve("transform_idToCell_" + "node"), mapMemoryNode);
final SortedLong2LongMap way2Cell = new SortedLong2LongMap(
SortedLong2LongMap way2Cell = new SortedLong2LongMap(
workDir.resolve("transform_idToCell_" + "way"), mapMemory - mapMemoryNode);) {
long maxMemory =
availableMemory - tag2Id.estimatedSize() - role2Id.estimatedSize() - mapMemory;
if (maxMemory < (100 * MB)) {
if (maxMemory < 100 * MB) {
System.out.println("warning: only 100MB memory left for transformation! "
+ "Increase heapsize -Xmx if possible");
}
if (maxMemory < (1 * MB)) {
if (maxMemory < 1 * MB) {
throw new Exception("to few memory left for transformation. "
+ "You need to increase JVM heapsize -Xmx for transforming");
}

System.out.println("maxMemory for transformation: " + (maxMemory / 1024L / 1024L) + " mb");
System.out.println("maxMemory for transformation: " + maxMemory / 1024L / 1024L + " mb");
System.out.print("start transforming relations ...");
Transform.withMaxMemory(maxMemory).withWorkDirectory(workDir).transformRelations(pbfMeta,
maxZoom, tag2Id, role2Id, node2Cell, way2Cell, worker, workerTotal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ public void transform(long id, List<Entity> versions) {
final long zId = getCell(node.getLongitude(), node.getLatitude());
if (zId >= 0) {
cellIds.add(zId);
} else {
// System.err.printf("negative zId! %s%n", node);
}
}
nodes.add(getNode(node));
}
final long cellId = (cellIds.size() > 0) ? findBestFittingCellId(cellIds) : -1;
final long cellId = cellIds.size() > 0 ? findBestFittingCellId(cellIds) : -1;

try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static TagToIdMapper getTagToIdMapper(Path workDirectory)
final StringToIdMappingImpl[] value2IdMappings;

final Function<InputStream, InputStream> input = Functions.identity();
try (final RandomAccessFile raf =
try (RandomAccessFile raf =
new RandomAccessFile(workDirectory.resolve("extract_keyvalues").toFile(), "r")) {
final FileChannel channel = raf.getChannel();
try (
Expand Down Expand Up @@ -156,16 +156,15 @@ public static RoleToIdMapper getRoleToIdMapper(Path workDirectory)
InputStream in = input.apply(new BufferedInputStream(
new FileInputStream(workDirectory.resolve("extract_roles").toFile())));
DataInputStream dataIn = new DataInputStream(new BufferedInputStream(in))) {

try {
while (true) {
final Role role = Role.read(dataIn);
final int hash = hashFunction.applyAsInt(role.role);
roleHash2Cnt.addTo(hash, 1);
roleCount++;
}
} catch (EOFException e) {
// no-op
while (true) {
final Role role = Role.read(dataIn);
final int hash = hashFunction.applyAsInt(role.role);
roleHash2Cnt.addTo(hash, 1);
roleCount++;
}
} catch (IOException e) {
if (!(e instanceof EOFException)) {
throw e;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

public interface OSHEntity {

public long getId();
long getId();

public OSHDBBoundingBox getBoundingBox();
OSHDBBoundingBox getBoundingBox();

public abstract OSMType getType();
abstract OSMType getType();


public Iterable<? extends OSMEntity> versions();
Iterable<? extends OSMEntity> versions();

public Iterator<? extends OSMEntity> iterator();
Iterator<? extends OSMEntity> iterator();

public Stream<? extends OSMEntity> stream();
Stream<? extends OSMEntity> stream();

public OSHEntity copy();
OSHEntity copy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ default OSMType getType() {
}

@Override
public OSHNode copy();
OSHNode copy();

@Override
public Iterator<OSMNode> iterator();
Iterator<OSMNode> iterator();

@Override
public Iterable<OSMNode> versions();
Iterable<OSMNode> versions();

@Override
public default Stream<OSMNode> stream() {
default Stream<OSMNode> stream() {
return StreamSupport.stream(versions().spliterator(), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface OSMEntity extends OSHDBTemporal {
int[] getTags();


public default String asString() {
default String asString() {
return String.format("ID:%d V:%d TS:%d CS:%d VIS:%s UID:%d TAGS:%S", getId(), getVersion(),
getEpochSecond(), getChangeset(), isVisible(), getUserId(),
Arrays.toString(getTags()));
Expand Down
Loading

0 comments on commit 112d2d3

Please sign in to comment.