Skip to content

Commit

Permalink
make sure Filter predicates are always serializable (#353)
Browse files Browse the repository at this point in the history
creates a copy of the existing SerializablePredicate class in order to avoid a circular dependency.
  • Loading branch information
tyrasd authored Feb 17, 2021
1 parent 36088f6 commit 46ec2eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
### other changes

* 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])
* make sure predicate-filters are always serializable. ([#353])
* 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])

### bugfixes
Expand All @@ -34,7 +35,7 @@ import org.heigit.ohsome.oshdb.api.db.OSHDBH2;
[#327]: https://github.com/GIScience/oshdb/issues/327
[#338]: https://github.com/GIScience/oshdb/issues/338
[#352]: https://github.com/GIScience/oshdb/pull/352

[#353]: https://github.com/GIScience/oshdb/pull/353

## 0.6.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.heigit.ohsome.oshdb.api.object.OSHDBMapReducible;
import org.heigit.ohsome.oshdb.api.object.OSMContribution;
import org.heigit.ohsome.oshdb.api.object.OSMEntitySnapshot;
import org.heigit.ohsome.oshdb.filter.Filter;
import org.heigit.ohsome.oshdb.filter.FilterExpression;
import org.heigit.ohsome.oshdb.osm.OSMEntity;
import org.heigit.ohsome.oshdb.osm.OSMType;
Expand Down Expand Up @@ -290,8 +291,9 @@ public MapAggregator<U, X> osmType(Set<OSMType> typeFilter) {
*
* @param f the filter function to call for each osm entity
* @return a modified copy of this object (can be used to chain multiple commands together)
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with
* {@link org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Predicate)} instead
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with {@link
* org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Filter.SerializablePredicate)}
* instead
*/
@Deprecated
@Contract(pure = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ public MapReducer<X> osmType(Set<OSMType> typeFilter) {
*
* @param f the filter function to call for each osm entity
* @return a modified copy of this mapReducer (can be used to chain multiple commands together)
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with
* {@link org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Predicate)} instead
* @deprecated use oshdb-filter {@link #filter(FilterExpression)} with {@link
* org.heigit.ohsome.oshdb.filter.Filter#byOSMEntity(Filter.SerializablePredicate)}
* instead
*/
@Deprecated
@Contract(pure = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.heigit.ohsome.oshdb.filter;

import java.io.Serializable;
import java.util.function.BiPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -12,6 +13,12 @@
* A filter condition which can be applied to an OSM entity.
*/
public interface Filter extends FilterExpression {
/** A predicate which is also serializable. */
public interface SerializablePredicate<T> extends Predicate<T>, Serializable {}

/** A bi-predicate which is also serializable. */
interface SerializableBiPredicate<T, U> extends BiPredicate<T, U>, Serializable {}

/**
* Constructs a simple filter based on a predicate on OSH entities.
*
Expand All @@ -23,7 +30,7 @@ public interface Filter extends FilterExpression {
* @param oshCallback predicate which tests osh entities
* @return a filter object which filters using the given predicate
*/
static Filter byOSHEntity(Predicate<OSHEntity> oshCallback) {
static Filter byOSHEntity(SerializablePredicate<OSHEntity> oshCallback) {
return by(oshCallback, ignored -> true);
}

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

Expand All @@ -54,7 +61,9 @@ static Filter byOSMEntity(Predicate<OSMEntity> osmCallback) {
* @param osmCallback predicate which tests osm entities
* @return a filter object which filters using the given predicates
*/
static Filter by(Predicate<OSHEntity> oshCallback, Predicate<OSMEntity> osmCallback) {
static Filter by(
SerializablePredicate<OSHEntity> oshCallback,
SerializablePredicate<OSMEntity> osmCallback) {
return by(oshCallback, osmCallback, (ignored, ignored2) -> true);
}

Expand All @@ -75,9 +84,9 @@ static Filter by(Predicate<OSHEntity> oshCallback, Predicate<OSMEntity> osmCallb
* @return a filter object which filters using the given predicates
*/
static Filter by(
Predicate<OSHEntity> oshCallback,
Predicate<OSMEntity> osmCallback,
BiPredicate<OSMEntity, Supplier<Geometry>> geomCallback
SerializablePredicate<OSHEntity> oshCallback,
SerializablePredicate<OSMEntity> osmCallback,
SerializableBiPredicate<OSMEntity, Supplier<Geometry>> geomCallback
) {
return new NegatableFilter(new FilterInternal() {
@Override
Expand Down

0 comments on commit 46ec2eb

Please sign in to comment.