Last active
December 1, 2017 10:30
-
-
Save wlievens/dd566876da4d308ccbf3ba2861610704 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
@Setter | |
@AllArgsConstructor | |
private static class GeometryHandle | |
{ | |
Geometry geometry; | |
} | |
public static Collector<Geometry, GeometryHandle, Geometry> collectorUnion(@NonNull GeometryFactory factory) | |
{ | |
return new Collector<Geometry, GeometryHandle, Geometry>() | |
{ | |
@Override | |
public Supplier<GeometryHandle> supplier() | |
{ | |
return () -> new GeometryHandle(factory.createGeometryCollection(new Geometry[0])); | |
} | |
@Override | |
public BiConsumer<GeometryHandle, Geometry> accumulator() | |
{ | |
return (a, b) -> a.geometry = a.geometry.union(b); | |
} | |
@Override | |
public BinaryOperator<GeometryHandle> combiner() | |
{ | |
return (a, b) -> new GeometryHandle(a.geometry.union(b.geometry)); | |
} | |
@Override | |
public Function<GeometryHandle, Geometry> finisher() | |
{ | |
return GeometryHandle::getGeometry; | |
} | |
@Override | |
public Set<Characteristics> characteristics() | |
{ | |
return Sets.immutableEnumSet(Characteristics.UNORDERED); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Java Stream API Collector implementation for the union operation on JTS geometries.
Depends on JTS, Lombok and Guava, but the latter two can be factored out trivially.