Skip to content

Commit

Permalink
deleting unnecessary exception declarations & curly brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosario Trischitta committed Sep 5, 2020
1 parent 2db08bb commit 4465503
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 182 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ public MapReducer<OSMEntitySnapshot> snapshotFilter(MapReducer<OSMEntitySnapshot
Set<OSMType> osmTypes1, Set<OSMType> osmTypes2, Set<SimpleFeatureType> simpleFeatureTypes1,
Set<SimpleFeatureType> simpleFeatureTypes2, Integer[] keysInt1, Integer[] keysInt2,
Integer[] valuesInt1, Integer[] valuesInt2) {
return mapRed.filter(snapshot -> {
return snapshotMatches(snapshot, osmTypes1, simpleFeatureTypes1, keysInt1, valuesInt1)
|| snapshotMatches(snapshot, osmTypes2, simpleFeatureTypes2, keysInt2, valuesInt2);
});
return mapRed.filter(
snapshot -> snapshotMatches(snapshot, osmTypes1, simpleFeatureTypes1, keysInt1, valuesInt1)
|| snapshotMatches(snapshot, osmTypes2, simpleFeatureTypes2, keysInt2, valuesInt2));
}

/**
Expand All @@ -123,10 +122,9 @@ public MapAggregator<OSHDBCombinedIndex<OSHDBTimestamp, Integer>, OSMEntitySnaps
Set<OSMType> osmTypes1, Set<OSMType> osmTypes2, Set<SimpleFeatureType> simpleFeatureTypes1,
Set<SimpleFeatureType> simpleFeatureTypes2, Integer[] keysInt1, Integer[] keysInt2,
Integer[] valuesInt1, Integer[] valuesInt2) {
return mapRed.filter(snapshot -> {
return snapshotMatches(snapshot, osmTypes1, simpleFeatureTypes1, keysInt1, valuesInt1)
|| snapshotMatches(snapshot, osmTypes2, simpleFeatureTypes2, keysInt2, valuesInt2);
});
return mapRed.filter(
snapshot -> snapshotMatches(snapshot, osmTypes1, simpleFeatureTypes1, keysInt1, valuesInt1)
|| snapshotMatches(snapshot, osmTypes2, simpleFeatureTypes2, keysInt2, valuesInt2));
}

/** Applies a filter on the given MapReducer object using the given filter expressions. */
Expand Down Expand Up @@ -230,7 +228,7 @@ public static <A, U extends Comparable<U> & Serializable, V extends Comparable<V
TreeMap<V, SortedMap<U, A>> ret = new TreeMap<>();
result.forEach((index, data) -> {
if (!ret.containsKey(index.getSecondIndex())) {
ret.put(index.getSecondIndex(), new TreeMap<U, A>());
ret.put(index.getSecondIndex(), new TreeMap<>());
}
ret.get(index.getSecondIndex()).put(index.getFirstIndex(), data);
});
Expand All @@ -250,7 +248,8 @@ public void streamElementsResponse(HttpServletResponse servletResponse, DataResp
jsonFactory.createGenerator(tempStream, JsonEncoding.UTF8).setCodec(objMapper)
.writeObject(osmData);

String scaffold = tempStream.toString("UTF-8").replaceFirst("\\s*]\\s*}\\s*$", "");
String scaffold =
tempStream.toString(StandardCharsets.UTF_8).replaceFirst("\\s*]\\s*}\\s*$", "");

servletResponse.setContentType("application/geo+json; charset=utf-8");
ServletOutputStream outputStream = servletResponse.getOutputStream();
Expand Down Expand Up @@ -468,13 +467,9 @@ public org.wololo.geojson.Feature createOSMFeature(OSMEntity entity, Geometry ge
return cacheInUserData(geom, () -> Geo.lengthOf(geom.getBoundary()));
});
case LENGTH:
return preResult.sum(geom -> {
return cacheInUserData(geom, () -> Geo.lengthOf(geom));
});
return preResult.sum(geom -> cacheInUserData(geom, () -> Geo.lengthOf(geom)));
case AREA:
return preResult.sum(geom -> {
return cacheInUserData(geom, () -> Geo.areaOf(geom));
});
return preResult.sum(geom -> cacheInUserData(geom, () -> Geo.areaOf(geom)));
default:
return null;
}
Expand All @@ -494,10 +489,8 @@ public <K extends Comparable<K> & Serializable, V extends Number> SortedMap<OSHD
return (SortedMap<OSHDBCombinedIndex<OSHDBTimestamp, K>, V>) preResult.count();
case LENGTH:
return (SortedMap<OSHDBCombinedIndex<OSHDBTimestamp, K>, V>) preResult
.sum((SerializableFunction<OSMEntitySnapshot, Number>) snapshot -> {
return cacheInUserData(snapshot.getGeometry(),
() -> Geo.lengthOf(snapshot.getGeometry()));
});
.sum((SerializableFunction<OSMEntitySnapshot, Number>) snapshot -> cacheInUserData(
snapshot.getGeometry(), () -> Geo.lengthOf(snapshot.getGeometry())));
case PERIMETER:
return (SortedMap<OSHDBCombinedIndex<OSHDBTimestamp, K>, V>) preResult
.sum((SerializableFunction<OSMEntitySnapshot, Number>) snapshot -> {
Expand All @@ -509,10 +502,8 @@ public <K extends Comparable<K> & Serializable, V extends Number> SortedMap<OSHD
});
case AREA:
return (SortedMap<OSHDBCombinedIndex<OSHDBTimestamp, K>, V>) preResult
.sum((SerializableFunction<OSMEntitySnapshot, Number>) snapshot -> {
return cacheInUserData(snapshot.getGeometry(),
() -> Geo.areaOf(snapshot.getGeometry()));
});
.sum((SerializableFunction<OSMEntitySnapshot, Number>) snapshot -> cacheInUserData(
snapshot.getGeometry(), () -> Geo.areaOf(snapshot.getGeometry())));
default:
return null;
}
Expand Down Expand Up @@ -541,14 +532,10 @@ public <K extends Comparable<K> & Serializable, V extends Number> SortedMap<OSHD
});
case LENGTH:
return (SortedMap<OSHDBCombinedIndex<OSHDBCombinedIndex<Integer, K>, OSHDBTimestamp>, V>) preResult
.sum(geom -> {
return cacheInUserData(geom, () -> Geo.lengthOf(geom));
});
.sum(geom -> cacheInUserData(geom, () -> Geo.lengthOf(geom)));
case AREA:
return (SortedMap<OSHDBCombinedIndex<OSHDBCombinedIndex<Integer, K>, OSHDBTimestamp>, V>) preResult
.sum(geom -> {
return cacheInUserData(geom, () -> Geo.areaOf(geom));
});
.sum(geom -> cacheInUserData(geom, () -> Geo.areaOf(geom)));
default:
return null;
}
Expand Down Expand Up @@ -722,17 +709,16 @@ public Pair<Pair<Integer, Integer>, OSMEntitySnapshot> mapSnapshotToTags(int key
int tagValueId = tags[i + 1];
if (tagKeyId == keysInt) {
if (valuesInt.length == 0) {
return new ImmutablePair<>(new ImmutablePair<Integer, Integer>(tagKeyId, tagValueId), f);
return new ImmutablePair<>(new ImmutablePair<>(tagKeyId, tagValueId), f);
}
for (int value : valuesInt) {
if (tagValueId == value) {
return new ImmutablePair<>(new ImmutablePair<Integer, Integer>(tagKeyId, tagValueId),
f);
return new ImmutablePair<>(new ImmutablePair<>(tagKeyId, tagValueId), f);
}
}
}
}
return new ImmutablePair<>(new ImmutablePair<Integer, Integer>(-1, -1), f);
return new ImmutablePair<>(new ImmutablePair<>(-1, -1), f);
}

