[osmosis-dev] keyValueList option, and latest node version
Andrzej Zaborowski
andrew.zaborowski at intel.com
Tue Aug 31 17:43:18 BST 2010
From: Andrzej Zaborowski <balrog at zabor.org>
Hi Brett,
On 30 August 2010 13:15, Brett Henderson <brett at bretth.com> wrote:
> I finally got around to checking out your patch. I've just checked it
> in.
> I changed the name of the task to --flatten or --f for short because I
> don't
> believe any other tasks have filter in the name.
Thanks. Is it possible there were "filter" tasks before? I seem to
remember there were some but I may be talking about a terribly old version.
(tagfilter?)
>
> I notice that it assumes that data is sorted. Ideally it should utilise
> something like the SortedEntityPipeValidator class to ensure that data is
> sorted and to throw an error if it isn't. Do you have time to add that
> in?
The following makes it use SortedEntityPipeValidator, however
SortedEntityPipeValidator bails out immediately on multiple objects with
the same id so it doesn't work. Possibly I need a new validator, do
you want me to add that? I'm sending the patch anyway to see if you're
ok with using the validator this way.
The reason I didn't add it in the first place was that I generally trust
the data I throw at osmosis so don't want to use cycles for testing, I'm
missing a way to globally turn off creation of the validators. Each of
them adds at least a full function call per entity.
Cheers
---
.../osmosis/set/v0_6/FlattenFilter.java | 95 ++++++++++----------
1 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/set/src/org/openstreetmap/osmosis/set/v0_6/FlattenFilter.java b/set/src/org/openstreetmap/osmosis/set/v0_6/FlattenFilter.java
index e96d6c2..064bff5 100644
--- a/set/src/org/openstreetmap/osmosis/set/v0_6/FlattenFilter.java
+++ b/set/src/org/openstreetmap/osmosis/set/v0_6/FlattenFilter.java
@@ -5,47 +5,69 @@ import org.openstreetmap.osmosis.core.container.v0_6.BoundContainer;
import org.openstreetmap.osmosis.core.container.v0_6.EntityContainer;
import org.openstreetmap.osmosis.core.domain.v0_6.Entity;
import org.openstreetmap.osmosis.core.task.v0_6.Sink;
-import org.openstreetmap.osmosis.core.task.v0_6.SinkSource;
+import org.openstreetmap.osmosis.core.sort.v0_6.SortedEntityPipeValidator;
/**
* Flatten / simplify a sorted entity stream.
* (similar to --simplify-change)
*/
-public class FlattenFilter implements SinkSource {
+public class FlattenFilter extends SortedEntityPipeValidator {
private Sink sink;
private EntityContainer previousContainer;
+ private Sink flattener = new Sink() {
+ /**
+ * Process a node, way or relation.
+ *
+ * @param currentContainer
+ * The entity container to be processed.
+ */
+ @Override
+ public void process(EntityContainer currentContainer) {
+ if (previousContainer == null) {
+ previousContainer = currentContainer;
+ return;
+ }
- /**
- * Creates a new instance.
- */
- public FlattenFilter() {
- }
+ Entity current = currentContainer.getEntity();
+ Entity previous = previousContainer.getEntity();
- /**
- * Process a node, way or relation.
- *
- * @param currentContainer
- * The entity container to be processed.
- */
- public void process(EntityContainer currentContainer) {
- if (previousContainer == null) {
- previousContainer = currentContainer;
- return;
+ if (current.getId() != previous.getId() ||
+ !current.getType().equals(previous.getType())) {
+ sink.process(previousContainer);
+ previousContainer = currentContainer;
+ return;
+ }
+
+ if (current.getVersion() > previous.getVersion())
+ previousContainer = currentContainer;
}
- Entity current = currentContainer.getEntity();
- Entity previous = previousContainer.getEntity();
+ @Override
+ public void complete() {
+ /*
+ * If we've stored entities temporarily, we now need to
+ * forward the stored ones to the output.
+ */
+ if (previousContainer != null) {
+ sink.process(previousContainer);
+ }
- if (current.getId() != previous.getId() || !current.getType().equals(previous.getType())) {
- sink.process(previousContainer);
- previousContainer = currentContainer;
- return;
+ sink.complete();
}
- if (current.getVersion() > previous.getVersion()) {
- previousContainer = currentContainer;
+ @Override
+ public void release() {
+ sink.release();
}
+ };
+
+ /**
+ * Creates a new instance.
+ */
+ public FlattenFilter() {
+ super();
+ super.setSink(flattener);
}
/**
@@ -62,28 +84,7 @@ public class FlattenFilter implements SinkSource {
/**
* {@inheritDoc}
*/
- public void complete() {
- /*
- * If we've stored entities temporarily, we now need to
- * forward the stored ones to the output.
- */
- if (previousContainer != null) {
- sink.process(previousContainer);
- }
-
- sink.complete();
- }
-
- /**
- * {@inheritDoc}
- */
- public void release() {
- sink.release();
- }
-
- /**
- * {@inheritDoc}
- */
+ @Override
public void setSink(Sink sink) {
this.sink = sink;
}
--
1.5.3.4
More information about the osmosis-dev
mailing list