Ignore:
Timestamp:
2010-11-01T02:37:25+01:00 (14 years ago)
Author:
oliverw
Message:
  • Added comments
  • Invalidate model on container changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressEditContainer.java

    r23967 r23979  
    5454
    5555/**
    56  * Provides a container serving streets and unresolved/incomplete addresses.
     56 * Provides a container serving streets and unresolved/incomplete addresses. It scans through a
     57 * set of OSM primitives and checks for incomplete addresses (e. g. missing addr:... tags) or
     58 * addresses with unknown streets ("unresolved addresses").
     59 *
     60 * It listens to changes within instances of {@link INodeEntity} to notify clients on update.
     61 *
     62 * {@link AddressEditContainer} is the central class used within actions and UI models to show
     63 * and alter OSM data.
     64 *
     65 * {@see AbstractAddressEditAction}
     66 * {@see AddressEditTableModel}
     67 * 
    5768 * @author Oliver Wieland <oliver.wieland@online.de>
    5869 *
     
    6071
    6172public class AddressEditContainer implements Visitor, DataSetListener, IAddressEditContainerListener {
    62         private HashMap<String, StreetNode> streetDict = new HashMap<String, StreetNode>(100);
     73       
     74        /** The street dictionary collecting all streets to a set of unique street names. */
     75        private HashMap<String, StreetNode> streetDict = new HashMap<String, StreetNode>(100);
     76       
     77        /** The unresolved addresses list. */
    6378        private List<AddressNode> unresolvedAddresses = new ArrayList<AddressNode>(100);
     79       
     80        /** The incomplete addresses list. */
    6481        private List<AddressNode> incompleteAddresses = new ArrayList<AddressNode>(100);
    6582       
    66         private HashMap<String, StreetNode> shadowStreetDict = new HashMap<String, StreetNode>(100);
     83        /** The shadow copy to assemble the street dict during update. */
     84        private HashMap<String, StreetNode> shadowStreetDict = new HashMap<String, StreetNode>(100);
     85        /** The shadow copy to assemble the unresolved addresses during update. */
    6786        private List<AddressNode> shadowUnresolvedAddresses = new ArrayList<AddressNode>(100);
     87        /** The shadow copy to assemble the incomplete addresses during update. */
    6888        private List<AddressNode> shadowIncompleteAddresses = new ArrayList<AddressNode>(100);
    6989       
     90        /** The visited nodes cache to increase iteration spped. */
    7091        private HashSet<Node> visitedNodes = new HashSet<Node>();
    71         private HashSet<Way> visitedWays = new HashSet<Way>();
     92        /** The visited ways cache to increase iteration spped. */
     93        private HashSet<Way> visitedWays = new HashSet<Way>(); 
     94        /** The tag list used within the data area. */
    7295        private HashSet<String> tags = new HashSet<String>();
    7396       
     97        /** The change listeners. */
    7498        private List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>();
    7599       
    76100        /**
    77          *
     101         * Creates an empty container.
    78102         */
    79103        public AddressEditContainer() {
     
    109133        }
    110134       
     135        /**
     136         * Marks an OSM node as visited.
     137         *
     138         * @param n the node to mark.
     139         */
    111140        private void markNodeAsVisited(Node n) {
    112141                visitedNodes.add(n);
    113142        }
    114143       
     144        /**
     145         * Checks a node for been visited.
     146         *
     147         * @param n the n
     148         * @return true, if successful
     149         */
    115150        private boolean hasBeenVisited(Node n) {
    116151                return visitedNodes.contains(n);
    117152        }
    118153       
     154        /**
     155         * Marks a way as visited.
     156         *
     157         * @param w the way to mark
     158         */
    119159        private void markWayAsVisited(Way w) {
    120160                visitedWays.add(w);
     
    171211        }
    172212
    173 
     213        /**
     214         * Adds and classify an address node according to completeness.
     215         *
     216         * @param aNode the address node to add and check
     217         */
    174218        private void addAndClassifyAddress(AddressNode aNode) {
    175219                if (!assignAddressToStreet(aNode)) {
     
    182226                }
    183227        }
    184        
    185228
    186229        /**
    187230         * Creates the node from an OSM way instance.
    188231         *
    189          * @param w the w
     232         * @param w the way to create the entity from
    190233         */
    191234        private void createNodeFromWay(Way w) {
     
    210253
    211254        /**
    212          * Process a entity node.
     255         * Process an entity node depending on the type. A street segment is added as a child to the
     256         * corresponding street dictionary while an address is added to the incomplete/unresolved list
     257         * depending of it's properties.
    213258         *
    214259         * @param ne the entity node.
     
    411456       
    412457        /**
    413          * Rebuilds the street and address lists.
     458         * Rebuilds the street and address lists using the current data set.
    414459         */
    415460        public void invalidate() {
     
    417462        }
    418463       
     464        /**
     465         * Invalidate using the given data collection.
     466         *
     467         * @param osmData the collection containing the osm data to work on.
     468         */
    419469        public void invalidate(final Collection<? extends OsmPrimitive> osmData) {
    420470                if (osmData == null || osmData.isEmpty())
     
    445495        }
    446496       
    447         public void clearData() {
     497        /**
     498         * Clears the shadowed lists data and resets the 'visited' flag for every OSM object.
     499         */
     500        private void clearData() {
    448501                shadowStreetDict.clear();
    449502                shadowUnresolvedAddresses.clear();
     
    455508        /**
    456509         * Connects the listener to the data set and revisits the data. This method should
    457          * be called immediately before an edit session starts.
     510         * be called immediately after an edit session finished.
     511         *
     512         * <code>
     513         * detachFromDataSet();
     514         * //... launch dialog or whatever
     515         * attachToDataSet();
     516         * </code>
    458517         */
    459518        public void attachToDataSet(Collection<? extends OsmPrimitive> dataToExamine) {         
     
    468527        /**
    469528         * Disconnects the listener from the data set. This method should
    470          * be called immediately after an edit session has ended.
     529         * be called immediately before an edit session started in order to
     530         * prevent updates caused by e. g. a selection change within the map view.
    471531         */
    472532        public void detachFromDataSet() {
     
    474534        }
    475535
     536        /* (non-Javadoc)
     537         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent)
     538         */
    476539        @Override
    477540        public void dataChanged(DataChangedEvent event) {
    478541        }
    479542
     543        /* (non-Javadoc)
     544         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent)
     545         */
    480546        @Override
    481547        public void nodeMoved(NodeMovedEvent event) {
     
    483549        }
    484550
     551        /* (non-Javadoc)
     552         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent)
     553         */
    485554        @Override
    486555        public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    487556        }
    488557
     558        /* (non-Javadoc)
     559         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primtivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent)
     560         */
    489561        @Override
    490562        public void primtivesAdded(PrimitivesAddedEvent event) {
     
    492564        }
    493565
     566        /* (non-Javadoc)
     567         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primtivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent)
     568         */
    494569        @Override
    495570        public void primtivesRemoved(PrimitivesRemovedEvent event) {
     
    497572        }
    498573
     574        /* (non-Javadoc)
     575         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent)
     576         */
    499577        @Override
    500578        public void relationMembersChanged(RelationMembersChangedEvent event) {
    501579        }
    502580
     581        /* (non-Javadoc)
     582         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent)
     583         */
    503584        @Override
    504585        public void tagsChanged(TagsChangedEvent event) {
     
    506587        }
    507588
     589        /* (non-Javadoc)
     590         * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent)
     591         */
    508592        @Override
    509593        public void wayNodesChanged(WayNodesChangedEvent event) {
    510594        }
    511595
     596        /* (non-Javadoc)
     597         * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
     598         */
    512599        @Override
    513600        public void containerChanged(AddressEditContainer container) {
    514                
    515         }
    516 
     601                invalidate();
     602        }
     603
     604        /* (non-Javadoc)
     605         * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.INodeEntity)
     606         */
    517607        @Override
    518608        public void entityChanged(INodeEntity entity) {
Note: See TracChangeset for help on using the changeset viewer.