Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename LayerPostProcesser to LayerPostProcessor #1031

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* <li>{@link FeatureProcessor} to handle features from a particular source (added through
* {@link #registerSourceHandler(String, FeatureProcessor)})</li>
* <li>{@link FinishHandler} to be notified whenever we finish processing each source</li>
* <li>{@link LayerPostProcesser} to post-process features in a layer before rendering the output tile</li>
* <li>{@link LayerPostProcessor} to post-process features in a layer before rendering the output tile</li>
* <li>{@link TilePostProcessor} to post-process features in a tile before rendering the output tile</li>
* </ul>
* See {@code OpenMapTilesProfile} for a full implementation using this framework.
Expand All @@ -44,8 +44,8 @@ public abstract class ForwardingProfile implements Profile {
private final List<OsmRelationPreprocessor> osmRelationPreprocessors = new ArrayList<>();
/** Handlers that get a callback when each source is finished reading. */
private final List<FinishHandler> finishHandlers = new ArrayList<>();
/** Map from layer name to its handler if it implements {@link LayerPostProcesser}. */
private final Map<String, List<LayerPostProcesser>> layerPostProcessors = new HashMap<>();
/** Map from layer name to its handler if it implements {@link LayerPostProcessor}. */
private final Map<String, List<LayerPostProcessor>> layerPostProcessors = new HashMap<>();
/** List of handlers that implement {@link TilePostProcessor}. */
private final List<TilePostProcessor> tilePostProcessors = new ArrayList<>();
/** List of handlers that implements {@link FeatureProcessor} along with a filter expression. */
Expand Down Expand Up @@ -147,7 +147,7 @@ public void registerFeatureHandler(FeatureProcessor processor) {

/**
* Call {@code handler} for different events based on which interfaces {@code handler} implements:
* {@link OsmRelationPreprocessor}, {@link FinishHandler}, {@link TilePostProcessor} or {@link LayerPostProcesser}.
* {@link OsmRelationPreprocessor}, {@link FinishHandler}, {@link TilePostProcessor} or {@link LayerPostProcessor}.
*/
public void registerHandler(Handler handler) {
if (!caresAboutLayer(handler)) {
Expand All @@ -166,7 +166,7 @@ public void registerHandler(Handler handler) {
if (handler instanceof FinishHandler finishHandler) {
finishHandlers.add(finishHandler);
}
if (handler instanceof LayerPostProcesser postProcessor) {
if (handler instanceof LayerPostProcessor postProcessor) {
layerPostProcessors.computeIfAbsent(postProcessor.name(), name -> new ArrayList<>())
.add(postProcessor);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public boolean caresAbout(Expression.PartialInput input) {
public List<VectorTile.Feature> postProcessLayerFeatures(String layer, int zoom, List<VectorTile.Feature> items)
throws GeometryException {
// delegate feature post-processing to each layer, if it implements FeaturePostProcessor
List<LayerPostProcesser> postProcessers = layerPostProcessors.get(layer);
List<LayerPostProcessor> postProcessers = layerPostProcessors.get(layer);
List<VectorTile.Feature> result = makeMutable(items);
if (postProcessers != null) {
for (var handler : postProcessers) {
Expand Down Expand Up @@ -350,7 +350,7 @@ public interface OsmRelationPreprocessor extends Handler {
}

/** Handlers should implement this interface to post-process vector tile features before emitting an output layer. */
public interface LayerPostProcesser extends HandlerForLayer {
public interface LayerPostProcessor extends HandlerForLayer {

/**
* Apply any post-processing to features in this output layer of a tile before writing it to the output archive.
Expand All @@ -361,9 +361,13 @@ public interface LayerPostProcesser extends HandlerForLayer {
List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) throws GeometryException;
}

/** @deprecated use {@link LayerPostProcesser} or {@link TilePostProcessor} instead */
/** @deprecated use {@link LayerPostProcessor} instead */
@Deprecated(forRemoval = true)
public interface FeaturePostProcessor extends LayerPostProcesser {}
public interface LayerPostProcesser extends LayerPostProcessor {}

/** @deprecated use {@link LayerPostProcessor} or {@link TilePostProcessor} instead */
@Deprecated(forRemoval = true)
public interface FeaturePostProcessor extends LayerPostProcessor {}

/**
* Handlers should implement this interface to post-process all features in a vector tile before writing to an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void testFinishHandler() {
}

@Test
void testLayerPostProcesser() throws GeometryException {
void testLayerPostProcessor() throws GeometryException {
VectorTile.Feature feature = new VectorTile.Feature(
"layer",
1,
Expand All @@ -167,7 +167,7 @@ void testLayerPostProcesser() throws GeometryException {
assertEquals(List.of(feature), profile.postProcessLayerFeatures("layer", 0, List.of(feature)));

// ignore null response
profile.registerHandler(new ForwardingProfile.LayerPostProcesser() {
profile.registerHandler(new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
return null;
Expand All @@ -181,7 +181,7 @@ public String name() {
assertEquals(List.of(feature), profile.postProcessLayerFeatures("a", 0, List.of(feature)));

// allow mutations on initial input
profile.registerHandler(new ForwardingProfile.LayerPostProcesser() {
profile.registerHandler(new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
items.set(0, items.getFirst());
Expand All @@ -196,7 +196,7 @@ public String name() {
assertEquals(List.of(feature), profile.postProcessLayerFeatures("a", 0, List.of(feature)));

// empty list removes
profile.registerHandler(new ForwardingProfile.LayerPostProcesser() {
profile.registerHandler(new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
return List.of();
Expand All @@ -212,7 +212,7 @@ public String name() {
assertEquals(List.of(feature), profile.postProcessLayerFeatures("b", 0, List.of(feature)));

// allow mutations on subsequent input
profile.registerHandler(new ForwardingProfile.LayerPostProcesser() {
profile.registerHandler(new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
items.add(null);
Expand All @@ -229,7 +229,7 @@ public String name() {
assertEquals(List.of(), profile.postProcessLayerFeatures("a", 0, new ArrayList<>(List.of(feature))));

// 2 handlers for same layer run one after another
var skip1 = new ForwardingProfile.LayerPostProcesser() {
var skip1 = new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
return items.stream().skip(1).toList();
Expand All @@ -242,7 +242,7 @@ public String name() {
};
profile.registerHandler(skip1);
profile.registerHandler(skip1);
profile.registerHandler(new ForwardingProfile.LayerPostProcesser() {
profile.registerHandler(new ForwardingProfile.LayerPostProcessor() {
@Override
public List<VectorTile.Feature> postProcess(int zoom, List<VectorTile.Feature> items) {
return null; // ensure that returning null after initial post-processors run keeps the postprocessed result
Expand Down
Loading