Skip to content

Commit be92298

Browse files
committed
make sure Filter predicates are always serializable
creates a copy of the existing SerializablePredicate class in order to avoid a circular dependency.
1 parent 7454255 commit be92298

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
2020
### other changes
2121

2222
* integrate [ohsome-filter](https://gitlab.gistools.geog.uni-heidelberg.de/giscience/big-data/ohsome/libs/ohsome-filter) module fully into this repository, renaming it to `oshdb-filter`. ([#306])
23+
* make sure predicate-filters are always serializable. ([#353])
2324
* improve maintainability of parts of important central processing algorithms for determining entity modification history: refactoring improves code structure, adds inline documentation and enhances test coverage. ([#327])
2425

2526
### bugfixes
@@ -34,7 +35,7 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
3435
[#327]: https://github.com/GIScience/oshdb/issues/327
3536
[#338]: https://github.com/GIScience/oshdb/issues/338
3637
[#352]: https://github.com/GIScience/oshdb/pull/352
37-
38+
[#353]: https://github.com/GIScience/oshdb/pull/353
3839

3940
## 0.6.3
4041

oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapAggregator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.heigit.ohsome.oshdb.api.object.OSHDBMapReducible;
3737
import org.heigit.ohsome.oshdb.api.object.OSMContribution;
3838
import org.heigit.ohsome.oshdb.api.object.OSMEntitySnapshot;
39+
import org.heigit.ohsome.oshdb.filter.Filter;
3940
import org.heigit.ohsome.oshdb.filter.FilterExpression;
4041
import org.heigit.ohsome.oshdb.osm.OSMEntity;
4142
import org.heigit.ohsome.oshdb.osm.OSMType;
@@ -290,8 +291,9 @@ public MapAggregator<U, X> osmType(Set<OSMType> typeFilter) {
290291
*
291292
* @param f the filter function to call for each osm entity
292293
* @return a modified copy of this object (can be used to chain multiple commands together)
293-
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with
294-
* {@link org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Predicate)} instead
294+
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with {@link
295+
* org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Filter.SerializablePredicate)}
296+
* instead
295297
*/
296298
@Deprecated
297299
@Contract(pure = true)

oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapReducer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,9 @@ public MapReducer<X> osmType(Set<OSMType> typeFilter) {
431431
*
432432
* @param f the filter function to call for each osm entity
433433
* @return a modified copy of this mapReducer (can be used to chain multiple commands together)
434-
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with
435-
* {@link org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Predicate)} instead
434+
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with {@link
435+
* org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Filter.SerializablePredicate)}
436+
* instead
436437
*/
437438
@Deprecated
438439
@Contract(pure = true)

oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/Filter.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.heigit.ohsome.oshdb.filter;
22

3+
import java.io.Serializable;
34
import java.util.function.BiPredicate;
45
import java.util.function.Predicate;
56
import java.util.function.Supplier;
@@ -12,6 +13,12 @@
1213
* A filter condition which can be applied to an OSM entity.
1314
*/
1415
public interface Filter extends FilterExpression {
16+
/** A predicate which is also serializable. */
17+
public interface SerializablePredicate<T> extends Predicate<T>, Serializable {}
18+
19+
/** A bi-predicate which is also serializable. */
20+
interface SerializableBiPredicate<T, U> extends BiPredicate<T, U>, Serializable {}
21+
1522
/**
1623
* Constructs a simple filter based on a predicate on OSH entities.
1724
*
@@ -23,7 +30,7 @@ public interface Filter extends FilterExpression {
2330
* @param oshCallback predicate which tests osh entities
2431
* @return a filter object which filters using the given predicate
2532
*/
26-
static Filter byOSHEntity(Predicate<OSHEntity> oshCallback) {
33+
static Filter byOSHEntity(SerializablePredicate<OSHEntity> oshCallback) {
2734
return by(oshCallback, ignored -> true);
2835
}
2936

@@ -38,7 +45,7 @@ static Filter byOSHEntity(Predicate<OSHEntity> oshCallback) {
3845
* @param osmCallback predicate which tests osm entities
3946
* @return a filter object which filters using the given predicate
4047
*/
41-
static Filter byOSMEntity(Predicate<OSMEntity> osmCallback) {
48+
static Filter byOSMEntity(SerializablePredicate<OSMEntity> osmCallback) {
4249
return new NegatableFilter(osmCallback::test);
4350
}
4451

@@ -54,7 +61,9 @@ static Filter byOSMEntity(Predicate<OSMEntity> osmCallback) {
5461
* @param osmCallback predicate which tests osm entities
5562
* @return a filter object which filters using the given predicates
5663
*/
57-
static Filter by(Predicate<OSHEntity> oshCallback, Predicate<OSMEntity> osmCallback) {
64+
static Filter by(
65+
SerializablePredicate<OSHEntity> oshCallback,
66+
SerializablePredicate<OSMEntity> osmCallback) {
5867
return by(oshCallback, osmCallback, (ignored, ignored2) -> true);
5968
}
6069

@@ -75,9 +84,9 @@ static Filter by(Predicate<OSHEntity> oshCallback, Predicate<OSMEntity> osmCallb
7584
* @return a filter object which filters using the given predicates
7685
*/
7786
static Filter by(
78-
Predicate<OSHEntity> oshCallback,
79-
Predicate<OSMEntity> osmCallback,
80-
BiPredicate<OSMEntity, Supplier<Geometry>> geomCallback
87+
SerializablePredicate<OSHEntity> oshCallback,
88+
SerializablePredicate<OSMEntity> osmCallback,
89+
SerializableBiPredicate<OSMEntity, Supplier<Geometry>> geomCallback
8190
) {
8291
return new NegatableFilter(new FilterInternal() {
8392
@Override

0 commit comments

Comments
 (0)