Package org.openstreetmap.osmosis.core.container.v0_6

Examples of org.openstreetmap.osmosis.core.container.v0_6.EntityContainer


   * Processes the input sources and sends the changes to the change sink.
   */
  public void run() {
    try {
      EntityContainerComparator comparator;
      EntityContainer fromEntityContainer = null;
      EntityContainer toEntityContainer = null;
      TimestampSetter timestampSetter;
     
      // Create a comparator for comparing two entities by type and identifier.
      comparator = new EntityContainerComparator(new EntityByTypeThenIdComparator());
     
      // Create an object for setting the current timestamp on entities being deleted.
      timestampSetter = new TimestampSetter();
     
      // We can't get meaningful data from the initialize data on the
      // input streams, so pass empty meta data to the sink and discard
      // the input meta data.
      fromPostbox.outputInitialize();
      toPostbox.outputInitialize();
      changeSink.initialize(Collections.<String, Object>emptyMap());
     
      // We continue in the comparison loop while both sources still have data.
      while (
          (fromEntityContainer != null || fromPostbox.hasNext())
          && (toEntityContainer != null || toPostbox.hasNext())) {
        int comparisonResult;
       
        // Get the next input data where required.
        if (fromEntityContainer == null) {
          fromEntityContainer = fromPostbox.getNext();
        }
        if (toEntityContainer == null) {
          toEntityContainer = toPostbox.getNext();
        }
       
        // Compare the two sources.
        comparisonResult = comparator.compare(fromEntityContainer, toEntityContainer);
       
        if (comparisonResult < 0) {
          // The from entity doesn't exist on the to source therefore
          // has been deleted. We don't know when the entity was
          // deleted so set the delete time to the current time.
          changeSink.process(
              new ChangeContainer(
                  timestampSetter.updateTimestamp(fromEntityContainer),
                  ChangeAction.Delete));
          fromEntityContainer = null;
        } else if (comparisonResult > 0) {
          // The to entity doesn't exist on the from source therefore has
          // been created.
          changeSink.process(new ChangeContainer(toEntityContainer, ChangeAction.Create));
          toEntityContainer = null;
        } else {
          // The entity exists on both sources, therefore we must
          // compare
          // the entities directly. If there is a difference, the
          // entity has been modified.
          if (!fromEntityContainer.getEntity().equals(toEntityContainer.getEntity())) {
            changeSink.process(new ChangeContainer(toEntityContainer, ChangeAction.Modify));
          }
          fromEntityContainer = null;
          toEntityContainer = null;
        }
View Full Code Here


    // Deleted entities are not visible, all others are.
    boolean visible = (ChangeAction.Delete != change.getAction());
   
    // Set a visible meta-tag on the entity because the Osmosis data model
    // doesn't natively support visible.
    EntityContainer entityContainer = change.getEntityContainer().getWriteableInstance();
    entityContainer.getEntity().getMetaTags().put("visible", visible);
   
    sink.process(entityContainer);
  }
View Full Code Here

      user = anonymousUser;
    }
   
    // Increment the relevant user statistic.
    entityContainer.process(
      new EntityProcessor() {
        private UserStatistics processorUser = user;
       
        public void process(BoundContainer bound) {
          // Do nothing.
        }
View Full Code Here

                }
                SimpleFeature feature = featureBuilder.buildFeature(ref.name());
                Entity entity = converter.toEntity(feature, id);
                EntityContainer container;
                if (entity instanceof Node) {
                    container = new NodeContainer((Node) entity);
                } else {
                    container = new WayContainer((Way) entity);
                }

                ChangeAction action = diff.changeType().equals(ChangeType.ADDED) ? ChangeAction.Create
View Full Code Here

                }
                SimpleFeature feature = featureBuilder.buildFeature(ref.name());
                Entity entity = converter.toEntity(feature, null);
                EntityContainer container;
                if (entity instanceof Node) {
                    container = new NodeContainer((Node) entity);
                } else {
                    container = new WayContainer((Way) entity);
                }

                return container;
View Full Code Here

        }

        while (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {     
          // Node, way, relation
          if (reader.getLocalName().equals(ELEMENT_NAME_NODE)) {
            sink.process(new NodeContainer(readNode()));
          } else if (reader.getLocalName().equals(ELEMENT_NAME_WAY)) {
            sink.process(new WayContainer(readWay()));
          } else if (reader.getLocalName().equals(ELEMENT_NAME_RELATION)) {
            sink.process(new RelationContainer(readRelation()));
          } else {
View Full Code Here

  @Test
  public void computeBoundNoUpstreamBound() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundComputer bc = new BoundComputer("NewBound");
    bc.setSink(inspector);
    bc.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    bc.process(new NodeContainer(new Node(new CommonEntityData(2, 2, new Date(), OsmUser.NONE, 1), 2, 2)));
    bc.complete();
    bc.release();

    EntityContainer ec = inspector.getProcessedEntities().iterator().next();
    Assert.assertEquals(new Bound(2, 1, 2, 1, "NewBound"), ec.getEntity());
View Full Code Here

  @Test
  public void computeBoundWithUpstreamBound() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundComputer bc = new BoundComputer("NewBound");
    bc.setSink(inspector);
    bc.process(new NodeContainer(new Node(new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    bc.process(new NodeContainer(new Node(new CommonEntityData(2, 2, new Date(), OsmUser.NONE, 1), 2, 2)));
    bc.complete();
    bc.release();

    Iterator<EntityContainer> iterator = inspector.getProcessedEntities().iterator();
    EntityContainer ec = iterator.next();
View Full Code Here

  public void removeExistingBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundSetter setter = new BoundSetter(null);
    setter.setSink(inspector);
    setter.process(new BoundContainer(new Bound("Test")));
    setter.process(new NodeContainer(new Node(
        new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    setter.complete();
    setter.release();
   
    EntityContainer ec = inspector.getProcessedEntities().iterator().next();
View Full Code Here

  @Test
  public void removeNoBoundTest() {
    SinkEntityInspector inspector = new SinkEntityInspector();
    BoundSetter setter = new BoundSetter(null);
    setter.setSink(inspector);
    setter.process(new NodeContainer(new Node(
        new CommonEntityData(1, 1, new Date(), OsmUser.NONE, 1), 1, 1)));
    setter.complete();
    setter.release();
   
    EntityContainer ec = inspector.getProcessedEntities().iterator().next();
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.core.container.v0_6.EntityContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.