/** Creates a RatioResponse. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ public static Response countGroupByType(HttpServletRequest servletRequest,
ProcessingData processingData = inputProcessor.getProcessingData();
RequestParameters requestParameters = processingData.getRequestParameters();
result = mapRed.aggregateByTimestamp()
.aggregateBy((SerializableFunction<OSMContribution, OSMType>) f -> {
return f.getEntityAfter().getType();
}, processingData.getOsmTypes()).map(OSMContribution::getContributorUserId).countUniq();
.aggregateBy(
(SerializableFunction<OSMContribution, OSMType>) f -> f.getEntityAfter().getType(),
processingData.getOsmTypes())
.map(OSMContribution::getContributorUserId).countUniq();
SortedMap<OSMType, SortedMap<OSHDBTimestamp, Integer>> groupByResult;
groupByResult = ExecutionUtils.nest(result);
GroupByResult[] resultSet = new GroupByResult[groupByResult.size()];
Expand Down Expand Up @@ -149,7 +150,7 @@ public static Response countGroupByTag(HttpServletRequest servletRequest,
if (groupByValues.length != 0) {
for (int j = 0; j < groupByValues.length; j++) {
valuesInt[j] = tt.getOSHDBTagOf(groupByKey[0], groupByValues[j]).getValue();
zeroFill.add(new ImmutablePair<Integer, Integer>(keysInt, valuesInt[j]));
zeroFill.add(new ImmutablePair<>(keysInt, valuesInt[j]));
}
}
SortedMap<OSHDBCombinedIndex<OSHDBTimestamp, Pair<Integer, Integer>>, Integer> result = null;
Expand All @@ -161,21 +162,19 @@ public static Response countGroupByTag(HttpServletRequest servletRequest,
int tagValueId = tags[i + 1];
if (tagKeyId == keysInt) {
if (valuesInt.length == 0) {
res.add(
new ImmutablePair<>(new ImmutablePair<Integer, Integer>(tagKeyId, tagValueId), f));
res.add(new ImmutablePair<>(new ImmutablePair<>(tagKeyId, tagValueId), f));
}
for (int value : valuesInt) {
if (tagValueId == value) {
res.add(new ImmutablePair<>(new ImmutablePair<Integer, Integer>(tagKeyId, tagValueId),
f));
res.add(new ImmutablePair<>(new ImmutablePair<>(tagKeyId, tagValueId), f));
}
}
}
}
if (res.isEmpty()) {
res.add(new ImmutablePair<>(new ImmutablePair<Integer, Integer>(-1, -1), f));
res.add(new ImmutablePair<>(new ImmutablePair<>(-1, -1), f));
}
res.add(new ImmutablePair<>(new ImmutablePair<Integer, Integer>(-2, -2), f));
res.add(new ImmutablePair<>(new ImmutablePair<>(-2, -2), f));
return res;
}).aggregateByTimestamp().aggregateBy(Pair::getKey, zeroFill).map(Pair::getValue)
.map(OSMContribution::getContributorUserId).countUniq();
Expand Down Expand Up @@ -298,7 +297,7 @@ public static <P extends Geometry & Polygonal> Response countGroupByBoundary(
mapRed = inputProcessor.processParameters();
ProcessingData processingData = inputProcessor.getProcessingData();
RequestParameters requestParameters = processingData.getRequestParameters();
ArrayList<Geometry> arrGeoms = processingData.getBoundaryList();
List<Geometry> arrGeoms = processingData.getBoundaryList();
@SuppressWarnings("unchecked") // intentionally as check for P on Polygonal is already performed
Map<Integer, P> geoms = IntStream.range(0, arrGeoms.size()).boxed()
.collect(Collectors.toMap(idx -> idx, idx -> (P) arrGeoms.get(idx)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GeometryBuilder() {
* @throws NotFoundException if the provided boundary parameter does not lie completely within the
* underlying data-extract polygon
*/
public Geometry createBboxes(String[] bboxes) throws BadRequestException, NotFoundException {
public Geometry createBboxes(String[] bboxes) {
try {
Geometry unifiedBbox;
OSHDBBoundingBox bbox;
Expand All @@ -70,7 +70,7 @@ public Geometry createBboxes(String[] bboxes) throws BadRequestException, NotFou
double maxLat = Double.parseDouble(bboxes[3]);
bbox = new OSHDBBoundingBox(minLon, minLat, maxLon, maxLat);
unifiedBbox = gf.createGeometry(OSHDBGeometryBuilder.getGeometry(bbox));
ArrayList<Geometry> geometryList = new ArrayList<Geometry>();
ArrayList<Geometry> geometryList = new ArrayList<>();
geometryList.add(OSHDBGeometryBuilder.getGeometry(bbox));
for (int i = 4; i < bboxes.length; i += 4) {
minLon = Double.parseDouble(bboxes[i]);
Expand Down Expand Up @@ -104,15 +104,14 @@ public Geometry createBboxes(String[] bboxes) throws BadRequestException, NotFou
* @throws NotFoundException if the provided boundary parameter does not lie completely within the
* underlying data-extract polygon
*/
public Geometry createCircularPolygons(String[] bpoints)
throws BadRequestException, NotFoundException {
public Geometry createCircularPolygons(String[] bpoints) {
GeometryFactory geomFact = new GeometryFactory();
Geometry buffer;
Geometry geom;
CoordinateReferenceSystem sourceCrs;
CoordinateReferenceSystem targetCrs;
MathTransform transform = null;
ArrayList<Geometry> geometryList = new ArrayList<Geometry>();
ArrayList<Geometry> geometryList = new ArrayList<>();
InputProcessingUtils utils = new InputProcessingUtils();
try {
for (int i = 0; i < bpoints.length; i += 3) {
Expand Down Expand Up @@ -157,7 +156,7 @@ public Geometry createCircularPolygons(String[] bpoints)
* @throws NotFoundException if the provided boundary parameter does not lie completely within the
* underlying data-extract polygon
*/
public Geometry createBpolys(String[] bpolys) throws BadRequestException, NotFoundException {
public Geometry createBpolys(String[] bpolys) {
GeometryFactory geomFact = new GeometryFactory();
Geometry bpoly;
ArrayList<Coordinate> coords = new ArrayList<>();
Expand Down Expand Up @@ -213,7 +212,7 @@ public Geometry createBpolys(String[] bpolys) throws BadRequestException, NotFou
*
* @throws RuntimeException if the derived GeoJSON cannot be converted to a Geometry
*/
public void createGeometryFromMetadataGeoJson(String geoJson) throws RuntimeException {
public void createGeometryFromMetadataGeoJson(String geoJson) {
GeoJSONReader reader = new GeoJSONReader();
try {
ProcessingData.setDataPolyGeom(reader.read(geoJson));
Expand Down Expand Up @@ -291,7 +290,7 @@ public Geometry createGeometryFromGeoJson(String geoJson, InputProcessor inputPr
* @throws NotFoundException if the unified Geometry does not lie completely within the underlying
* data extract
*/
private Geometry unifyPolys(Collection<Geometry> geometries) throws NotFoundException {
private Geometry unifyPolys(Collection<Geometry> geometries) {
GeometryFactory geometryFactory = new GeometryFactory();
Polygon[] polys = geometries.stream().flatMap(geo -> {
if (geo instanceof MultiPolygon) {
Expand Down Expand Up @@ -346,7 +345,7 @@ private Object createBoundaryIdFromJsonObjectId(JsonObject jsonObject,
* @throws BadRequestException if the given <code>JsonObject</code> is not of type Polygon or
* Multipolygon
*/
private void checkGeometryTypeOfFeature(JsonObject geomObj) throws BadRequestException {
private void checkGeometryTypeOfFeature(JsonObject geomObj) {
if (!geomObj.getString("type").equals("Polygon")
&& !geomObj.getString("type").equals("MultiPolygon")) {
throw new BadRequestException(
Expand Down
Loading

0 comments on commit 4465503

Please sign in to comment.