Changeset 30348 in osm for applications


Ignore:
Timestamp:
2014-03-24T21:51:44+01:00 (11 years ago)
Author:
donvip
Message:

[josm_fixaddresses] code cleanup

Location:
applications/editors/josm/plugins/FixAddresses
Files:
1 deleted
47 edited

Legend:

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

    r29967 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
    14 
    15 /* File created on 24.10.2010 */
     1// License: GPL. For details, see LICENSE file.
    162package org.openstreetmap.josm.plugins.fixAddresses;
    173
     
    5743 *
    5844 */
    59 
    6045public class AddressEditContainer implements Visitor, DataSetListener, IAddressEditContainerListener, IProblemVisitor, IAllKnowingTrashHeap {
    6146
    62         private Collection<? extends OsmPrimitive> workingSet;
    63         /** The street dictionary collecting all streets to a set of unique street names. */
    64         private HashMap<String, OSMStreet> streetDict = new HashMap<String, OSMStreet>(100);
    65 
    66         /** The unresolved (addresses without valid street name) addresses list. */
    67         private List<OSMAddress> unresolvedAddresses = new ArrayList<OSMAddress>(100);
    68 
    69         /** The incomplete addresses list. */
    70         private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>(100);
    71 
    72         /** The shadow copy to assemble the street dict during update. */
    73         private HashMap<String, OSMStreet> shadowStreetDict = new HashMap<String, OSMStreet>(100);
    74         /** The shadow copy to assemble the unresolved addresses during update. */
    75         private List<OSMAddress> shadowUnresolvedAddresses = new ArrayList<OSMAddress>(100);
    76         /** The shadow copy to assemble the incomplete addresses during update. */
    77         private List<OSMAddress> shadowIncompleteAddresses = new ArrayList<OSMAddress>(100);
    78 
    79         /** The visited nodes cache to increase iteration speed. */
    80         private HashSet<Node> visitedNodes = new HashSet<Node>();
    81         /** The visited ways cache to increase iteration speed. */
    82         private HashSet<Way> visitedWays = new HashSet<Way>();
    83         /** The tag list used within the data area. */
    84         private HashSet<String> tags = new HashSet<String>();
    85         /** The tag list used within the data area. */
    86         private HashMap<String, String> values = new HashMap<String, String>();
    87 
    88         /** The list containing the problems */
    89         private List<IProblem> problems = new ArrayList<IProblem>();
    90 
    91         /** The change listeners. */
    92         private List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>();
    93 
    94         /**
    95          * Creates an empty container.
    96          */
    97         public AddressEditContainer() {
    98                 OSMEntityBase.addChangedListener(this);
    99         }
    100 
    101         /**
    102          * Gets the working set used by the container. This can by either the complete or just
    103          * a subset of the current data layer.
    104          *
    105          * @return the workingSet
    106          */
    107         protected Collection<? extends OsmPrimitive> getWorkingSet() {
    108                 return workingSet;
    109         }
    110 
    111         /**
    112          * Adds a change listener.
    113          * @param listener
    114          */
    115         public void addChangedListener(IAddressEditContainerListener listener) {
    116                 listeners.add(listener);
    117         }
    118 
    119         /**
    120          * Removes a change listener.
    121          * @param listener
    122          */
    123         public void removeChangedListener(IAddressEditContainerListener listener) {
    124                 listeners.remove(listener);
    125         }
    126 
    127         /**
    128          * Notifies clients that the address container changed.
    129          */
    130         protected void fireContainerChanged() {
    131                 List<IAddressEditContainerListener> shadowListeners =
    132                         new ArrayList<IAddressEditContainerListener>(listeners);
    133 
    134                 for (IAddressEditContainerListener listener : shadowListeners) {
    135                         listener.containerChanged(this);
    136                 }
    137         }
    138 
    139         /**
    140          * Notifies clients that an entity within the address container changed.
    141          */
    142         protected void fireEntityChanged(IOSMEntity entity) {
    143                 if (entity == null) throw new RuntimeException("Entity must not be null");
    144 
    145                 List<IAddressEditContainerListener> shadowListeners =
    146                         new ArrayList<IAddressEditContainerListener>(listeners);
    147 
    148                 for (IAddressEditContainerListener listener : shadowListeners) {
    149                         listener.entityChanged(entity);
    150                 }
    151         }
    152 
    153         /**
    154          * Marks an OSM node as visited.
    155          *
    156          * @param n the node to mark.
    157          */
    158         private void markNodeAsVisited(Node n) {
    159                 visitedNodes.add(n);
    160         }
    161 
    162         /**
    163          * Checks a node for been visited.
    164          *
    165          * @param n the n
    166          * @return true, if node has been visited
    167          */
    168         private boolean hasBeenVisited(Node n) {
    169                 return visitedNodes.contains(n);
    170         }
    171 
    172         /**
    173          * Marks a way as visited.
    174          *
    175          * @param w the way to mark
    176          */
    177         private void markWayAsVisited(Way w) {
    178                 visitedWays.add(w);
    179         }
    180 
    181         /**
    182          * Checks a way for been visited.
    183          *
    184          * @param w the w to check
    185          * @return true, if way has been visited
    186          */
    187         private boolean hasBeenVisited(Way w) {
    188                 return visitedWays.contains(w);
    189         }
    190 
    191         /* (non-Javadoc)
    192          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Node)
    193          */
    194         @Override
    195         public void visit(Node n) {
    196                 if (hasBeenVisited(n)) {
    197                         return;
    198                 }
    199 
    200                 OSMAddress aNode = null;
    201                 // Address nodes are recycled in order to keep instance variables like guessed names
    202                 aNode = OsmFactory.createNode(n);
    203 
    204                 if (aNode != null) {
    205                         addAndClassifyAddress(aNode);
    206                         aNode.visit(this, this);
    207                 }
    208                 markNodeAsVisited(n);
    209         }
    210 
    211         /* (non-Javadoc)
    212          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way)
    213          */
    214         @Override
    215         public void visit(Way w) {
    216                 // This doesn't matter, we just need the street name
    217                 //if (w.isIncomplete()) return;
    218 
    219                 if (hasBeenVisited(w)) {
    220                         return;
    221                 }
    222 
    223                 createNodeFromWay(w);
    224                 markWayAsVisited(w);
    225         }
    226 
    227         /**
    228          * Adds and classify an address node according to completeness.
    229          *
    230          * @param aNode the address node to add and check
    231          */
    232         private void addAndClassifyAddress(OSMAddress aNode) {
    233                 if (!assignAddressToStreet(aNode)) {
    234                         // Assignment failed: Street is not known (yet) -> add to 'unresolved' list
    235                         shadowUnresolvedAddresses.add(aNode);
    236                 }
    237 
    238                 if (!aNode.isComplete()) {
    239                         shadowIncompleteAddresses.add(aNode);
    240                 }
    241         }
    242 
    243         /**
    244          * Creates the node from an OSM way instance.
    245          *
    246          * @param w the way to create the entity from
    247          */
    248         private void createNodeFromWay(Way w) {
    249                 IOSMEntity ne = OsmFactory.createNodeFromWay(w);
    250 
    251                 if (!processNode(ne, w)) {
    252                         // Look also into nodes for addresses (unlikely, but at least they
    253                         // get marked as visited).
    254                         for (Node n : w.getNodes()) {
    255                                 visit(n);
    256                         }
    257 
    258                         for (String key : w.keySet()) {
    259                                 if (!tags.contains(key)) {
    260                                         tags.add(key);
    261                                 }
    262 
    263                                 String v = w.get(key);
    264                                 if (!values.containsKey(v)) {
    265                                         values.put(v, key);
    266                                 }
    267                         }
    268                 } // else: node has been processed, no need to look deeper
    269         }
    270 
    271         /**
    272          * Process an entity node depending on the type. A street segment is added as a child to the
    273          * corresponding street dictionary while an address is added to the incomplete/unresolved list
    274          * depending of it's properties.
    275          *
    276          * @param ne the entity node.
    277          * @param w the corresponding OSM way
    278          * @return true, if node has been processed
    279          */
    280         private boolean processNode(IOSMEntity ne, Way w) {
    281                 if (ne != null) {
    282                         // Node is a street (segment)
    283                         if (ne instanceof OSMStreetSegment) {
    284                                 OSMStreetSegment newSegment = (OSMStreetSegment) ne;
    285 
    286                                 if (newSegment != null) {
    287                                         String name = newSegment.getName();
    288                                         if (StringUtils.isNullOrEmpty(name)) return false;
    289 
    290                                         OSMStreet sNode = null;
    291                                         if (shadowStreetDict.containsKey(name)) { // street exists?
    292                                                 sNode = shadowStreetDict.get(name);
    293                                         } else { // new street name -> add to dict
    294                                                 sNode = new OSMStreet(w);
    295                                                 shadowStreetDict.put(name, sNode);
    296                                         }
    297 
    298                                         if (sNode != null) {
    299                                                 // TODO: Check if segment really belongs to the street, even if the
    300                                                 // names are the same. Then the streets should be split up...
    301                                                 sNode.addStreetSegment(newSegment);
    302                                                 return true;
    303                                         } else {
    304                                                 throw new RuntimeException("Street node is null!");
    305                                         }
    306                                 }
    307                         }
    308 
    309                         // Node is an address
    310                         if (ne instanceof OSMAddress) {
    311                                 OSMAddress aNode = (OSMAddress) ne;
    312                                 addAndClassifyAddress(aNode);
    313                                 return true;
    314                         }
    315                 }
    316                 return false;
    317         }
    318 
    319         /* (non-Javadoc)
    320          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Relation)
    321          */
    322         @Override
    323         public void visit(Relation e) {
    324         }
    325 
    326         /* (non-Javadoc)
    327          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Changeset)
    328          */
    329         @Override
    330         public void visit(Changeset cs) {
    331         }
    332 
    333         /**
    334          * Gets the dictionary contains the collected streets.
    335          * @return
    336          */
    337         public HashMap<String, OSMStreet> getStreetDict() {
    338                 return streetDict;
    339         }
    340 
    341         /**
    342          * Gets the unresolved (addresses without valid street name) addresses.
    343          *
    344          * @return the unresolved addresses
    345          */
    346         public List<OSMAddress> getUnresolvedAddresses() {
    347                 return unresolvedAddresses;
    348         }
    349 
    350         /**
    351          * Gets the list with incomplete addresses.
    352          *
    353          * @return the incomplete addresses
    354          */
    355         public List<OSMAddress> getIncompleteAddresses() {
    356                 return incompleteAddresses;
    357         }
    358 
    359         /**
    360          * Gets the street list.
    361          *
    362          * @return the street list
    363          */
    364         public List<OSMStreet> getStreetList() {
    365                 ArrayList<OSMStreet> sortedList = new ArrayList<OSMStreet>(streetDict.values());
    366                 Collections.sort(sortedList);
    367                 return sortedList;
    368         }
    369 
    370         /**
    371          * Gets all addresses without valid street.
    372          * @return
    373          */
    374         public List<OSMAddress> getUnresolvedItems() {
    375                 return unresolvedAddresses;
    376         }
    377 
    378         /**
    379          * Gets the tags used in the data layer.
    380          * @return
    381          */
    382         public HashSet<String> getTags() {
    383                 return tags;
    384         }
    385 
    386         /**
    387          * @return the values
    388          */
    389         protected HashMap<String, String> getValues() {
    390                 return values;
    391         }
    392 
    393         /**
    394          * Gets the number of streets in the container.
    395          * @return
    396          */
    397         public int getNumberOfStreets() {
    398                 return streetDict != null ? streetDict.size() : 0;
    399         }
    400 
    401         /**
    402          * Get the number of incomplete addresses.
    403          * @return
    404          */
    405         public int getNumberOfIncompleteAddresses() {
    406                 return incompleteAddresses != null ? incompleteAddresses.size() : 0;
    407         }
    408 
    409         /**
    410          * Gets the number of unresolved addresses.
    411          * @return
    412          */
    413         public int getNumberOfUnresolvedAddresses() {
    414                 return unresolvedAddresses != null ? unresolvedAddresses.size() : 0;
    415         }
    416 
    417         /**
    418          * Gets the number of invalid (unresolved and/or incomplete) addresses.
    419          *
    420          * @return the number of invalid addresses
    421          */
    422         public int getNumberOfInvalidAddresses() {
    423                 return getNumberOfIncompleteAddresses() + getNumberOfUnresolvedAddresses();
    424         }
    425 
    426         /**
    427          * Gets the number of guessed tags.
    428          * @return
    429          */
    430         public int getNumberOfGuesses() {
    431                 int sum = 0;
    432 
    433                 for (OSMAddress aNode : getAllAddressesToFix()) {
    434                         if (aNode.hasGuesses()) {
    435                                 sum++;
    436                         }
    437                 }
    438                 return sum;
    439         }
    440 
    441         /**
    442          * Gets all (incomplete and/or unresolved) address nodes to fix.
    443          * @return
    444          */
    445         public List<OSMAddress> getAllAddressesToFix() {
    446                 List<OSMAddress> all = new ArrayList<OSMAddress>(incompleteAddresses);
    447 
    448                 for (OSMAddress aNode : unresolvedAddresses) {
    449                         if (!all.contains(aNode)) {
    450                                 all.add(aNode);
    451                         }
    452                 }
    453 
    454                 return all;
    455         }
    456 
    457         /**
    458          * @return the problems
    459          */
    460         protected List<IProblem> getProblems() {
    461                 return problems;
    462         }
    463 
    464         /**
    465          * Clears the problem list.
    466          */
    467         protected void clearProblems() {
    468                 problems.clear();
    469         }
    470 
    471         /**
    472          * Tries to assign an address to a street.
    473          * @param aNode
    474          */
    475         private boolean assignAddressToStreet(OSMAddress aNode) {
    476                 String streetName = aNode.getStreetName();
    477 
    478                 // street name via relation -> implicitly resolved (see TRAC #8336)
    479                 if (aNode.isPartOfRelation()) {
    480                     return true;
    481                 }
    482                
    483                 if (streetName != null && shadowStreetDict.containsKey(streetName)) {
    484                         OSMStreet sNode = shadowStreetDict.get(streetName);
    485                         sNode.addAddress(aNode);
    486                         return true;
    487                 }
    488 
    489                 return false;
    490         }
    491 
    492         /**
    493          * Walks through the list of unassigned addresses and tries to assign them to streets.
    494          */
    495         public void resolveAddresses() {
    496                 List<OSMAddress> resolvedAddresses = new ArrayList<OSMAddress>();
    497                 for (OSMAddress node : shadowUnresolvedAddresses) {
    498                         if (assignAddressToStreet(node)) {
    499                                 resolvedAddresses.add(node);
    500                         }
    501                 }
    502 
    503                 /* Remove all resolves nodes from unresolved list */
    504                 for (OSMAddress resolved : resolvedAddresses) {
    505                         shadowUnresolvedAddresses.remove(resolved);
    506                 }
    507         }
    508 
    509         /**
    510          * Rebuilds the street and address lists using the data set given
    511          * in  {@link AddressEditContainer#attachToDataSet(Collection)} or the
    512          * full data set of the current data layer {@link Main#getCurrentDataSet()}.
    513          */
    514         public void invalidate() {
    515                 if (workingSet != null) {
    516                         invalidate(workingSet);
    517                 } else {
    518                         if (Main.main.getCurrentDataSet() != null) {
    519                                 invalidate(Main.main.getCurrentDataSet().allPrimitives());
    520                         }
    521                 }
    522         }
    523 
    524         /**
    525          * Invalidate using the given data collection.
    526          *
    527          * @param osmData the collection containing the osm data to work on.
    528          */
    529         public void invalidate(final Collection<? extends OsmPrimitive> osmData) {
    530                 if (osmData == null || osmData.isEmpty())
    531                         return;
    532 
    533                 synchronized (this) {
    534                         clearData();
    535                         clearProblems();
    536                         // visit data set for problems...
    537                         for (OsmPrimitive osmPrimitive : osmData) {
    538                                 if (osmPrimitive.isUsable()) {
    539                                         osmPrimitive.accept(this);
    540                                 }
    541                         }
    542                        
    543                         // match streets with addresses...
    544                         resolveAddresses();
    545                         // sort problem lists
    546                         Collections.sort(shadowIncompleteAddresses);
    547                         Collections.sort(shadowUnresolvedAddresses);
    548 
    549                         // put results from shadow copy into real lists
    550                         incompleteAddresses = new ArrayList<OSMAddress>(shadowIncompleteAddresses);
    551                         unresolvedAddresses = new ArrayList<OSMAddress>(shadowUnresolvedAddresses);
    552                         streetDict = new HashMap<String, OSMStreet>(shadowStreetDict);
    553                         // remove temp data
    554                         shadowStreetDict.clear();
    555                         shadowUnresolvedAddresses.clear();
    556                         shadowIncompleteAddresses.clear();
    557 
    558                         // update clients
    559                         fireContainerChanged();
    560                 }
    561         }
    562 
    563         /**
    564          * Clears the shadowed lists data and resets the 'visited' flag for every OSM object.
    565          */
    566         private void clearData() {
    567                 shadowStreetDict.clear();
    568                 shadowUnresolvedAddresses.clear();
    569                 shadowIncompleteAddresses.clear();
    570                 visitedNodes.clear();
    571                 visitedWays.clear();
    572         }
    573 
    574         /**
    575          * Connects the listener to the given data set and revisits the data. This method should
    576          * be called immediately after an edit session finished.
    577          *
    578          * If the given data set is not null, calls of {@link AddressEditContainer#invalidate()} will
    579          * only consider the data given within this set. This can be useful to keep out unimportant
    580          * areas. However, a side-effect could be that some streets are not included and leads to
    581          * false alarms regarding unresolved addresses.
    582          *
    583          * Calling {@link AddressEditContainer#detachFromDataSet()} drops the explicit data set and uses
    584          * the full data set on subsequent updates.<p>
    585          *
    586          * <b>Example</b><br>
    587          * <code>
    588          * attachToDataSet(osmDataSetToWorkOn); // osmDataSetToWorkOn = selected items<br>
    589          * //... launch dialog or whatever<br>
    590          * detachFromDataSet();
    591          * </code>
    592          *
    593          * @param osmDataToWorkOn the data to examine
    594          */
    595         public void attachToDataSet(Collection<? extends OsmPrimitive> osmDataToWorkOn) {
    596                 if (osmDataToWorkOn != null && !osmDataToWorkOn.isEmpty()) {
    597                         workingSet = new ArrayList<OsmPrimitive>(osmDataToWorkOn);
    598                 } else {
    599                         detachFromDataSet(); // drop old stuff, if present
    600                 }
    601                 invalidate(); // start our investigation...
    602         }
    603 
    604         /**
    605          * Disconnects the listener from the data set. This method should
    606          * be called immediately before an edit session started in order to
    607          * prevent updates caused by e. g. a selection change within the map view.
    608          */
    609         public void detachFromDataSet() {
    610                 //Main.main.getCurrentDataSet().removeDataSetListener(this);
    611                 if (workingSet != null) {
    612                         workingSet.clear();
    613                         workingSet = null;
    614                 }
    615         }
    616 
    617         /* (non-Javadoc)
    618          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent)
    619          */
    620         @Override
    621         public void dataChanged(DataChangedEvent event) {
    622         }
    623 
    624         /* (non-Javadoc)
    625          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent)
    626          */
    627         @Override
    628         public void nodeMoved(NodeMovedEvent event) {
    629 
    630         }
    631 
    632         /* (non-Javadoc)
    633          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent)
    634          */
    635         @Override
    636         public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    637         }
    638 
    639         /* (non-Javadoc)
    640          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent)
    641          */
     47    private Collection<? extends OsmPrimitive> workingSet;
     48    /** The street dictionary collecting all streets to a set of unique street names. */
     49    private HashMap<String, OSMStreet> streetDict = new HashMap<String, OSMStreet>(100);
     50
     51    /** The unresolved (addresses without valid street name) addresses list. */
     52    private List<OSMAddress> unresolvedAddresses = new ArrayList<OSMAddress>(100);
     53
     54    /** The incomplete addresses list. */
     55    private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>(100);
     56
     57    /** The shadow copy to assemble the street dict during update. */
     58    private HashMap<String, OSMStreet> shadowStreetDict = new HashMap<String, OSMStreet>(100);
     59    /** The shadow copy to assemble the unresolved addresses during update. */
     60    private List<OSMAddress> shadowUnresolvedAddresses = new ArrayList<OSMAddress>(100);
     61    /** The shadow copy to assemble the incomplete addresses during update. */
     62    private List<OSMAddress> shadowIncompleteAddresses = new ArrayList<OSMAddress>(100);
     63
     64    /** The visited nodes cache to increase iteration speed. */
     65    private HashSet<Node> visitedNodes = new HashSet<Node>();
     66    /** The visited ways cache to increase iteration speed. */
     67    private HashSet<Way> visitedWays = new HashSet<Way>();
     68    /** The tag list used within the data area. */
     69    private HashSet<String> tags = new HashSet<String>();
     70    /** The tag list used within the data area. */
     71    private HashMap<String, String> values = new HashMap<String, String>();
     72
     73    /** The list containing the problems */
     74    private List<IProblem> problems = new ArrayList<IProblem>();
     75
     76    /** The change listeners. */
     77    private List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>();
     78
     79    /**
     80     * Creates an empty container.
     81     */
     82    public AddressEditContainer() {
     83        OSMEntityBase.addChangedListener(this);
     84    }
     85
     86    /**
     87     * Gets the working set used by the container. This can by either the complete or just
     88     * a subset of the current data layer.
     89     *
     90     * @return the workingSet
     91     */
     92    protected Collection<? extends OsmPrimitive> getWorkingSet() {
     93        return workingSet;
     94    }
     95
     96    /**
     97     * Adds a change listener.
     98     * @param listener
     99     */
     100    public void addChangedListener(IAddressEditContainerListener listener) {
     101        listeners.add(listener);
     102    }
     103
     104    /**
     105     * Removes a change listener.
     106     * @param listener
     107     */
     108    public void removeChangedListener(IAddressEditContainerListener listener) {
     109        listeners.remove(listener);
     110    }
     111
     112    /**
     113     * Notifies clients that the address container changed.
     114     */
     115    protected void fireContainerChanged() {
     116        List<IAddressEditContainerListener> shadowListeners =
     117            new ArrayList<IAddressEditContainerListener>(listeners);
     118
     119        for (IAddressEditContainerListener listener : shadowListeners) {
     120            listener.containerChanged(this);
     121        }
     122    }
     123
     124    /**
     125     * Notifies clients that an entity within the address container changed.
     126     */
     127    protected void fireEntityChanged(IOSMEntity entity) {
     128        if (entity == null) throw new RuntimeException("Entity must not be null");
     129
     130        List<IAddressEditContainerListener> shadowListeners =
     131            new ArrayList<IAddressEditContainerListener>(listeners);
     132
     133        for (IAddressEditContainerListener listener : shadowListeners) {
     134            listener.entityChanged(entity);
     135        }
     136    }
     137
     138    /**
     139     * Marks an OSM node as visited.
     140     *
     141     * @param n the node to mark.
     142     */
     143    private void markNodeAsVisited(Node n) {
     144        visitedNodes.add(n);
     145    }
     146
     147    /**
     148     * Checks a node for been visited.
     149     *
     150     * @param n the n
     151     * @return true, if node has been visited
     152     */
     153    private boolean hasBeenVisited(Node n) {
     154        return visitedNodes.contains(n);
     155    }
     156
     157    /**
     158     * Marks a way as visited.
     159     *
     160     * @param w the way to mark
     161     */
     162    private void markWayAsVisited(Way w) {
     163        visitedWays.add(w);
     164    }
     165
     166    /**
     167     * Checks a way for been visited.
     168     *
     169     * @param w the w to check
     170     * @return true, if way has been visited
     171     */
     172    private boolean hasBeenVisited(Way w) {
     173        return visitedWays.contains(w);
     174    }
     175
     176    @Override
     177    public void visit(Node n) {
     178        if (hasBeenVisited(n)) {
     179            return;
     180        }
     181
     182        OSMAddress aNode = null;
     183        // Address nodes are recycled in order to keep instance variables like guessed names
     184        aNode = OsmFactory.createNode(n);
     185
     186        if (aNode != null) {
     187            addAndClassifyAddress(aNode);
     188            aNode.visit(this, this);
     189        }
     190        markNodeAsVisited(n);
     191    }
     192
     193    @Override
     194    public void visit(Way w) {
     195        // This doesn't matter, we just need the street name
     196        //if (w.isIncomplete()) return;
     197
     198        if (hasBeenVisited(w)) {
     199            return;
     200        }
     201
     202        createNodeFromWay(w);
     203        markWayAsVisited(w);
     204    }
     205
     206    /**
     207     * Adds and classify an address node according to completeness.
     208     *
     209     * @param aNode the address node to add and check
     210     */
     211    private void addAndClassifyAddress(OSMAddress aNode) {
     212        if (!assignAddressToStreet(aNode)) {
     213            // Assignment failed: Street is not known (yet) -> add to 'unresolved' list
     214            shadowUnresolvedAddresses.add(aNode);
     215        }
     216
     217        if (!aNode.isComplete()) {
     218            shadowIncompleteAddresses.add(aNode);
     219        }
     220    }
     221
     222    /**
     223     * Creates the node from an OSM way instance.
     224     *
     225     * @param w the way to create the entity from
     226     */
     227    private void createNodeFromWay(Way w) {
     228        IOSMEntity ne = OsmFactory.createNodeFromWay(w);
     229
     230        if (!processNode(ne, w)) {
     231            // Look also into nodes for addresses (unlikely, but at least they
     232            // get marked as visited).
     233            for (Node n : w.getNodes()) {
     234                visit(n);
     235            }
     236
     237            for (String key : w.keySet()) {
     238                if (!tags.contains(key)) {
     239                    tags.add(key);
     240                }
     241
     242                String v = w.get(key);
     243                if (!values.containsKey(v)) {
     244                    values.put(v, key);
     245                }
     246            }
     247        } // else: node has been processed, no need to look deeper
     248    }
     249
     250    /**
     251     * Process an entity node depending on the type. A street segment is added as a child to the
     252     * corresponding street dictionary while an address is added to the incomplete/unresolved list
     253     * depending of it's properties.
     254     *
     255     * @param ne the entity node.
     256     * @param w the corresponding OSM way
     257     * @return true, if node has been processed
     258     */
     259    private boolean processNode(IOSMEntity ne, Way w) {
     260        if (ne != null) {
     261            // Node is a street (segment)
     262            if (ne instanceof OSMStreetSegment) {
     263                OSMStreetSegment newSegment = (OSMStreetSegment) ne;
     264
     265                if (newSegment != null) {
     266                    String name = newSegment.getName();
     267                    if (StringUtils.isNullOrEmpty(name)) return false;
     268
     269                    OSMStreet sNode = null;
     270                    if (shadowStreetDict.containsKey(name)) { // street exists?
     271                        sNode = shadowStreetDict.get(name);
     272                    } else { // new street name -> add to dict
     273                        sNode = new OSMStreet(w);
     274                        shadowStreetDict.put(name, sNode);
     275                    }
     276
     277                    if (sNode != null) {
     278                        // TODO: Check if segment really belongs to the street, even if the
     279                        // names are the same. Then the streets should be split up...
     280                        sNode.addStreetSegment(newSegment);
     281                        return true;
     282                    } else {
     283                        throw new RuntimeException("Street node is null!");
     284                    }
     285                }
     286            }
     287
     288            // Node is an address
     289            if (ne instanceof OSMAddress) {
     290                OSMAddress aNode = (OSMAddress) ne;
     291                addAndClassifyAddress(aNode);
     292                return true;
     293            }
     294        }
     295        return false;
     296    }
     297
     298    @Override
     299    public void visit(Relation e) {
     300    }
     301
     302    @Override
     303    public void visit(Changeset cs) {
     304    }
     305
     306    /**
     307     * Gets the dictionary contains the collected streets.
     308     * @return
     309     */
     310    public HashMap<String, OSMStreet> getStreetDict() {
     311        return streetDict;
     312    }
     313
     314    /**
     315     * Gets the unresolved (addresses without valid street name) addresses.
     316     *
     317     * @return the unresolved addresses
     318     */
     319    public List<OSMAddress> getUnresolvedAddresses() {
     320        return unresolvedAddresses;
     321    }
     322
     323    /**
     324     * Gets the list with incomplete addresses.
     325     *
     326     * @return the incomplete addresses
     327     */
     328    public List<OSMAddress> getIncompleteAddresses() {
     329        return incompleteAddresses;
     330    }
     331
     332    /**
     333     * Gets the street list.
     334     *
     335     * @return the street list
     336     */
     337    public List<OSMStreet> getStreetList() {
     338        ArrayList<OSMStreet> sortedList = new ArrayList<OSMStreet>(streetDict.values());
     339        Collections.sort(sortedList);
     340        return sortedList;
     341    }
     342
     343    /**
     344     * Gets all addresses without valid street.
     345     * @return
     346     */
     347    public List<OSMAddress> getUnresolvedItems() {
     348        return unresolvedAddresses;
     349    }
     350
     351    /**
     352     * Gets the tags used in the data layer.
     353     * @return
     354     */
     355    public HashSet<String> getTags() {
     356        return tags;
     357    }
     358
     359    /**
     360     * @return the values
     361     */
     362    protected HashMap<String, String> getValues() {
     363        return values;
     364    }
     365
     366    /**
     367     * Gets the number of streets in the container.
     368     * @return
     369     */
     370    public int getNumberOfStreets() {
     371        return streetDict != null ? streetDict.size() : 0;
     372    }
     373
     374    /**
     375     * Get the number of incomplete addresses.
     376     * @return
     377     */
     378    public int getNumberOfIncompleteAddresses() {
     379        return incompleteAddresses != null ? incompleteAddresses.size() : 0;
     380    }
     381
     382    /**
     383     * Gets the number of unresolved addresses.
     384     * @return
     385     */
     386    public int getNumberOfUnresolvedAddresses() {
     387        return unresolvedAddresses != null ? unresolvedAddresses.size() : 0;
     388    }
     389
     390    /**
     391     * Gets the number of invalid (unresolved and/or incomplete) addresses.
     392     *
     393     * @return the number of invalid addresses
     394     */
     395    public int getNumberOfInvalidAddresses() {
     396        return getNumberOfIncompleteAddresses() + getNumberOfUnresolvedAddresses();
     397    }
     398
     399    /**
     400     * Gets the number of guessed tags.
     401     * @return
     402     */
     403    public int getNumberOfGuesses() {
     404        int sum = 0;
     405
     406        for (OSMAddress aNode : getAllAddressesToFix()) {
     407            if (aNode.hasGuesses()) {
     408                sum++;
     409            }
     410        }
     411        return sum;
     412    }
     413
     414    /**
     415     * Gets all (incomplete and/or unresolved) address nodes to fix.
     416     * @return
     417     */
     418    public List<OSMAddress> getAllAddressesToFix() {
     419        List<OSMAddress> all = new ArrayList<OSMAddress>(incompleteAddresses);
     420
     421        for (OSMAddress aNode : unresolvedAddresses) {
     422            if (!all.contains(aNode)) {
     423                all.add(aNode);
     424            }
     425        }
     426
     427        return all;
     428    }
     429
     430    /**
     431     * @return the problems
     432     */
     433    protected List<IProblem> getProblems() {
     434        return problems;
     435    }
     436
     437    /**
     438     * Clears the problem list.
     439     */
     440    protected void clearProblems() {
     441        problems.clear();
     442    }
     443
     444    /**
     445     * Tries to assign an address to a street.
     446     * @param aNode
     447     */
     448    private boolean assignAddressToStreet(OSMAddress aNode) {
     449        String streetName = aNode.getStreetName();
     450
     451        // street name via relation -> implicitly resolved (see TRAC #8336)
     452        if (aNode.isPartOfRelation()) {
     453            return true;
     454        }
     455       
     456        if (streetName != null && shadowStreetDict.containsKey(streetName)) {
     457            OSMStreet sNode = shadowStreetDict.get(streetName);
     458            sNode.addAddress(aNode);
     459            return true;
     460        }
     461
     462        return false;
     463    }
     464
     465    /**
     466     * Walks through the list of unassigned addresses and tries to assign them to streets.
     467     */
     468    public void resolveAddresses() {
     469        List<OSMAddress> resolvedAddresses = new ArrayList<OSMAddress>();
     470        for (OSMAddress node : shadowUnresolvedAddresses) {
     471            if (assignAddressToStreet(node)) {
     472                resolvedAddresses.add(node);
     473            }
     474        }
     475
     476        /* Remove all resolves nodes from unresolved list */
     477        for (OSMAddress resolved : resolvedAddresses) {
     478            shadowUnresolvedAddresses.remove(resolved);
     479        }
     480    }
     481
     482    /**
     483     * Rebuilds the street and address lists using the data set given
     484     * in  {@link AddressEditContainer#attachToDataSet(Collection)} or the
     485     * full data set of the current data layer {@link Main#getCurrentDataSet()}.
     486     */
     487    public void invalidate() {
     488        if (workingSet != null) {
     489            invalidate(workingSet);
     490        } else {
     491            if (Main.main.getCurrentDataSet() != null) {
     492                invalidate(Main.main.getCurrentDataSet().allPrimitives());
     493            }
     494        }
     495    }
     496
     497    /**
     498     * Invalidate using the given data collection.
     499     *
     500     * @param osmData the collection containing the osm data to work on.
     501     */
     502    public void invalidate(final Collection<? extends OsmPrimitive> osmData) {
     503        if (osmData == null || osmData.isEmpty())
     504            return;
     505
     506        synchronized (this) {
     507            clearData();
     508            clearProblems();
     509            // visit data set for problems...
     510            for (OsmPrimitive osmPrimitive : osmData) {
     511                if (osmPrimitive.isUsable()) {
     512                    osmPrimitive.accept(this);
     513                }
     514            }
     515           
     516            // match streets with addresses...
     517            resolveAddresses();
     518            // sort problem lists
     519            Collections.sort(shadowIncompleteAddresses);
     520            Collections.sort(shadowUnresolvedAddresses);
     521
     522            // put results from shadow copy into real lists
     523            incompleteAddresses = new ArrayList<OSMAddress>(shadowIncompleteAddresses);
     524            unresolvedAddresses = new ArrayList<OSMAddress>(shadowUnresolvedAddresses);
     525            streetDict = new HashMap<String, OSMStreet>(shadowStreetDict);
     526            // remove temp data
     527            shadowStreetDict.clear();
     528            shadowUnresolvedAddresses.clear();
     529            shadowIncompleteAddresses.clear();
     530
     531            // update clients
     532            fireContainerChanged();
     533        }
     534    }
     535
     536    /**
     537     * Clears the shadowed lists data and resets the 'visited' flag for every OSM object.
     538     */
     539    private void clearData() {
     540        shadowStreetDict.clear();
     541        shadowUnresolvedAddresses.clear();
     542        shadowIncompleteAddresses.clear();
     543        visitedNodes.clear();
     544        visitedWays.clear();
     545    }
     546
     547    /**
     548     * Connects the listener to the given data set and revisits the data. This method should
     549     * be called immediately after an edit session finished.
     550     *
     551     * If the given data set is not null, calls of {@link AddressEditContainer#invalidate()} will
     552     * only consider the data given within this set. This can be useful to keep out unimportant
     553     * areas. However, a side-effect could be that some streets are not included and leads to
     554     * false alarms regarding unresolved addresses.
     555     *
     556     * Calling {@link AddressEditContainer#detachFromDataSet()} drops the explicit data set and uses
     557     * the full data set on subsequent updates.<p>
     558     *
     559     * <b>Example</b><br>
     560     * <code>
     561     * attachToDataSet(osmDataSetToWorkOn); // osmDataSetToWorkOn = selected items<br>
     562     * //... launch dialog or whatever<br>
     563     * detachFromDataSet();
     564     * </code>
     565     *
     566     * @param osmDataToWorkOn the data to examine
     567     */
     568    public void attachToDataSet(Collection<? extends OsmPrimitive> osmDataToWorkOn) {
     569        if (osmDataToWorkOn != null && !osmDataToWorkOn.isEmpty()) {
     570            workingSet = new ArrayList<OsmPrimitive>(osmDataToWorkOn);
     571        } else {
     572            detachFromDataSet(); // drop old stuff, if present
     573        }
     574        invalidate(); // start our investigation...
     575    }
     576
     577    /**
     578     * Disconnects the listener from the data set. This method should
     579     * be called immediately before an edit session started in order to
     580     * prevent updates caused by e. g. a selection change within the map view.
     581     */
     582    public void detachFromDataSet() {
     583        //Main.main.getCurrentDataSet().removeDataSetListener(this);
     584        if (workingSet != null) {
     585            workingSet.clear();
     586            workingSet = null;
     587        }
     588    }
     589
     590    @Override
     591    public void dataChanged(DataChangedEvent event) {
     592    }
     593
     594    @Override
     595    public void nodeMoved(NodeMovedEvent event) {
     596
     597    }
     598
     599    @Override
     600    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
     601    }
     602
     603    @Override
     604    public void primitivesAdded(PrimitivesAddedEvent event) {
     605        invalidate();
     606    }
     607
     608    @Override
     609    public void primitivesRemoved(PrimitivesRemovedEvent event) {
     610        invalidate();
     611    }
     612
     613    @Override
     614    public void relationMembersChanged(RelationMembersChangedEvent event) {
     615    }
     616
     617    @Override
     618    public void tagsChanged(TagsChangedEvent event) {
     619        invalidate();
     620    }
     621
     622    @Override
     623    public void wayNodesChanged(WayNodesChangedEvent event) {
     624    }
     625
     626    @Override
     627    public void containerChanged(AddressEditContainer container) {
     628        invalidate();
     629    }
     630
     631    @Override
     632    public void entityChanged(IOSMEntity entity) {
     633        fireEntityChanged(entity);
     634    }
     635
     636    @Override
     637    public void addProblem(IProblem problem) {
     638        problems.add(problem);
     639    }
     640
     641    @Override
     642    public void removeProblemsOfSource(IOSMEntity entity) {
     643        CheckParameterUtil.ensureParameterNotNull(entity, "entity");
     644
     645        List<IProblem> problemsToRemove = new ArrayList<IProblem>();
     646        for (IProblem problem : problems) {
     647            if (problem.getSource() == entity) {
     648                problemsToRemove.add(problem);
     649            }
     650        }
     651
     652        for (IProblem iProblem : problemsToRemove) {
     653            problems.remove(iProblem);
     654        }
     655    }
     656
     657    @Override
     658    public String getClosestStreetName(String name) {
     659        List<String> matches = getClosestStreetNames(name, 1);
     660
     661        if (matches != null && matches.size() > 0) {
     662            return matches.get(0);
     663        }
     664
     665        return null;
     666    }
     667
     668    @Override
     669    public List<String> getClosestStreetNames(String name, int maxEntries) {
     670        CheckParameterUtil.ensureParameterNotNull(name, "name");
     671
     672        // ensure right number of entries
     673        if (maxEntries < 1) maxEntries = 1;
     674
     675        List<StreetScore> scores = new ArrayList<StreetScore>();
     676        List<String> matches = new ArrayList<String>();
     677
     678        // Find the longest common sub string
     679        for (String streetName : streetDict.keySet()) {
     680            int score = StringUtils.lcsLength(name, streetName);
     681
     682            if (score > 3) { // reasonable value?
     683                StreetScore sc = new StreetScore(streetName, score);
     684                scores.add(sc);
     685            }
     686        }
     687
     688        // sort by score
     689        Collections.sort(scores);
     690
     691        // populate result list
     692        int n = Math.min(maxEntries, scores.size());
     693        for (int i = 0; i < n; i++) {
     694            matches.add(scores.get(i).getName());
     695        }
     696
     697        return matches;
     698    }
     699
     700    @Override
     701    public boolean isValidStreetName(String name) {
     702        if (streetDict == null) return false;
     703
     704        return streetDict.containsKey(name);
     705    }
     706
     707    /**
     708     * Internal class to handle results of {@link AddressEditContainer#getClosestStreetNames(String, int)}.
     709     */
     710    private class StreetScore implements Comparable<StreetScore> {
     711        private String name;
     712        private int score;
     713
     714        /**
     715         * @param name Name of the street.
     716         * @param score Score of the street (length of longest common substring)
     717         */
     718        public StreetScore(String name, int score) {
     719            super();
     720            this.name = name;
     721            this.score = score;
     722        }
     723
     724        /**
     725         * @return the name of the street.
     726         */
     727        protected String getName() {
     728            return name;
     729        }
     730
     731        /**
     732         * @return the score of the street.
     733         */
     734        @SuppressWarnings("unused")
     735        // TODO: Implement properly
     736        protected int getScore() {
     737            return score;
     738        }
     739
    642740        @Override
    643         public void primitivesAdded(PrimitivesAddedEvent event) {
    644                 invalidate();
    645         }
    646 
    647         /* (non-Javadoc)
    648          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent)
    649          */
    650         @Override
    651         public void primitivesRemoved(PrimitivesRemovedEvent event) {
    652                 invalidate();
    653         }
    654 
    655         /* (non-Javadoc)
    656          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent)
    657          */
    658         @Override
    659         public void relationMembersChanged(RelationMembersChangedEvent event) {
    660         }
    661 
    662         /* (non-Javadoc)
    663          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent)
    664          */
    665         @Override
    666         public void tagsChanged(TagsChangedEvent event) {
    667                 invalidate();
    668         }
    669 
    670         /* (non-Javadoc)
    671          * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent)
    672          */
    673         @Override
    674         public void wayNodesChanged(WayNodesChangedEvent event) {
    675         }
    676 
    677         /* (non-Javadoc)
    678          * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    679          */
    680         @Override
    681         public void containerChanged(AddressEditContainer container) {
    682                 invalidate();
    683         }
    684 
    685         /* (non-Javadoc)
    686          * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)
    687          */
    688         @Override
    689         public void entityChanged(IOSMEntity entity) {
    690                 fireEntityChanged(entity);
    691         }
    692 
    693         /* (non-Javadoc)
    694          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor#addProblem(org.openstreetmap.josm.plugins.fixAddresses.IProblem)
    695          */
    696         @Override
    697         public void addProblem(IProblem problem) {
    698                 problems.add(problem);
    699         }
    700 
    701         /* (non-Javadoc)
    702          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor#removeProblemsOfSource(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)
    703          */
    704         @Override
    705         public void removeProblemsOfSource(IOSMEntity entity) {
    706                 CheckParameterUtil.ensureParameterNotNull(entity, "entity");
    707 
    708                 List<IProblem> problemsToRemove = new ArrayList<IProblem>();
    709                 for (IProblem problem : problems) {
    710                         if (problem.getSource() == entity) {
    711                                 problemsToRemove.add(problem);
    712                         }
    713                 }
    714 
    715                 for (IProblem iProblem : problemsToRemove) {
    716                         problems.remove(iProblem);
    717                 }
    718         }
    719 
    720         /* (non-Javadoc)
    721          * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#getClosestStreetName(java.lang.String)
    722          */
    723         @Override
    724         public String getClosestStreetName(String name) {
    725                 List<String> matches = getClosestStreetNames(name, 1);
    726 
    727                 if (matches != null && matches.size() > 0) {
    728                         return matches.get(0);
    729                 }
    730 
    731                 return null;
    732         }
    733 
    734         /* (non-Javadoc)
    735          * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#getClosestStreetNames(java.lang.String, int)
    736          */
    737         @Override
    738         public List<String> getClosestStreetNames(String name, int maxEntries) {
    739                 CheckParameterUtil.ensureParameterNotNull(name, "name");
    740 
    741                 // ensure right number of entries
    742                 if (maxEntries < 1) maxEntries = 1;
    743 
    744                 List<StreetScore> scores = new ArrayList<StreetScore>();
    745                 List<String> matches = new ArrayList<String>();
    746 
    747                 // Find the longest common sub string
    748                 for (String streetName : streetDict.keySet()) {
    749                         int score = StringUtils.lcsLength(name, streetName);
    750 
    751                         if (score > 3) { // reasonable value?
    752                                 StreetScore sc = new StreetScore(streetName, score);
    753                                 scores.add(sc);
    754                         }
    755                 }
    756 
    757                 // sort by score
    758                 Collections.sort(scores);
    759 
    760                 // populate result list
    761                 int n = Math.min(maxEntries, scores.size());
    762                 for (int i = 0; i < n; i++) {
    763                         matches.add(scores.get(i).getName());
    764                 }
    765 
    766                 return matches;
    767         }
    768 
    769         /* (non-Javadoc)
    770          * @see org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap#isValidStreetName(java.lang.String)
    771          */
    772         @Override
    773         public boolean isValidStreetName(String name) {
    774                 if (streetDict == null) return false;
    775 
    776                 return streetDict.containsKey(name);
    777         }
    778 
    779         /**
    780          * Internal class to handle results of {@link AddressEditContainer#getClosestStreetNames(String, int)}.
    781          */
    782         private class StreetScore implements Comparable<StreetScore> {
    783                 private String name;
    784                 private int score;
    785 
    786                 /**
    787                  * @param name Name of the street.
    788                  * @param score Score of the street (length of longest common substring)
    789                  */
    790                 public StreetScore(String name, int score) {
    791                         super();
    792                         this.name = name;
    793                         this.score = score;
    794                 }
    795 
    796                 /**
    797                  * @return the name of the street.
    798                  */
    799                 protected String getName() {
    800                         return name;
    801                 }
    802 
    803                 /**
    804                  * @return the score of the street.
    805                  */
    806                 @SuppressWarnings("unused")
    807                 // TODO: Implement properly
    808                 protected int getScore() {
    809                         return score;
    810                 }
    811 
    812                 @Override
    813                 public int compareTo(StreetScore arg0) {
    814                         if (arg0 == null) return 1;
    815 
    816                         return new Integer(score).compareTo(new Integer(arg0.score));
    817                 }
    818         }
     741        public int compareTo(StreetScore arg0) {
     742            if (arg0 == null) return 1;
     743
     744            return new Integer(score).compareTo(new Integer(arg0.score));
     745        }
     746    }
    819747}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressProblem.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    208
    219public class AddressProblem implements IProblem {
    22         private List<ISolution> solutions = null;
    23         private String description;
    24         private ProblemType type;
    25         private IOSMEntity source;
     10    private List<ISolution> solutions = null;
     11    private String description;
     12    private ProblemType type;
     13    private IOSMEntity source;
    2614
    27         /**
    28         * Instantiates a new problem.
    29         *
    30         * @param source the source
    31         * @param description The problem description.
    32         * @param solutions This list of solutions.
    33         * @param type the type
    34         */
    35         public AddressProblem(IOSMEntity source, String description,
    36                         List<ISolution> solutions, ProblemType type) {
    37                 super();
    38                 this.source = source;
    39                 this.description = description;
    40                 this.solutions = solutions;
    41                 this.type = type;
    42         }
     15    /**
     16    * Instantiates a new problem.
     17    *
     18    * @param source the source
     19    * @param description The problem description.
     20    * @param solutions This list of solutions.
     21    * @param type the type
     22    */
     23    public AddressProblem(IOSMEntity source, String description,
     24            List<ISolution> solutions, ProblemType type) {
     25        super();
     26        this.source = source;
     27        this.description = description;
     28        this.solutions = solutions;
     29        this.type = type;
     30    }
    4331
    44         /**
    45         * Instantiates a new problem with type 'warning'.
    46         *
    47         * @param source the source
    48         * @param description The problem description.
    49         * @param solutions This list of solutions.
    50         */
    51         public AddressProblem(IOSMEntity source, String description, List<ISolution> solutions) {
    52                 this(source, description, solutions, ProblemType.Warning);
    53         }
     32    /**
     33    * Instantiates a new problem with type 'warning'.
     34    *
     35    * @param source the source
     36    * @param description The problem description.
     37    * @param solutions This list of solutions.
     38    */
     39    public AddressProblem(IOSMEntity source, String description, List<ISolution> solutions) {
     40        this(source, description, solutions, ProblemType.Warning);
     41    }
    5442
    55         /**
    56         * Instantiates a new problem with type 'warning' and without solutions.
    57         *
    58         * @param source the source
    59         * @param description The problem description.
    60         */
    61         public AddressProblem(IOSMEntity source, String description) {
    62                 this(source, description, null, ProblemType.Warning);
    63         }
     43    /**
     44    * Instantiates a new problem with type 'warning' and without solutions.
     45    *
     46    * @param source the source
     47    * @param description The problem description.
     48    */
     49    public AddressProblem(IOSMEntity source, String description) {
     50        this(source, description, null, ProblemType.Warning);
     51    }
    6452
    65         /**
    66         * Creates the solution list, if necessary.
    67         */
    68         private void lazyCreateSolutions() {
    69                 if (solutions == null) {
    70                         solutions = new ArrayList<ISolution>();
    71                 }
    72         }
     53    /**
     54    * Creates the solution list, if necessary.
     55    */
     56    private void lazyCreateSolutions() {
     57        if (solutions == null) {
     58            solutions = new ArrayList<ISolution>();
     59        }
     60    }
    7361
    74         /* (non-Javadoc)
    75          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#addSolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution)
    76          */
    77         @Override
    78         public void addSolution(ISolution solution) {
    79                 CheckParameterUtil.ensureParameterNotNull(solution, "solution");
     62    @Override
     63    public void addSolution(ISolution solution) {
     64        CheckParameterUtil.ensureParameterNotNull(solution, "solution");
    8065
    81                 lazyCreateSolutions();
    82                 solutions.add(solution);
    83         }
     66        lazyCreateSolutions();
     67        solutions.add(solution);
     68    }
    8469
    85         /* (non-Javadoc)
    86          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#applySolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution)
    87          */
    88         @Override
    89         public void applySolution(ISolution solution) {
    90                 CheckParameterUtil.ensureParameterNotNull(solution, "solution");
     70    @Override
     71    public void applySolution(ISolution solution) {
     72        CheckParameterUtil.ensureParameterNotNull(solution, "solution");
    9173
    92                 solution.solve();
    93         }
     74        solution.solve();
     75    }
    9476
    95         /* (non-Javadoc)
    96          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#clearSolutions()
    97          */
    98         @Override
    99         public void clearSolutions() {
    100                 if (solutions == null) return;
     77    @Override
     78    public void clearSolutions() {
     79        if (solutions == null) return;
    10180
    102                 solutions.clear();
    103         }
     81        solutions.clear();
     82    }
    10483
    105         /* (non-Javadoc)
    106          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getDescription()
    107          */
    108         @Override
    109         public String getDescription() {
    110                 return description;
    111         }
     84    @Override
     85    public String getDescription() {
     86        return description;
     87    }
    11288
    113         /* (non-Javadoc)
    114          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getSolutions()
    115          */
    116         @Override
    117         public List<ISolution> getSolutions() {
    118                 return solutions;
    119         }
     89    @Override
     90    public List<ISolution> getSolutions() {
     91        return solutions;
     92    }
    12093
    121         /* (non-Javadoc)
    122          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getType()
    123          */
    124         @Override
    125         public ProblemType getType() {
    126                 return type;
    127         }
     94    @Override
     95    public ProblemType getType() {
     96        return type;
     97    }
    12898
    129         /* (non-Javadoc)
    130          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#removeSolution(org.openstreetmap.josm.plugins.fixAddresses.ISolution)
    131          */
    132         @Override
    133         public void removeSolution(ISolution solution) {
    134                 if (solutions == null ) throw new RuntimeException("Solution list is null");
    135                 if (solutions.size() == 0) throw new RuntimeException("Solution list is empty");
     99    @Override
     100    public void removeSolution(ISolution solution) {
     101        if (solutions == null ) throw new RuntimeException("Solution list is null");
     102        if (solutions.size() == 0) throw new RuntimeException("Solution list is empty");
    136103
    137                 CheckParameterUtil.ensureParameterNotNull(solution, "solution");
    138                 solutions.remove(solution);
    139         }
     104        CheckParameterUtil.ensureParameterNotNull(solution, "solution");
     105        solutions.remove(solution);
     106    }
    140107
    141         /* (non-Javadoc)
    142          * @see org.openstreetmap.josm.plugins.fixAddresses.IProblem#getSource()
    143          */
    144         @Override
    145         public IOSMEntity getSource() {
    146                 return source;
    147         }
     108    @Override
     109    public IOSMEntity getSource() {
     110        return source;
     111    }
    148112
    149113}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressSolution.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    208 */
    219public class AddressSolution implements ISolution {
    22         private JosmAction action;
    23         private String description;
    24         private SolutionType type;
     10    private JosmAction action;
     11    private String description;
     12    private SolutionType type;
    2513
    26         /**
    27         * @param description The solution description.
    28         * @param action The action to execute to solve the problem.
    29         * @param type The solution type.
    30         */
    31         public AddressSolution(String description, JosmAction action,
    32                         SolutionType type) {
    33                 super();
    34                 this.description = description;
    35                 this.action = action;
    36                 this.type = type;
    37         }
     14    /**
     15    * @param description The solution description.
     16    * @param action The action to execute to solve the problem.
     17    * @param type The solution type.
     18    */
     19    public AddressSolution(String description, JosmAction action,
     20            SolutionType type) {
     21        super();
     22        this.description = description;
     23        this.action = action;
     24        this.type = type;
     25    }
    3826
    39         @Override
    40         public JosmAction getAction() {
    41                 return action;
    42         }
     27    @Override
     28    public JosmAction getAction() {
     29        return action;
     30    }
    4331
    44         @Override
    45         public String getDescription() {
    46                 return description;
    47         }
     32    @Override
     33    public String getDescription() {
     34        return description;
     35    }
    4836
    49         @Override
    50         public SolutionType getType() {
    51                 return type;
    52         }
     37    @Override
     38    public SolutionType getType() {
     39        return type;
     40    }
    5341
    54         @Override
    55         public void solve() {
    56                 // TODO: Remove??
    57         }
     42    @Override
     43    public void solve() {
     44        // TODO: Remove??
     45    }
    5846}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesMapMode.java

    r26509 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    219import org.openstreetmap.josm.gui.MapFrame;
    2210
    23 
    2411@SuppressWarnings("serial")
    2512public class FixAddressesMapMode extends MapMode {
    2613
    27         public FixAddressesMapMode(MapFrame mapFrame) {
    28                 super(tr("Fix addresses"), "incompleteaddress_24",
    29                                 tr("Show dialog with incomplete addresses"),
    30                                 mapFrame,
    31                                 Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    32         }
    33 
    34 
     14    public FixAddressesMapMode(MapFrame mapFrame) {
     15        super(tr("Fix addresses"), "incompleteaddress_24",
     16                tr("Show dialog with incomplete addresses"),
     17                mapFrame,
     18                Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     19    }
    3520}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesPlugin.java

    r29869 r30348  
    1 /**
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2816 */
    2917public class FixAddressesPlugin extends Plugin {
    30         private static FixAddressesPreferences preferences;
     18    private static FixAddressesPreferences preferences;
    3119
    32         /**
    33         * Constructor for the AddressEdit plugin. Called by JOSM when loading the plugin.
    34         * @param info Context information of the plugin.
    35         */
    36         public FixAddressesPlugin(PluginInformation info) {
    37                 super(info);
     20    /**
     21    * Constructor for the AddressEdit plugin. Called by JOSM when loading the plugin.
     22    * @param info Context information of the plugin.
     23    */
     24    public FixAddressesPlugin(PluginInformation info) {
     25        super(info);
    3826
    39                 // Create actions...
    40                 FixUnresolvedStreetsAction action = new FixUnresolvedStreetsAction();
    41                 SelectIncompleteAddressesAction incAddrAction = new SelectIncompleteAddressesAction();
     27        // Create actions...
     28        FixUnresolvedStreetsAction action = new FixUnresolvedStreetsAction();
     29        SelectIncompleteAddressesAction incAddrAction = new SelectIncompleteAddressesAction();
    4230
    43                 // ... and add them to the tools menu in main
     31        // ... and add them to the tools menu in main
    4432                MainMenu.add(Main.main.menu.toolsMenu, action, false, 0);
    45                 MainMenu.add(Main.main.menu.toolsMenu, incAddrAction);
     33        MainMenu.add(Main.main.menu.toolsMenu, incAddrAction);
    4634
    47                 // create preferences instance
    48                 preferences = (FixAddressesPreferences) new FixAddressesPreferences.Factory().createPreferenceSetting();
    49         }
     35        // create preferences instance
     36        preferences = (FixAddressesPreferences) new FixAddressesPreferences.Factory().createPreferenceSetting();
     37    }
    5038
    51         /* (non-Javadoc)
    52          * @see org.openstreetmap.josm.plugins.Plugin#mapFrameInitialized(org.openstreetmap.josm.gui.MapFrame, org.openstreetmap.josm.gui.MapFrame)
    53          */
    54         @Override
    55         public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    56                 if (newFrame != null) {
    57                         FixAddressesMapMode faMode = new FixAddressesMapMode(Main.map);
    58                         IconToggleButton faModeButton = new IconToggleButton(faMode);
    59                         faModeButton.setVisible(true);
    60                         newFrame.addToggleDialog(new IncompleteAddressesDialog());
    61                 }
    62         }
     39    @Override
     40    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     41        if (newFrame != null) {
     42            FixAddressesMapMode faMode = new FixAddressesMapMode(Main.map);
     43            IconToggleButton faModeButton = new IconToggleButton(faMode);
     44            faModeButton.setVisible(true);
     45            newFrame.addToggleDialog(new IncompleteAddressesDialog());
     46        }
     47    }
    6348
    64         @Override
    65         public PreferenceSetting getPreferenceSetting() {
    66                 return getPreferences();
    67         }
     49    @Override
     50    public PreferenceSetting getPreferenceSetting() {
     51        return getPreferences();
     52    }
    6853
    69         /**
    70         * Gets the preferences instance for this plugin.
    71         *
    72         * @return the preferences
    73         */
    74         public static FixAddressesPreferences getPreferences() {
    75                 return preferences;
    76         }
     54    /**
     55    * Gets the preferences instance for this plugin.
     56    *
     57    * @return the preferences
     58    */
     59    public static FixAddressesPreferences getPreferences() {
     60        return preferences;
     61    }
    7762}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixAddressesPreferences.java

    r29500 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2614
    2715public class FixAddressesPreferences extends DefaultTabPreferenceSetting {
    28         private static final String FIX_ADDRESSES_IGNORE_POST_CODE_KEY = "fixAddresses.ignorePostCode";
    29         private static final String FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY = "fixAddresses.selectGuessedObjects";
    30        
    31         private JCheckBox cbSelectGuessedObjects = new JCheckBox(tr("Include objects used for guesses"));
    32         private JCheckBox cbIgnorePostCode = new JCheckBox();
     16    private static final String FIX_ADDRESSES_IGNORE_POST_CODE_KEY = "fixAddresses.ignorePostCode";
     17    private static final String FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY = "fixAddresses.selectGuessedObjects";
     18   
     19    private JCheckBox cbSelectGuessedObjects = new JCheckBox(tr("Include objects used for guesses"));
     20    private JCheckBox cbIgnorePostCode = new JCheckBox();
    3321
    34         /**
    35         * Internal factory class. Call <code>FixAddressesPreferences.Factory().createPreferenceSetting()</code> to
    36         * create the preference setting instance.
    37         */
    38         public static class Factory implements PreferenceSettingFactory {
    39                 public PreferenceSetting createPreferenceSetting() {
    40                         return new FixAddressesPreferences();
    41                 }
    42         }
    43        
    44         /**
    45         * Internal constructor.
    46         */
    47         private FixAddressesPreferences() {
    48                 loadFromPrefs();
    49         }
    50        
    51         /**
    52         * Loads the (initial) preference settings.
    53         */
    54         private void loadFromPrefs() {
    55                 setSelectGuessedObjects(Main.pref.getBoolean(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, false));
    56                 setIgnorePostCode(Main.pref.getBoolean(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, false));
    57         }
    58        
    59         /**
    60         * Save the preference settings.
    61         */
    62         private void saveToPrefs() {
    63                 Main.pref.put(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, isSelectGuessedObjects());
    64                 Main.pref.put(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, isIgnorePostCode());
    65         }
     22    /**
     23    * Internal factory class. Call <code>FixAddressesPreferences.Factory().createPreferenceSetting()</code> to
     24    * create the preference setting instance.
     25    */
     26    public static class Factory implements PreferenceSettingFactory {
     27        public PreferenceSetting createPreferenceSetting() {
     28            return new FixAddressesPreferences();
     29        }
     30    }
     31   
     32    /**
     33    * Internal constructor.
     34    */
     35    private FixAddressesPreferences() {
     36        loadFromPrefs();
     37    }
     38   
     39    /**
     40    * Loads the (initial) preference settings.
     41    */
     42    private void loadFromPrefs() {
     43        setSelectGuessedObjects(Main.pref.getBoolean(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, false));
     44        setIgnorePostCode(Main.pref.getBoolean(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, false));
     45    }
     46   
     47    /**
     48    * Save the preference settings.
     49    */
     50    private void saveToPrefs() {
     51        Main.pref.put(FIX_ADDRESSES_SELECT_GUESSED_OBJECTS_KEY, isSelectGuessedObjects());
     52        Main.pref.put(FIX_ADDRESSES_IGNORE_POST_CODE_KEY, isIgnorePostCode());
     53    }
    6654
    67         /* (non-Javadoc)
    68          * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#addGui(org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane)
    69          */
    70         @Override
    71         public void addGui(PreferenceTabbedPane gui) {
    72                 // Import settings
     55    @Override
     56    public void addGui(PreferenceTabbedPane gui) {
     57        // Import settings
    7358        ButtonGroup fixAddrOptions = new ButtonGroup();
    7459        fixAddrOptions.add(cbSelectGuessedObjects);
    7560        fixAddrOptions.add(cbIgnorePostCode);
    76         }
     61    }
    7762
    78         /* (non-Javadoc)
    79          * @see org.openstreetmap.josm.gui.preferences.PreferenceSetting#ok()
    80          */
    81         @Override
    82         public boolean ok() {
    83                 saveToPrefs();
    84                 loadFromPrefs();
    85                 return false;
    86         }
     63    @Override
     64    public boolean ok() {
     65        saveToPrefs();
     66        loadFromPrefs();
     67        return false;
     68    }
    8769
    88         /**
    89         * Checks if option "select guessed objects" is set. If yes, every selection
    90         * includes also the objects used for guessing the address tags.
    91         * Otherwise only the address itself is selected.
    92         *
    93         * @return the selectGuessedObjects
    94         */
    95         public boolean isSelectGuessedObjects() {
    96                 return cbSelectGuessedObjects.isSelected();
    97         }
     70    /**
     71    * Checks if option "select guessed objects" is set. If yes, every selection
     72    * includes also the objects used for guessing the address tags.
     73    * Otherwise only the address itself is selected.
     74    *
     75    * @return the selectGuessedObjects
     76    */
     77    public boolean isSelectGuessedObjects() {
     78        return cbSelectGuessedObjects.isSelected();
     79    }
    9880
    99         /**
    100         * Sets the select guessed objects.
    101         *
    102         * @param selectGuessedObjects the selectGuessedObjects to set
    103         */
    104         void setSelectGuessedObjects(boolean selectGuessedObjects) {
    105                 cbSelectGuessedObjects.setSelected(selectGuessedObjects);
    106         }
     81    /**
     82    * Sets the select guessed objects.
     83    *
     84    * @param selectGuessedObjects the selectGuessedObjects to set
     85    */
     86    void setSelectGuessedObjects(boolean selectGuessedObjects) {
     87        cbSelectGuessedObjects.setSelected(selectGuessedObjects);
     88    }
    10789
    108         /**
    109         * Checks if invalid post codes should be ignored. If yes, post codes are neither
    110         * checked for existence nor for correctness.
    111         * @return
    112         */
    113         public boolean isIgnorePostCode() {
    114                 return cbIgnorePostCode.isSelected();
    115         }
     90    /**
     91    * Checks if invalid post codes should be ignored. If yes, post codes are neither
     92    * checked for existence nor for correctness.
     93    * @return
     94    */
     95    public boolean isIgnorePostCode() {
     96        return cbIgnorePostCode.isSelected();
     97    }
    11698
    117         public void setIgnorePostCode(boolean ignorePostCode) {
    118                 cbIgnorePostCode.setSelected(ignorePostCode);
    119         }
     99    public void setIgnorePostCode(boolean ignorePostCode) {
     100        cbIgnorePostCode.setSelected(ignorePostCode);
     101    }
    120102}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/FixUnresolvedStreetsAction.java

    r29500 r30348  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.fixAddresses;
    23
     
    2021 * @author Oliver Wieland <oliver.wieland@online.de>
    2122 */
    22 
    2323@SuppressWarnings("serial")
    2424public class FixUnresolvedStreetsAction extends JosmAction implements SelectionChangedListener {
    25         private AddressEditContainer addressEditContainer;
    26         private Collection<? extends OsmPrimitive> newSelection;
     25    private AddressEditContainer addressEditContainer;
     26    private Collection<? extends OsmPrimitive> newSelection;
    2727
    28         public FixUnresolvedStreetsAction() {
    29                 super(tr("Fix street addresses"), "fixstreets_24",
    30                                 tr("Find and fix addresses without (valid) streets."),
    31                                 Shortcut.registerShortcut("tools:AddressEdit", tr("Tool: {0}",
    32                                 tr("Address Edit")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), false);
     28    public FixUnresolvedStreetsAction() {
     29        super(tr("Fix street addresses"), "fixstreets_24",
     30                tr("Find and fix addresses without (valid) streets."),
     31                Shortcut.registerShortcut("tools:AddressEdit", tr("Tool: {0}",
     32                tr("Address Edit")), KeyEvent.VK_X, Shortcut.CTRL_SHIFT), false);
    3333
    34                 setEnabled(false);
    35                 addressEditContainer = new AddressEditContainer();
    36                 DataSet.addSelectionListener(this);
    37         }
     34        setEnabled(false);
     35        addressEditContainer = new AddressEditContainer();
     36        DataSet.addSelectionListener(this);
     37    }
    3838
    39         /* (non-Javadoc)
    40          * @see org.openstreetmap.josm.data.SelectionChangedListener#selectionChanged(java.util.Collection)
    41          */
    42         @Override
    43         public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    44                 /* remember new selection for actionPerformed */
    45                 this.newSelection = newSelection;
    46         }
     39    @Override
     40    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     41        /* remember new selection for actionPerformed */
     42        this.newSelection = newSelection;
     43    }
    4744
    48         /* (non-Javadoc)
    49          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    50          */
    51         @Override
    52         public void actionPerformed(ActionEvent arg0) {
    53                 if (addressEditContainer != null) {
    54                         addressEditContainer.attachToDataSet(newSelection);
    55                         try {
    56                                 //generateTagCode(addressEditContainer);
    57                                 AddressEditDialog dlg = new AddressEditDialog(addressEditContainer);
    58                                 dlg.setVisible(true);
    59                         } finally {
    60                                 addressEditContainer.detachFromDataSet();
    61                         }
    62                 }
    63         }
     45    @Override
     46    public void actionPerformed(ActionEvent arg0) {
     47        if (addressEditContainer != null) {
     48            addressEditContainer.attachToDataSet(newSelection);
     49            try {
     50                //generateTagCode(addressEditContainer);
     51                AddressEditDialog dlg = new AddressEditDialog(addressEditContainer);
     52                dlg.setVisible(true);
     53            } finally {
     54                addressEditContainer.detachFromDataSet();
     55            }
     56        }
     57    }
    6458
     59    @Override
     60    protected void updateEnabledState() {
     61        setEnabled(getCurrentDataSet() != null);
     62    }
    6563
    66         /* (non-Javadoc)
    67          * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState()
    68          */
    69         @Override
    70         protected void updateEnabledState() {
    71                 setEnabled(getCurrentDataSet() != null);
    72         }
     64    @Override
     65    protected void updateEnabledState(
     66            Collection<? extends OsmPrimitive> selection) {
     67        // Enable button if there is either a selection or at least a data set
     68        setEnabled( selection != null && !selection.isEmpty() ||
     69                    (getCurrentDataSet() != null));
     70    }
    7371
    74         @Override
    75         protected void updateEnabledState(
    76                         Collection<? extends OsmPrimitive> selection) {
    77                 // Enable button if there is either a selection or at least a data set
    78                 setEnabled( selection != null && !selection.isEmpty() ||
    79                                         (getCurrentDataSet() != null));
    80         }
     72    /* This code is abused to generate tag utility code */
    8173
    82         /* This code is abused to generate tag utility code */
     74    @SuppressWarnings("unused")
     75    private void generateTagCode(AddressEditContainer addrVisitor) {
    8376
    84         @SuppressWarnings("unused")
    85         private void generateTagCode(AddressEditContainer addrVisitor) {
     77        for (String tag : addrVisitor.getTags()) {
     78            String methodName = createMethodName(tag);
     79            System.out
     80            .println(String
     81                    .format(
     82                            "/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n",
     83                            tag, methodName, tag.toUpperCase()
     84                            .replaceAll(":", "_")));
     85            System.out
     86            .println(String
     87                    .format(
     88                            "/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n",
     89                            tag, methodName, tag.toUpperCase()
     90                            .replaceAll(":", "_")));
     91        }
    8692
    87                 for (String tag : addrVisitor.getTags()) {
    88                         String methodName = createMethodName(tag);
    89                         System.out
    90                         .println(String
    91                                         .format(
    92                                                         "/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n",
    93                                                         tag, methodName, tag.toUpperCase()
    94                                                         .replaceAll(":", "_")));
    95                         System.out
    96                         .println(String
    97                                         .format(
    98                                                         "/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n",
    99                                                         tag, methodName, tag.toUpperCase()
    100                                                         .replaceAll(":", "_")));
    101                 }
     93        for (String tag : addrVisitor.getTags()) {
     94            System.out.println(String.format(
     95                    "public static final String %s_TAG = \"%s\";", tag
     96                    .toUpperCase().replaceAll(":", "_"), tag));
     97        }
    10298
    103                 for (String tag : addrVisitor.getTags()) {
    104                         System.out.println(String.format(
    105                                         "public static final String %s_TAG = \"%s\";", tag
    106                                         .toUpperCase().replaceAll(":", "_"), tag));
    107                 }
     99        for (String value : addrVisitor.getValues().keySet()) {
     100            String tag = addrVisitor.getValues().get(value);
    108101
    109                 for (String value : addrVisitor.getValues().keySet()) {
    110                         String tag = addrVisitor.getValues().get(value);
     102            String tags = tag.toUpperCase().replaceAll(":", "_");
     103            String values = value.toUpperCase().replaceAll(":", "_");
     104            System.out.println(String.format(
     105                    "public static final String %s_%s_VALUE = \"%s\";", tags, values
     106                    , value));
     107        }
     108    }
    111109
    112                         String tags = tag.toUpperCase().replaceAll(":", "_");
    113                         String values = value.toUpperCase().replaceAll(":", "_");
    114                         System.out.println(String.format(
    115                                         "public static final String %s_%s_VALUE = \"%s\";", tags, values
    116                                         , value));
    117                 }
    118         }
     110    private String createMethodName(String osmName) {
     111        StringBuffer result = new StringBuffer(osmName.length());
     112        boolean nextUp = false;
     113        for (int i = 0; i < osmName.length(); i++) {
     114            char c = osmName.charAt(i);
     115            if (i == 0) {
     116                result.append(Character.toUpperCase(c));
     117                continue;
     118            }
     119            if (c == '_' || c == ':') {
     120                nextUp = true;
     121            } else {
     122                if (nextUp) {
     123                    result.append(Character.toUpperCase(c));
     124                    nextUp = false;
     125                } else {
     126                    result.append(c);
     127                }
     128            }
     129        }
    119130
    120         private String createMethodName(String osmName) {
    121                 StringBuffer result = new StringBuffer(osmName.length());
    122                 boolean nextUp = false;
    123                 for (int i = 0; i < osmName.length(); i++) {
    124                         char c = osmName.charAt(i);
    125                         if (i == 0) {
    126                                 result.append(Character.toUpperCase(c));
    127                                 continue;
    128                         }
    129                         if (c == '_' || c == ':') {
    130                                 nextUp = true;
    131                         } else {
    132                                 if (nextUp) {
    133                                         result.append(Character.toUpperCase(c));
    134                                         nextUp = false;
    135                                 } else {
    136                                         result.append(c);
    137                                 }
    138                         }
    139                 }
    140 
    141                 return result.toString();
    142         }
     131        return result.toString();
     132    }
    143133}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessAddressRunnable.java

    r29870 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    3624 */
    3725public class GuessAddressRunnable extends PleaseWaitRunnable {
    38         private List<OSMAddress> addressesToGuess;
    39         private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>();
    40         private boolean isRunning = false;
    41         private boolean canceled;
    42 
    43         private GuessedValueHandler[] wayGuessers = new GuessedValueHandler[]{new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG)};
    44         private GuessedValueHandler[] nodeGuessers = new GuessedValueHandler[]{
    45                         new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, 500.0),
    46                         new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 5000.0),
    47                         new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, 5000.0),
    48                         new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, 5000.0),
    49                         new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 2000.0)
    50         };
    51 
    52         /**
    53          * Instantiates a new guess address runnable.
    54          *
    55          * @param addresses the addresses to guess the values for
    56          * @param title the title of progress monitor
    57          */
    58         public GuessAddressRunnable(List<OSMAddress> addresses, String title) {
    59                 super(title != null ? title : tr("Searching"));
    60                 setAddressEditContainer(addresses);
    61         }
    62 
    63         /**
    64          * Sets the address edit container.
    65          *
    66          * @param nodes the new address edit container
    67          */
    68         public void setAddressEditContainer(List<OSMAddress> nodes) {
    69                 if (isRunning) {
    70                         throw new ConcurrentModificationException();
    71                 }
    72                 this.addressesToGuess = nodes;
    73         }
    74 
    75         /**
    76          * Gets the addresses to guess.
    77          *
    78          * @return the addresses to guess
    79          */
    80         public List<OSMAddress> getAddressesToGuess() {
    81                 return addressesToGuess;
    82         }
    83         /**
    84          * @return the isRunning
    85          */
    86         public boolean isRunning() {
    87                 return isRunning;
    88         }
    89 
    90         /**
    91          * Adds a finish listener.
    92          *
    93          * @param l the listener to add
    94          */
    95         public void addFinishListener(IProgressMonitorFinishedListener l) {
    96                 finishListeners.add(l);
    97         }
    98 
    99         /**
    100          * Removes a finish listener.
    101          *
    102          * @param l the listener to remove
    103          */
    104         public void removeFinishListener(IProgressMonitorFinishedListener l) {
    105                 finishListeners.remove(l);
    106         }
    107 
    108         /**
    109          * Fires the 'finished' event after the thread has done his work.
    110          */
    111         protected void fireFinished() {
    112                 for (IProgressMonitorFinishedListener l : finishListeners) {
    113                         l.finished();                   
    114                 }
    115                 // this event is fired only once, then we disconnect all listeners
    116                 finishListeners.clear();
    117         }
    118 
    119         /* (non-Javadoc)
    120          * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#cancel()
    121          */
    122         @Override
    123         protected void cancel() {
    124                 canceled = true;
    125         }
    126 
    127         /* (non-Javadoc)
    128          * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#finish()
    129          */
    130         @Override
    131         protected void finish() {
    132                 // nothing to do yet
    133         }
    134 
    135         /* (non-Javadoc)
    136          * @see org.openstreetmap.josm.gui.PleaseWaitRunnable#realRun()
    137          */
    138         @Override
    139         protected void realRun() throws SAXException, IOException,
    140         OsmTransferException {
    141 
    142                 if (Main.main.getCurrentDataSet() == null || addressesToGuess == null) return;
    143 
    144                 isRunning = true;
    145                 canceled = false;
    146 
    147                 // Start progress monitor to guess address values
    148                 progressMonitor.subTask(tr("Searching") + "...");
    149 
    150                 try {
    151                         progressMonitor.setTicksCount(addressesToGuess.size());
    152 
    153                         List<OSMAddress> shadowCopy = new ArrayList<OSMAddress>(addressesToGuess);
    154                         for (OSMAddress aNode : shadowCopy) {
    155                                 if (!aNode.needsGuess()) { // nothing to do
    156                                         progressMonitor.worked(1);
    157                                         continue;
    158                                 }
    159 
    160                                 // check for cancel
    161                                 if (canceled) {
    162                                         break;
    163                                 }
    164 
    165                                 // Update progress monitor
    166                                 progressMonitor.subTask(tr("Guess values for ") + aNode);
    167 
    168                                 // Run way-related guessers
    169                                 for (int i = 0; i < wayGuessers.length; i++) {
    170                                         GuessedValueHandler guesser = wayGuessers[i];
    171                                        
    172                                         guesser.setAddressNode(aNode);
    173 
    174                                         // visit osm data
    175                                         for (Way way : Main.main.getCurrentDataSet().getWays()) {
    176                                                 if (canceled) {
    177                                                         break;
    178                                                 }
    179                                                 way.accept(guesser);                                           
    180                                         }
    181                                        
    182                                         String guessedVal = guesser.getCurrentValue();
    183                                         if (guessedVal != null) {
    184                                                 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode());
    185                                         }
    186                                 }
    187                                
    188                                 // Run node-related guessers
    189                                 for (int i = 0; i < nodeGuessers.length; i++) {
    190                                         GuessedValueHandler guesser = nodeGuessers[i];
    191                                        
    192                                         guesser.setAddressNode(aNode);
    193 
    194                                         // visit osm data
    195                                         for (Node node : Main.main.getCurrentDataSet().getNodes()) {
    196                                                 if (canceled) {
    197                                                         break;
    198                                                 }
    199                                                 node.accept(guesser);                                           
    200                                         }
    201                                        
    202                                         String guessedVal = guesser.getCurrentValue();
    203                                         if (guessedVal != null) {
    204                                                 aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode());
    205                                         }
    206                                 }
    207 
    208                                 // report progress
    209                                 progressMonitor.worked(1);
    210                         }
    211                 } finally {
    212                         isRunning = false;
    213                         fireFinished();
    214                 }
    215         }
    216 
    217         // TODO: Put in separate file
    218         private class GuessStreetValueHandler extends GuessedValueHandler {
    219                 public GuessStreetValueHandler(String tag) {
    220                         this(tag, null);
    221                 }
    222 
    223                 public GuessStreetValueHandler(String tag, OSMAddress aNode) {
    224                         super(tag, aNode, 200.0);
    225                 }
    226 
    227                 /* (non-Javadoc)
    228                  * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Node)
    229                  */
    230                 @Override
    231                 public void visit(Node n) {
    232                         // do nothing
    233                 }
    234 
    235                 /* (non-Javadoc)
    236                  * @see org.openstreetmap.josm.plugins.fixAddresses.GuessedValueHandler#visit(org.openstreetmap.josm.data.osm.Way)
    237                  */
    238                 @Override
    239                 public void visit(Way w) {
    240                         if (TagUtils.isStreetSupportingHousenumbers(w)) {
    241                                 OSMAddress aNode = getAddressNode();
    242                                 String newVal = TagUtils.getNameValue(w);
    243                                
    244                                 if (newVal != null) {
    245                                         double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w);
    246                                        
    247                                         if (dist < minDist && dist < getMaxDistance()) {
    248                                                 minDist = dist;
    249                                                 currentValue = newVal;
    250                                                 srcNode = w;
    251                                                 //aNode.setGuessedValue(getTag(), currentValue, w);
    252                                         } else {
    253                                                 //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist));
    254                                         }
    255                                 }
    256                         }
    257                 }
    258         }
     26    private List<OSMAddress> addressesToGuess;
     27    private List<IProgressMonitorFinishedListener> finishListeners = new ArrayList<IProgressMonitorFinishedListener>();
     28    private boolean isRunning = false;
     29    private boolean canceled;
     30
     31    private GuessedValueHandler[] wayGuessers = new GuessedValueHandler[]{new GuessStreetValueHandler(TagUtils.ADDR_STREET_TAG)};
     32    private GuessedValueHandler[] nodeGuessers = new GuessedValueHandler[]{
     33            new GuessedValueHandler(TagUtils.ADDR_POSTCODE_TAG, 500.0),
     34            new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 5000.0),
     35            new GuessedValueHandler(TagUtils.ADDR_STATE_TAG, 5000.0),
     36            new GuessedValueHandler(TagUtils.ADDR_COUNTRY_TAG, 5000.0),
     37            new GuessedValueHandler(TagUtils.ADDR_CITY_TAG, 2000.0)
     38    };
     39
     40    /**
     41     * Instantiates a new guess address runnable.
     42     *
     43     * @param addresses the addresses to guess the values for
     44     * @param title the title of progress monitor
     45     */
     46    public GuessAddressRunnable(List<OSMAddress> addresses, String title) {
     47        super(title != null ? title : tr("Searching"));
     48        setAddressEditContainer(addresses);
     49    }
     50
     51    /**
     52     * Sets the address edit container.
     53     *
     54     * @param nodes the new address edit container
     55     */
     56    public void setAddressEditContainer(List<OSMAddress> nodes) {
     57        if (isRunning) {
     58            throw new ConcurrentModificationException();
     59        }
     60        this.addressesToGuess = nodes;
     61    }
     62
     63    /**
     64     * Gets the addresses to guess.
     65     *
     66     * @return the addresses to guess
     67     */
     68    public List<OSMAddress> getAddressesToGuess() {
     69        return addressesToGuess;
     70    }
     71    /**
     72     * @return the isRunning
     73     */
     74    public boolean isRunning() {
     75        return isRunning;
     76    }
     77
     78    /**
     79     * Adds a finish listener.
     80     *
     81     * @param l the listener to add
     82     */
     83    public void addFinishListener(IProgressMonitorFinishedListener l) {
     84        finishListeners.add(l);
     85    }
     86
     87    /**
     88     * Removes a finish listener.
     89     *
     90     * @param l the listener to remove
     91     */
     92    public void removeFinishListener(IProgressMonitorFinishedListener l) {
     93        finishListeners.remove(l);
     94    }
     95
     96    /**
     97     * Fires the 'finished' event after the thread has done his work.
     98     */
     99    protected void fireFinished() {
     100        for (IProgressMonitorFinishedListener l : finishListeners) {
     101            l.finished();           
     102        }
     103        // this event is fired only once, then we disconnect all listeners
     104        finishListeners.clear();
     105    }
     106
     107    @Override
     108    protected void cancel() {
     109        canceled = true;
     110    }
     111
     112    @Override
     113    protected void finish() {
     114        // nothing to do yet
     115    }
     116
     117    @Override
     118    protected void realRun() throws SAXException, IOException,
     119    OsmTransferException {
     120
     121        if (Main.main.getCurrentDataSet() == null || addressesToGuess == null) return;
     122
     123        isRunning = true;
     124        canceled = false;
     125
     126        // Start progress monitor to guess address values
     127        progressMonitor.subTask(tr("Searching") + "...");
     128
     129        try {
     130            progressMonitor.setTicksCount(addressesToGuess.size());
     131
     132            List<OSMAddress> shadowCopy = new ArrayList<OSMAddress>(addressesToGuess);
     133            for (OSMAddress aNode : shadowCopy) {
     134                if (!aNode.needsGuess()) { // nothing to do
     135                    progressMonitor.worked(1);
     136                    continue;
     137                }
     138
     139                // check for cancel
     140                if (canceled) {
     141                    break;
     142                }
     143
     144                // Update progress monitor
     145                progressMonitor.subTask(tr("Guess values for ") + aNode);
     146
     147                // Run way-related guessers
     148                for (int i = 0; i < wayGuessers.length; i++) {
     149                    GuessedValueHandler guesser = wayGuessers[i];
     150                   
     151                    guesser.setAddressNode(aNode);
     152
     153                    // visit osm data
     154                    for (Way way : Main.main.getCurrentDataSet().getWays()) {
     155                        if (canceled) {
     156                            break;
     157                        }
     158                        way.accept(guesser);                       
     159                    }
     160                   
     161                    String guessedVal = guesser.getCurrentValue();
     162                    if (guessedVal != null) {
     163                        aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode());
     164                    }
     165                }
     166               
     167                // Run node-related guessers
     168                for (int i = 0; i < nodeGuessers.length; i++) {
     169                    GuessedValueHandler guesser = nodeGuessers[i];
     170                   
     171                    guesser.setAddressNode(aNode);
     172
     173                    // visit osm data
     174                    for (Node node : Main.main.getCurrentDataSet().getNodes()) {
     175                        if (canceled) {
     176                            break;
     177                        }
     178                        node.accept(guesser);                       
     179                    }
     180                   
     181                    String guessedVal = guesser.getCurrentValue();
     182                    if (guessedVal != null) {
     183                        aNode.setGuessedValue(guesser.getTag(), guessedVal, guesser.getSourceNode());
     184                    }
     185                }
     186
     187                // report progress
     188                progressMonitor.worked(1);
     189            }
     190        } finally {
     191            isRunning = false;
     192            fireFinished();
     193        }
     194    }
     195
     196    // TODO: Put in separate file
     197    private class GuessStreetValueHandler extends GuessedValueHandler {
     198        public GuessStreetValueHandler(String tag) {
     199            this(tag, null);
     200        }
     201
     202        public GuessStreetValueHandler(String tag, OSMAddress aNode) {
     203            super(tag, aNode, 200.0);
     204        }
     205
     206        @Override
     207        public void visit(Node n) {
     208            // do nothing
     209        }
     210
     211        @Override
     212        public void visit(Way w) {
     213            if (TagUtils.isStreetSupportingHousenumbers(w)) {
     214                OSMAddress aNode = getAddressNode();
     215                String newVal = TagUtils.getNameValue(w);
     216               
     217                if (newVal != null) {
     218                    double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w);
     219                   
     220                    if (dist < minDist && dist < getMaxDistance()) {
     221                        minDist = dist;
     222                        currentValue = newVal;
     223                        srcNode = w;
     224                        //aNode.setGuessedValue(getTag(), currentValue, w);
     225                    } else {
     226                        //System.out.println(String.format("Skipped %s: %4.2f m", TagUtils.getNameValue(w), dist));
     227                    }
     228                }
     229            }
     230        }
     231    }
    259232}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/GuessedValueHandler.java

    r27326 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    3018public class GuessedValueHandler implements Visitor {
    3119
    32         /** Default maximum distance (100m) */
    33         private static final double DEFAULT_MAX_DIST = 100.0;
     20    /** Default maximum distance (100m) */
     21    private static final double DEFAULT_MAX_DIST = 100.0;
    3422
    35         private String tag;
    36         protected double minDist;
    37         protected String currentValue;
    38         private OSMAddress aNode;
    39         private double maxDist = DEFAULT_MAX_DIST;
    40         protected OsmPrimitive srcNode;
     23    private String tag;
     24    protected double minDist;
     25    protected String currentValue;
     26    private OSMAddress aNode;
     27    private double maxDist = DEFAULT_MAX_DIST;
     28    protected OsmPrimitive srcNode;
    4129
    42         /**
    43         * Instantiates a new guessed value handler without node and default maximum distance.
    44         *
    45         * @param tag the tag to find the guessed value for.
    46         */
    47         public GuessedValueHandler(String tag) {
    48                 this(tag, null, DEFAULT_MAX_DIST);
    49         }
    50        
    51         /**
    52         * Instantiates a new guessed value handler without node.
    53         *
    54         * @param tag the tag to find the guessed value for.
    55         * @param maxDist the maximum distance for a node/way to be considered as guessed value.
    56         */
    57         public GuessedValueHandler(String tag, double maxDist) {
    58                 this(tag, null, maxDist);
    59         }
    60        
    61         /**
    62         * Instantiates a new guessed value handler.
    63         *
    64         * @param tag the tag to find the guessed value for.
    65         * @param aNode the address node to guess the values for.
    66         * @param maxDist the maximum distance for a node/way to be considered as guessed value.
    67         */
    68         public GuessedValueHandler(String tag, OSMAddress aNode) {
    69                 this(tag, aNode, DEFAULT_MAX_DIST);
    70         }
     30    /**
     31    * Instantiates a new guessed value handler without node and default maximum distance.
     32    *
     33    * @param tag the tag to find the guessed value for.
     34    */
     35    public GuessedValueHandler(String tag) {
     36        this(tag, null, DEFAULT_MAX_DIST);
     37    }
     38   
     39    /**
     40    * Instantiates a new guessed value handler without node.
     41    *
     42    * @param tag the tag to find the guessed value for.
     43    * @param maxDist the maximum distance for a node/way to be considered as guessed value.
     44    */
     45    public GuessedValueHandler(String tag, double maxDist) {
     46        this(tag, null, maxDist);
     47    }
     48   
     49    /**
     50    * Instantiates a new guessed value handler.
     51    *
     52    * @param tag the tag to find the guessed value for.
     53    * @param aNode the address node to guess the values for.
     54    * @param maxDist the maximum distance for a node/way to be considered as guessed value.
     55    */
     56    public GuessedValueHandler(String tag, OSMAddress aNode) {
     57        this(tag, aNode, DEFAULT_MAX_DIST);
     58    }
    7159
    72         /**
    73         * Instantiates a new guessed value handler.
    74         *
    75         * @param tag the tag to find the guessed value for.
    76         * @param aNode the address node to guess the values for.
    77         * @param maxDist the maximum distance for a node/way to be considered as guessed value.
    78         */
    79         public GuessedValueHandler(String tag, OSMAddress aNode, double maxDist) {
    80                 super();
     60    /**
     61    * Instantiates a new guessed value handler.
     62    *
     63    * @param tag the tag to find the guessed value for.
     64    * @param aNode the address node to guess the values for.
     65    * @param maxDist the maximum distance for a node/way to be considered as guessed value.
     66    */
     67    public GuessedValueHandler(String tag, OSMAddress aNode, double maxDist) {
     68        super();
    8169
    82                 if (StringUtils.isNullOrEmpty(tag)) {
    83                         throw new RuntimeException("Tag must not be empty or null!");
    84                 }
     70        if (StringUtils.isNullOrEmpty(tag)) {
     71            throw new RuntimeException("Tag must not be empty or null!");
     72        }
    8573
    86                 if (maxDist < 1.0) { // clip value
    87                         maxDist = 1.0;
    88                 }
    89                
    90                 this.tag = tag;
    91                 this.maxDist = maxDist;
    92                 setAddressNode(aNode);         
    93         }
     74        if (maxDist < 1.0) { // clip value
     75            maxDist = 1.0;
     76        }
     77       
     78        this.tag = tag;
     79        this.maxDist = maxDist;
     80        setAddressNode(aNode);       
     81    }
    9482
    95         /**
    96         * Gets the address node to make the guess for.
    97         *
    98         * @return the aNode
    99         */
    100         protected OSMAddress getAddressNode() {
    101                 return aNode;
    102         }
    103        
     83    /**
     84    * Gets the address node to make the guess for.
     85    *
     86    * @return the aNode
     87    */
     88    protected OSMAddress getAddressNode() {
     89        return aNode;
     90    }
     91   
    10492
    105         /**
    106         * Sets the address node to make the guess for.
    107         * @param aNode
    108         */
    109         public void setAddressNode(OSMAddress aNode) {         
    110                 this.aNode = aNode;
    111                 // reset search results
    112                 minDist = Double.MAX_VALUE;
    113                 srcNode = null;
    114                 currentValue = null;           
    115         }
     93    /**
     94    * Sets the address node to make the guess for.
     95    * @param aNode
     96    */
     97    public void setAddressNode(OSMAddress aNode) {       
     98        this.aNode = aNode;
     99        // reset search results
     100        minDist = Double.MAX_VALUE;
     101        srcNode = null;
     102        currentValue = null;       
     103    }
    116104
    117         /**
    118         * Gets the max distance allowed to consider a node as guess.
    119         * If the distance of the node is greater than maxDist, the
    120         * node/way will be ignored.
    121         *
    122         * @return the maxDist
    123         */
    124         protected double getMaxDistance() {
    125                 return maxDist;
    126         }
     105    /**
     106    * Gets the max distance allowed to consider a node as guess.
     107    * If the distance of the node is greater than maxDist, the
     108    * node/way will be ignored.
     109    *
     110    * @return the maxDist
     111    */
     112    protected double getMaxDistance() {
     113        return maxDist;
     114    }
    127115
    128         /**
    129         * Gets the tag name to use as guess.
    130         *
    131         * @return the tag
    132         */
    133         protected String getTag() {
    134                 return tag;
    135         }
     116    /**
     117    * Gets the tag name to use as guess.
     118    *
     119    * @return the tag
     120    */
     121    protected String getTag() {
     122        return tag;
     123    }
    136124
    137         /**
    138         * Gets the distance of the node/way which has been used for the guessed value.
    139         *
    140         * @return the minDist
    141         */
    142         protected double getMinimumDist() {
    143                 return minDist;
    144         }
     125    /**
     126    * Gets the distance of the node/way which has been used for the guessed value.
     127    *
     128    * @return the minDist
     129    */
     130    protected double getMinimumDist() {
     131        return minDist;
     132    }
    145133
    146         /**
    147         * Gets the current guessed value or null, if no guess has been possible (so far).
    148         *
    149         * @return the currentValue
    150         */
    151         public String getCurrentValue() {
    152                 return currentValue;
    153         }
    154        
    155        
    156         /**
    157         * Gets the node/way which has been selected for the guess.
    158         * @return The source node or null; if no appropriate source primitive has been found
    159         */
    160         public OsmPrimitive getSourceNode() {
    161                 return srcNode;
    162         }
     134    /**
     135    * Gets the current guessed value or null, if no guess has been possible (so far).
     136    *
     137    * @return the currentValue
     138    */
     139    public String getCurrentValue() {
     140        return currentValue;
     141    }
     142   
     143   
     144    /**
     145    * Gets the node/way which has been selected for the guess.
     146    * @return The source node or null; if no appropriate source primitive has been found
     147    */
     148    public OsmPrimitive getSourceNode() {
     149        return srcNode;
     150    }
    163151
    164         /**
    165         * Check if we need to visit the OSM data
    166         *
    167         * @return true, if successful
    168         */
    169         public boolean needsGuess() {
    170                 return aNode.needsGuessedValue(tag);
    171         }
     152    /**
     153    * Check if we need to visit the OSM data
     154    *
     155    * @return true, if successful
     156    */
     157    public boolean needsGuess() {
     158        return aNode.needsGuessedValue(tag);
     159    }
    172160
    173         /* (non-Javadoc)
    174          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Node)
    175          */
    176         @Override
    177         public void visit(Node n) {
    178                 assert aNode != null;
    179                
    180                 if (n.hasKey(tag)) {
    181                         double dist = n.getCoor().greatCircleDistance(aNode.getCoor());
    182                         if (dist < minDist && dist < maxDist) {
    183                                 minDist = dist;
    184                                 currentValue = n.get(tag);
    185                                 srcNode = n;
    186                         }
    187                 }
    188         }
     161    @Override
     162    public void visit(Node n) {
     163        assert aNode != null;
     164       
     165        if (n.hasKey(tag)) {
     166            double dist = n.getCoor().greatCircleDistance(aNode.getCoor());
     167            if (dist < minDist && dist < maxDist) {
     168                minDist = dist;
     169                currentValue = n.get(tag);
     170                srcNode = n;
     171            }
     172        }
     173    }
    189174
    190         /* (non-Javadoc)
    191          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Way)
    192          */
    193         @Override
    194         public void visit(Way w) {
    195                 assert aNode != null;
    196                
    197                 if (w.hasKey(tag)) {
    198                         double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w);
    199                         if (dist < minDist && dist < maxDist) {
    200                                 minDist = dist;
    201                                 currentValue = w.get(tag);
    202                                 srcNode = w;
    203                         }
    204                 }
    205         }
     175    @Override
     176    public void visit(Way w) {
     177        assert aNode != null;
     178       
     179        if (w.hasKey(tag)) {
     180            double dist = OsmUtils.getMinimumDistanceToWay(aNode.getCoor(), w);
     181            if (dist < minDist && dist < maxDist) {
     182                minDist = dist;
     183                currentValue = w.get(tag);
     184                srcNode = w;
     185            }
     186        }
     187    }
    206188
    207         /* (non-Javadoc)
    208          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Relation)
    209          */
    210         @Override
    211         public void visit(Relation e) {
    212                 // nothing to do (yet)
    213         }
     189    @Override
     190    public void visit(Relation e) {
     191        // nothing to do (yet)
     192    }
    214193
    215         /* (non-Javadoc)
    216          * @see org.openstreetmap.josm.data.osm.visitor.Visitor#visit(org.openstreetmap.josm.data.osm.Changeset)
    217          */
    218         @Override
    219         public void visit(Changeset cs) {
    220                 // nothing to do (yet)
    221         }
     194    @Override
     195    public void visit(Changeset cs) {
     196        // nothing to do (yet)
     197    }
    222198}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IAddressEditContainerListener.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     4public interface IAddressEditContainerListener {
     5    /**
     6     * Notifies clients that the container has been changed.
     7     * @param container
     8     */
     9    public void containerChanged(AddressEditContainer container);
    1610
    17 public interface IAddressEditContainerListener {
    18         /**
    19          * Notifies clients that the container has been changed.
    20          * @param container
    21          */
    22         public void containerChanged(AddressEditContainer container);
    23 
    24         /**
    25          * Notifies clients that an entity has been changed.
    26          */
    27         public void entityChanged(IOSMEntity node);
     11    /**
     12     * Notifies clients that an entity has been changed.
     13     */
     14    public void entityChanged(IOSMEntity node);
    2815}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IAllKnowingTrashHeap.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    186public interface IAllKnowingTrashHeap {
    197
    20         /**
    21         * Gets the list containing the best matching (closest) street names.
    22         *
    23         * @param name the name of the street to find the matches for.
    24         * @param maxEntries the maximum number of matches.
    25         * @return the closest street names
    26         */
    27         public List<String> getClosestStreetNames(String name, int maxEntries);
     8    /**
     9    * Gets the list containing the best matching (closest) street names.
     10    *
     11    * @param name the name of the street to find the matches for.
     12    * @param maxEntries the maximum number of matches.
     13    * @return the closest street names
     14    */
     15    public List<String> getClosestStreetNames(String name, int maxEntries);
    2816
    29         /**
    30         * Gets the closest street name to the given name.
    31         *
    32         * @param name the name of the street to find a match for.
    33         * @return the closest street name
    34         */
    35         public String getClosestStreetName(String name);
     17    /**
     18    * Gets the closest street name to the given name.
     19    *
     20    * @param name the name of the street to find a match for.
     21    * @return the closest street name
     22    */
     23    public String getClosestStreetName(String name);
    3624
    37         /**
    38         * Checks if the given street name is valid.
    39         *
    40         * @param name the name of the street to check.
    41         * @return true, if street name is valid; otherwise false.
    42         */
    43         public boolean isValidStreetName(String name);
     25    /**
     26    * Checks if the given street name is valid.
     27    *
     28    * @param name the name of the street to check.
     29    * @return true, if street name is valid; otherwise false.
     30    */
     31    public boolean isValidStreetName(String name);
    4432}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ICommandListener.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    175
    186public interface ICommandListener {
    19         /**
    20         * Called by a node entity if a command has been created. Clients may collect
    21         * these commands to define a sequence command.
    22         * @param entity The entity which created/used the command.
    23         * @param command The command instance to process by the enclosing command listener.
    24         */
    25         public void commandIssued(IOSMEntity entity, Command command);
     7    /**
     8    * Called by a node entity if a command has been created. Clients may collect
     9    * these commands to define a sequence command.
     10    * @param entity The entity which created/used the command.
     11    * @param command The command instance to process by the enclosing command listener.
     12    */
     13    public void commandIssued(IOSMEntity entity, Command command);
    2614}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IOSMEntity.java

    r29869 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2513 *
    2614 */
     15public interface IOSMEntity extends Comparable<IOSMEntity> {
     16    /**
     17     * Gets the underlying OSM object.
     18     * @return
     19     */
     20    public OsmPrimitive getOsmObject();
    2721
    28 public interface IOSMEntity extends Comparable<IOSMEntity> {
    29         /**
    30          * Gets the underlying OSM object.
    31          * @return
    32          */
    33         public OsmPrimitive getOsmObject();
     22    /**
     23     * Checks if underlying OSM object has a name.
     24     * @return
     25     */
     26    public boolean hasName();
    3427
    35         /**
    36          * Checks if underlying OSM object has a name.
    37         * @return
    38         */
    39         public boolean hasName();
     28    /**
     29     * Gets the name of the entity node.
     30    * @return
     31    */
     32    public String getName();
    4033
    41         /**
    42          * Gets the name of the entity node.
    43         * @return
    44         */
    45         public String getName();
     34    /**
     35     * Gets the children of the entity node.
     36    * @return
     37    */
     38    public List<IOSMEntity> getChildren();
    4639
    47         /**
    48          * Gets the children of the entity node.
    49          * @return
    50          */
    51         public List<IOSMEntity> getChildren();
     40    /**
     41     * Gets the coordinate of the node. If the underlying object is a
     42     * node, it just returns the node coordinate. For ways and areas, this
     43     * method returns the coordinate of the center (balance point).
     44     * @return
     45     */
     46    public LatLon getCoor();
    5247
    53         /**
    54          * Gets the coordinate of the node. If the underlying object is a
    55          * node, it just returns the node coordinate. For ways and areas, this
    56          * method returns the coordinate of the center (balance point).
    57          * @return
    58          */
    59         public LatLon getCoor();
     48    /**
     49     * Adds a command listener.
     50     * @param listener
     51     */
     52    public void addCommandListener(ICommandListener listener);
    6053
    61         /**
    62          * Adds a command listener.
    63         * @param listener
    64         */
    65         public void addCommandListener(ICommandListener listener);
     54    /**
     55     * Removes a command listener.
     56    * @param listener
     57    */
     58    public void removeCommandListener(ICommandListener listener);
    6659
    67         /**
    68          * Removes a command listener.
    69          * @param listener
    70          */
    71         public void removeCommandListener(ICommandListener listener);
     60    /**
     61     * Collects problems and possible solutions.
     62     *
     63     * @param trashHeap the trash heap to ask for possible solutions
     64     * @param visitor the problem visitor
     65     */
     66    public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor);
    7267
    73         /**
    74          * Collects problems and possible solutions.
    75          *
    76          * @param trashHeap the trash heap to ask for possible solutions
    77          * @param visitor the problem visitor
    78          */
    79         public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor);
    80 
    81         int compareTo(IOSMEntity o);
     68    int compareTo(IOSMEntity o);
    8269}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProblem.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    186public interface IProblem {
    197
    20         /**
    21         * Gets the OSM entity which causes the problem.
    22         *
    23         * @return the source
    24         */
    25         public IOSMEntity getSource();
     8    /**
     9    * Gets the OSM entity which causes the problem.
     10    *
     11    * @return the source
     12    */
     13    public IOSMEntity getSource();
    2614
    27         /**
    28         * Gets the problem description.
    29         *
    30         * @return the description
    31         */
    32         public String getDescription();
     15    /**
     16    * Gets the problem description.
     17    *
     18    * @return the description
     19    */
     20    public String getDescription();
    3321
    34         /**
    35         * Gets the problem type.
    36         *
    37         * @return the type
    38         */
    39         public ProblemType getType();
     22    /**
     23    * Gets the problem type.
     24    *
     25    * @return the type
     26    */
     27    public ProblemType getType();
    4028
    41         /**
    42         * Gets the available solutions for this problem.
    43         *
    44         * @return the solutions
    45         */
    46         public List<ISolution> getSolutions();
     29    /**
     30    * Gets the available solutions for this problem.
     31    *
     32    * @return the solutions
     33    */
     34    public List<ISolution> getSolutions();
    4735
    48         /**
    49         * Adds a possible solution to the problem.
    50         *
    51         * @param solution the solution
    52         */
    53         public void addSolution(ISolution solution);
     36    /**
     37    * Adds a possible solution to the problem.
     38    *
     39    * @param solution the solution
     40    */
     41    public void addSolution(ISolution solution);
    5442
    55         /**
    56         * Removes a solution from this problem.
    57         *
    58         * @param solution the solution
    59         */
    60         public void removeSolution(ISolution solution);
     43    /**
     44    * Removes a solution from this problem.
     45    *
     46    * @param solution the solution
     47    */
     48    public void removeSolution(ISolution solution);
    6149
    62         /**
    63         * Removes all solutions from this problem.
    64         */
    65         public void clearSolutions();
     50    /**
     51    * Removes all solutions from this problem.
     52    */
     53    public void clearSolutions();
    6654
    67         /**
    68         * Applies a {@link ISolution} instance on the problem.
    69         *
    70         * @param solution the solution
    71         */
    72         public void applySolution(ISolution solution);
     55    /**
     56    * Applies a {@link ISolution} instance on the problem.
     57    *
     58    * @param solution the solution
     59    */
     60    public void applySolution(ISolution solution);
    7361}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProblemVisitor.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     4public interface IProblemVisitor {
     5    /**
     6     * Adds a problem without solution.
     7     *
     8     * @param problem the problem to add
     9     */
     10    public void addProblem(IProblem problem);
    1611
    17 public interface IProblemVisitor {
    18         /**
    19          * Adds a problem without solution.
    20          *
    21          * @param problem the problem to add
    22          */
    23         public void addProblem(IProblem problem);
    24 
    25         /**
    26          * Removes the problems of the given source.
    27          */
    28         public void removeProblemsOfSource(IOSMEntity entity);
     12    /**
     13     * Removes the problems of the given source.
     14     */
     15    public void removeProblemsOfSource(IOSMEntity entity);
    2916}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/IProgressMonitorFinishedListener.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
    164public interface IProgressMonitorFinishedListener {
    17         public void finished();
     5    public void finished();
    186}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ISolution.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    186public interface ISolution {
    197
    20         /**
    21         * Gets the description of the solution.
    22         *
    23         * @return the description
    24         */
    25         public String getDescription();
     8    /**
     9    * Gets the description of the solution.
     10    *
     11    * @return the description
     12    */
     13    public String getDescription();
    2614
    27         /**
    28         * Gets the action to execute for solving the problem.
    29         *
    30         * @return the action
    31         */
    32         public JosmAction getAction();
     15    /**
     16    * Gets the action to execute for solving the problem.
     17    *
     18    * @return the action
     19    */
     20    public JosmAction getAction();
    3321
    34         /**
    35         * Gets the solution type.
    36         *
    37         * @return the type
    38         */
    39         public SolutionType getType();
     22    /**
     23    * Gets the solution type.
     24    *
     25    * @return the type
     26    */
     27    public SolutionType getType();
    4028
    41         /**
    42         * Executes one or more actions to solve a problem.
    43         */
    44         public void solve();
     29    /**
     30    * Executes one or more actions to solve a problem.
     31    */
     32    public void solve();
    4533}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMAddress.java

    r29967 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    4634
    4735    public OSMAddress(OsmPrimitive osmObject) {
    48         super(osmObject);
    49     }
    50 
    51     /*
    52      * (non-Javadoc)
    53      *
    54      * @see
    55      * org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#setOsmObject
    56      * (org.openstreetmap.josm.data.osm.OsmPrimitive)
    57      */
     36    super(osmObject);
     37    }
     38
    5839    @Override
    5940    public void setOsmObject(OsmPrimitive osmObject) {
    60         super.setOsmObject(osmObject);
    61 
    62         isPartOfInterpolation = OsmUtils
    63                 .getValuesFromAddressInterpolation(this);
    64         isPartOfAssocStreetRel = OsmUtils.getValuesFromRelation(this);
     41    super.setOsmObject(osmObject);
     42
     43    isPartOfInterpolation = OsmUtils
     44        .getValuesFromAddressInterpolation(this);
     45    isPartOfAssocStreetRel = OsmUtils.getValuesFromRelation(this);
    6546    }
    6647
     
    7253     */
    7354    public boolean isComplete() {
    74         boolean isComplete = hasCity() && hasHouseNumber() && hasCity()
    75                 && hasStreetName();
    76 
    77         // Check, if "addr:state" is required (US and AU)
    78         if (TagUtils.isStateRequired()) {
    79             isComplete = isComplete && hasState();
    80         }
    81 
    82         // Check, if user checked "ignore post code"
    83         if (!FixAddressesPlugin.getPreferences().isIgnorePostCode()) {
    84             isComplete = isComplete && hasPostalCode()
    85                     && PostalCodeChecker.hasValidPostalCode(this);
    86         }
    87 
    88         return isComplete;
     55    boolean isComplete = hasCity() && hasHouseNumber() && hasCity()
     56        && hasStreetName();
     57
     58    // Check, if "addr:state" is required (US and AU)
     59    if (TagUtils.isStateRequired()) {
     60        isComplete = isComplete && hasState();
     61    }
     62
     63    // Check, if user checked "ignore post code"
     64    if (!FixAddressesPlugin.getPreferences().isIgnorePostCode()) {
     65        isComplete = isComplete && hasPostalCode()
     66            && PostalCodeChecker.hasValidPostalCode(this);
     67    }
     68
     69    return isComplete;
    8970    }
    9071
     
    9576     */
    9677    public String getStreetName() {
    97         return getTagValueWithGuess(TagUtils.ADDR_STREET_TAG);
     78    return getTagValueWithGuess(TagUtils.ADDR_STREET_TAG);
    9879    }
    9980
     
    10889     */
    10990    private String getTagValueWithGuess(String tag) {
    110         if (StringUtils.isNullOrEmpty(tag))
    111             return MISSING_TAG;
    112         if (osmObject == null)
    113             return MISSING_TAG;
    114 
    115         if (!osmObject.hasKey(tag)
    116                 || StringUtils.isNullOrEmpty(osmObject.get(tag))) {
    117             if (!hasDerivedValue(tag)) {
    118                 // object does not have this tag -> check for guess
    119                 if (hasGuessedValue(tag)) {
    120                     return "*" + getGuessedValue(tag);
    121                 } else {
    122                     // give up
    123                     return MISSING_TAG;
    124                 }
    125             } else { // ok, use derived value known via associated relation or
    126                      // way
    127                 return getDerivedValue(tag);
    128             }
    129         } else { // get existing tag value
    130             return osmObject.get(tag);
    131         }
     91    if (StringUtils.isNullOrEmpty(tag))
     92        return MISSING_TAG;
     93    if (osmObject == null)
     94        return MISSING_TAG;
     95
     96    if (!osmObject.hasKey(tag)
     97        || StringUtils.isNullOrEmpty(osmObject.get(tag))) {
     98        if (!hasDerivedValue(tag)) {
     99        // object does not have this tag -> check for guess
     100        if (hasGuessedValue(tag)) {
     101            return "*" + getGuessedValue(tag);
     102        } else {
     103            // give up
     104            return MISSING_TAG;
     105        }
     106        } else { // ok, use derived value known via associated relation or
     107             // way
     108        return getDerivedValue(tag);
     109        }
     110    } else { // get existing tag value
     111        return osmObject.get(tag);
     112    }
    132113    }
    133114
     
    138119     */
    139120    public boolean hasStreetName() {
    140         return hasTag(TagUtils.ADDR_STREET_TAG) || isPartOfRelation();
     121    return hasTag(TagUtils.ADDR_STREET_TAG) || isPartOfRelation();
    141122    }
    142123
     
    147128     */
    148129    public String getGuessedStreetName() {
    149         return getGuessedValue(TagUtils.ADDR_STREET_TAG);
     130    return getGuessedValue(TagUtils.ADDR_STREET_TAG);
    150131    }
    151132
     
    159140     */
    160141    public void setGuessedStreetName(String guessedStreetName,
    161             OsmPrimitive srcObj) {
    162         setGuessedValue(TagUtils.ADDR_STREET_TAG, guessedStreetName, srcObj);
     142        OsmPrimitive srcObj) {
     143    setGuessedValue(TagUtils.ADDR_STREET_TAG, guessedStreetName, srcObj);
    163144    }
    164145
     
    169150     */
    170151    public boolean hasGuessedStreetName() {
    171         return hasGuessedValue(TagUtils.ADDR_STREET_TAG);
     152    return hasGuessedValue(TagUtils.ADDR_STREET_TAG);
    172153    }
    173154
     
    176157     */
    177158    public String getGuessedPostalCode() {
    178         return getGuessedValue(TagUtils.ADDR_POSTCODE_TAG);
     159    return getGuessedValue(TagUtils.ADDR_POSTCODE_TAG);
    179160    }
    180161
     
    188169     */
    189170    public void setGuessedPostalCode(String guessedPostCode, OsmPrimitive srcObj) {
    190         setGuessedValue(TagUtils.ADDR_POSTCODE_TAG, guessedPostCode, srcObj);
     171    setGuessedValue(TagUtils.ADDR_POSTCODE_TAG, guessedPostCode, srcObj);
    191172    }
    192173
     
    197178     */
    198179    public boolean hasGuessedPostalCode() {
    199         return hasGuessedValue(TagUtils.ADDR_POSTCODE_TAG);
     180    return hasGuessedValue(TagUtils.ADDR_POSTCODE_TAG);
    200181    }
    201182
     
    204185     */
    205186    public String getGuessedCity() {
    206         return getGuessedValue(TagUtils.ADDR_CITY_TAG);
     187    return getGuessedValue(TagUtils.ADDR_CITY_TAG);
    207188    }
    208189
     
    216197     */
    217198    public void setGuessedCity(String guessedCity, OsmPrimitive srcObj) {
    218         setGuessedValue(TagUtils.ADDR_CITY_TAG, guessedCity, srcObj);
     199    setGuessedValue(TagUtils.ADDR_CITY_TAG, guessedCity, srcObj);
    219200    }
    220201
     
    225206     */
    226207    public boolean hasGuessedCity() {
    227         return hasGuessedValue(TagUtils.ADDR_CITY_TAG);
     208    return hasGuessedValue(TagUtils.ADDR_CITY_TAG);
    228209    }
    229210
     
    234215     */
    235216    public boolean hasGuesses() {
    236         return guessedValues.size() > 0;
     217    return guessedValues.size() > 0;
    237218    }
    238219
     
    241222     */
    242223    public void applyAllGuesses() {
    243         for (String tag : guessedValues.keySet()) {
    244             applyGuessForTag(tag);
    245         }
    246 
    247         // Clear all guesses
    248         guessedValues.clear();
    249         guessedObjects.clear();
     224    for (String tag : guessedValues.keySet()) {
     225        applyGuessForTag(tag);
     226    }
     227
     228    // Clear all guesses
     229    guessedValues.clear();
     230    guessedObjects.clear();
    250231    }
    251232
     
    257238     */
    258239    public void applyGuessForTag(String tag) {
    259         if (guessedValues.containsKey(tag)) {
    260             String val = guessedValues.get(tag);
    261             if (!StringUtils.isNullOrEmpty(val)) {
    262                 setOSMTag(tag, val);
    263             }
    264         }
     240    if (guessedValues.containsKey(tag)) {
     241        String val = guessedValues.get(tag);
     242        if (!StringUtils.isNullOrEmpty(val)) {
     243        setOSMTag(tag, val);
     244        }
     245    }
    265246    }
    266247
     
    271252     */
    272253    public String getPostalCode() {
    273         String pc = getTagValueWithGuess(TagUtils.ADDR_POSTCODE_TAG);
    274 
    275         if (!MISSING_TAG.equals(pc)
    276                 && !PostalCodeChecker.hasValidPostalCode(getCountry(), pc)) {
    277             pc = "(!)" + pc;
    278         }
    279         return pc;
     254    String pc = getTagValueWithGuess(TagUtils.ADDR_POSTCODE_TAG);
     255
     256    if (!MISSING_TAG.equals(pc)
     257        && !PostalCodeChecker.hasValidPostalCode(getCountry(), pc)) {
     258        pc = "(!)" + pc;
     259    }
     260    return pc;
    280261    }
    281262
     
    286267     */
    287268    public boolean hasValidPostalCode() {
    288         return PostalCodeChecker.hasValidPostalCode(this);
     269    return PostalCodeChecker.hasValidPostalCode(this);
    289270    }
    290271
     
    295276     */
    296277    public boolean hasPostalCode() {
    297         return hasTag(TagUtils.ADDR_POSTCODE_TAG);
     278    return hasTag(TagUtils.ADDR_POSTCODE_TAG);
    298279    }
    299280
     
    304285     */
    305286    public String getHouseNumber() {
    306         if (!TagUtils.hasAddrHousenumberTag(osmObject)) {
    307             if (!isPartOfInterpolation) {
    308                 return MISSING_TAG;
    309             } else {
    310                 return INTERPOLATION_TAG;
    311             }
    312         }
    313         return TagUtils.getAddrHousenumberValue(osmObject);
     287    if (!TagUtils.hasAddrHousenumberTag(osmObject)) {
     288        if (!isPartOfInterpolation) {
     289        return MISSING_TAG;
     290        } else {
     291        return INTERPOLATION_TAG;
     292        }
     293    }
     294    return TagUtils.getAddrHousenumberValue(osmObject);
    314295    }
    315296
     
    320301     */
    321302    public boolean hasHouseNumber() {
    322         return TagUtils.hasAddrHousenumberTag(osmObject)
    323                 || isPartOfInterpolation;
    324     }
    325 
    326     /*
    327      * (non-Javadoc)
    328      *
    329      * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#getName()
    330      */
     303    return TagUtils.hasAddrHousenumberTag(osmObject)
     304        || isPartOfInterpolation;
     305    }
     306
    331307    public String getName() {
    332         String name = TagUtils.getNameValue(osmObject);
    333         if (!StringUtils.isNullOrEmpty(name)) {
    334             return TagUtils.getAddrHousenameValue(osmObject);
    335         }
    336 
    337         return "";
     308    String name = TagUtils.getNameValue(osmObject);
     309    if (!StringUtils.isNullOrEmpty(name)) {
     310        return TagUtils.getAddrHousenameValue(osmObject);
     311    }
     312
     313    return "";
    338314    }
    339315
     
    344320     */
    345321    protected boolean isPartOfInterpolation() {
    346         return isPartOfInterpolation;
     322    return isPartOfInterpolation;
    347323    }
    348324
     
    353329     */
    354330    protected boolean isPartOfRelation() {
    355         return isPartOfAssocStreetRel;
     331    return isPartOfAssocStreetRel;
    356332    }
    357333
     
    362338     */
    363339    public String getCity() {
    364         return getTagValueWithGuess(TagUtils.ADDR_CITY_TAG);
     340    return getTagValueWithGuess(TagUtils.ADDR_CITY_TAG);
    365341    }
    366342
     
    371347     */
    372348    public boolean hasCity() {
    373         return hasTag(TagUtils.ADDR_CITY_TAG);
     349    return hasTag(TagUtils.ADDR_CITY_TAG);
    374350    }
    375351
     
    380356     */
    381357    public String getState() {
    382         return getTagValueWithGuess(TagUtils.ADDR_STATE_TAG);
     358    return getTagValueWithGuess(TagUtils.ADDR_STATE_TAG);
    383359    }
    384360
     
    389365     */
    390366    public boolean hasState() {
    391         return hasTag(TagUtils.ADDR_STATE_TAG);
     367    return hasTag(TagUtils.ADDR_STATE_TAG);
    392368    }
    393369
     
    398374     */
    399375    public String getCountry() {
    400         return getTagValueWithGuess(TagUtils.ADDR_COUNTRY_TAG);
     376    return getTagValueWithGuess(TagUtils.ADDR_COUNTRY_TAG);
    401377    }
    402378
     
    407383     */
    408384    public boolean hasCountry() {
    409         return hasTag(TagUtils.ADDR_COUNTRY_TAG);
     385    return hasTag(TagUtils.ADDR_COUNTRY_TAG);
    410386    }
    411387
     
    414390     */
    415391    public void removeAllAddressTags() {
    416         removeOSMTag(TagUtils.ADDR_CITY_TAG);
    417         removeOSMTag(TagUtils.ADDR_COUNTRY_TAG);
    418         removeOSMTag(TagUtils.ADDR_POSTCODE_TAG);
    419         removeOSMTag(TagUtils.ADDR_HOUSENUMBER_TAG);
    420         removeOSMTag(TagUtils.ADDR_STATE_TAG);
    421         removeOSMTag(TagUtils.ADDR_STREET_TAG);
     392    removeOSMTag(TagUtils.ADDR_CITY_TAG);
     393    removeOSMTag(TagUtils.ADDR_COUNTRY_TAG);
     394    removeOSMTag(TagUtils.ADDR_POSTCODE_TAG);
     395    removeOSMTag(TagUtils.ADDR_HOUSENUMBER_TAG);
     396    removeOSMTag(TagUtils.ADDR_STATE_TAG);
     397    removeOSMTag(TagUtils.ADDR_STREET_TAG);
    422398    }
    423399
     
    431407     */
    432408    public boolean hasTag(String tag) {
    433         if (StringUtils.isNullOrEmpty(tag))
    434             return false;
    435 
    436         return TagUtils.hasTag(osmObject, tag) || hasDerivedValue(tag);
    437     }
    438 
    439     /*
    440      * (non-Javadoc)
    441      *
    442      * @see
    443      * org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#compareTo(org
    444      * .openstreetmap.josm.plugins.addressEdit.INodeEntity)
    445      */
     409    if (StringUtils.isNullOrEmpty(tag))
     410        return false;
     411
     412    return TagUtils.hasTag(osmObject, tag) || hasDerivedValue(tag);
     413    }
     414
    446415    @Override
    447416    public int compareTo(IOSMEntity o) {
    448         if (o == null || !(o instanceof OSMAddress)) {
    449             return -1;
    450         }
    451         OSMAddress other = (OSMAddress) o;
    452 
    453         if (this.equals(other))
    454             return 0;
    455 
    456         int cc = 0;
    457         cc = this.getCountry().compareTo(other.getCountry());
    458         if (cc == 0) {
    459             cc = this.getState().compareTo(other.getState());
    460             if (cc == 0) {
    461                 cc = this.getCity().compareTo(other.getCity());
    462                 if (cc == 0) {
    463                     cc = this.getStreetName().compareTo(other.getStreetName());
    464                     if (cc == 0) {
    465                         if (hasGuessedStreetName()) {
    466                             if (other.hasStreetName()) {
    467                                 // Compare guessed name with the real name
    468                                 String gsm = this.getGuessedStreetName();
    469                                 cc = this.getGuessedStreetName().compareTo(
    470                                         other.getStreetName());
    471                                 if (cc == 0) {
    472                                     cc = this.getHouseNumber().compareTo(
    473                                             other.getHouseNumber());
    474                                 }
    475                             } else if (other.hasGuessedStreetName()) {
    476                                 // Compare guessed name with the guessed name
    477                                 cc = this.getGuessedStreetName().compareTo(
    478                                         other.getGuessedStreetName());
    479                                 if (cc == 0) {
    480                                     cc = this.getHouseNumber().compareTo(
    481                                             other.getHouseNumber());
    482                                 }
    483                             } // else: give up
    484                               // No guessed name at all -> just compare the
    485                               // number
    486                         } else {
    487                             cc = this.getHouseNumber().compareTo(
    488                                     other.getHouseNumber());
    489                         }
    490                     }
    491                 }
    492             }
    493         }
    494 
    495         return cc;
     417    if (o == null || !(o instanceof OSMAddress)) {
     418        return -1;
     419    }
     420    OSMAddress other = (OSMAddress) o;
     421
     422    if (this.equals(other))
     423        return 0;
     424
     425    int cc = 0;
     426    cc = this.getCountry().compareTo(other.getCountry());
     427    if (cc == 0) {
     428        cc = this.getState().compareTo(other.getState());
     429        if (cc == 0) {
     430        cc = this.getCity().compareTo(other.getCity());
     431        if (cc == 0) {
     432            cc = this.getStreetName().compareTo(other.getStreetName());
     433            if (cc == 0) {
     434            if (hasGuessedStreetName()) {
     435                if (other.hasStreetName()) {
     436                // Compare guessed name with the real name
     437                /*String gsm =*/ this.getGuessedStreetName();
     438                cc = this.getGuessedStreetName().compareTo(
     439                    other.getStreetName());
     440                if (cc == 0) {
     441                    cc = this.getHouseNumber().compareTo(
     442                        other.getHouseNumber());
     443                }
     444                } else if (other.hasGuessedStreetName()) {
     445                // Compare guessed name with the guessed name
     446                cc = this.getGuessedStreetName().compareTo(
     447                    other.getGuessedStreetName());
     448                if (cc == 0) {
     449                    cc = this.getHouseNumber().compareTo(
     450                        other.getHouseNumber());
     451                }
     452                } // else: give up
     453                  // No guessed name at all -> just compare the
     454                  // number
     455            } else {
     456                cc = this.getHouseNumber().compareTo(
     457                    other.getHouseNumber());
     458            }
     459            }
     460        }
     461        }
     462    }
     463
     464    return cc;
    496465    }
    497466
     
    502471     */
    503472    public void assignStreet(OSMStreet node) {
    504         if (node == null || !node.hasName())
    505             return;
    506 
    507         if (!node.getName().equals(getStreetName())) {
    508             setStreetName(node.getName());
    509             node.addAddress(this);
    510             fireEntityChanged(this);
    511         }
     473    if (node == null || !node.hasName())
     474        return;
     475
     476    if (!node.getName().equals(getStreetName())) {
     477        setStreetName(node.getName());
     478        node.addAddress(this);
     479        fireEntityChanged(this);
     480    }
    512481    }
    513482
     
    520489     */
    521490    public String getGuessedValue(String tag) {
    522         CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    523 
    524         if (!hasGuessedValue(tag)) {
    525             return null;
    526         }
    527         return guessedValues.get(tag);
     491    CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     492
     493    if (!hasGuessedValue(tag)) {
     494        return null;
     495    }
     496    return guessedValues.get(tag);
    528497    }
    529498
     
    536505     */
    537506    public OsmPrimitive getGuessedObject(String tag) {
    538         CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    539 
    540         if (guessedObjects.containsKey(tag)) {
    541             return guessedObjects.get(tag);
    542         }
    543         return null;
     507    CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     508
     509    if (guessedObjects.containsKey(tag)) {
     510        return guessedObjects.get(tag);
     511    }
     512    return null;
    544513    }
    545514
     
    551520     */
    552521    public Collection<OsmPrimitive> getGuessedObjects() {
    553         if (guessedObjects == null)
    554             return null;
    555 
    556         return guessedObjects.values();
     522    if (guessedObjects == null)
     523        return null;
     524
     525    return guessedObjects.values();
    557526    }
    558527
     
    564533     */
    565534    public boolean needsGuess() {
    566         return needsGuessedValue(TagUtils.ADDR_CITY_TAG)
    567                 || needsGuessedValue(TagUtils.ADDR_POSTCODE_TAG)
    568                 || needsGuessedValue(TagUtils.ADDR_COUNTRY_TAG) ||
    569                 // needsGuessedValue(TagUtils.ADDR_STATE_TAG) ||
    570                 needsGuessedValue(TagUtils.ADDR_STREET_TAG);
     535    return needsGuessedValue(TagUtils.ADDR_CITY_TAG)
     536        || needsGuessedValue(TagUtils.ADDR_POSTCODE_TAG)
     537        || needsGuessedValue(TagUtils.ADDR_COUNTRY_TAG) ||
     538        // needsGuessedValue(TagUtils.ADDR_STATE_TAG) ||
     539        needsGuessedValue(TagUtils.ADDR_STREET_TAG);
    571540    }
    572541
     
    577546     */
    578547    public boolean needsGuessedValue(String tag) {
    579         return MISSING_TAG.equals(getTagValueWithGuess(tag));
     548    return MISSING_TAG.equals(getTagValueWithGuess(tag));
    580549    }
    581550
     
    584553     */
    585554    public void clearAllGuesses() {
    586         guessedValues.clear();
     555    guessedValues.clear();
    587556    }
    588557
     
    596565     */
    597566    private boolean hasGuessedValue(String tag) {
    598         CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    599 
    600         return guessedValues.containsKey(tag)
    601                 && !StringUtils.isNullOrEmpty(guessedValues.get(tag));
     567    CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     568
     569    return guessedValues.containsKey(tag)
     570        && !StringUtils.isNullOrEmpty(guessedValues.get(tag));
    602571    }
    603572
     
    613582     */
    614583    public void setGuessedValue(String tag, String value, OsmPrimitive osm) {
    615         CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    616 
    617         if (value != null && osm != null) {
    618             guessedValues.put(tag, value);
    619             if (osm != null) {
    620                 guessedObjects.put(tag, osm);
    621             }
    622             fireEntityChanged(this);
    623         }
     584    CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     585
     586    if (value != null && osm != null) {
     587        guessedValues.put(tag, value);
     588        if (osm != null) {
     589        guessedObjects.put(tag, osm);
     590        }
     591        fireEntityChanged(this);
     592    }
    624593    }
    625594
     
    633602     */
    634603    private boolean hasDerivedValue(String tag) {
    635         CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    636 
    637         return derivedValues.containsKey(tag)
    638                 && !StringUtils.isNullOrEmpty(derivedValues.get(tag));
     604    CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     605
     606    return derivedValues.containsKey(tag)
     607        && !StringUtils.isNullOrEmpty(derivedValues.get(tag));
    639608    }
    640609
     
    645614     */
    646615    public boolean hasDerivedValues() {
    647         return derivedValues.size() > 0;
     616    return derivedValues.size() > 0;
    648617    }
    649618
     
    656625     */
    657626    public String getDerivedValue(String tag) {
    658         if (!hasDerivedValue(tag)) {
    659             return null;
    660         }
    661         return derivedValues.get(tag);
     627    if (!hasDerivedValue(tag)) {
     628        return null;
     629    }
     630    return derivedValues.get(tag);
    662631    }
    663632
     
    671640     */
    672641    public void setDerivedValue(String tag, String value) {
    673         derivedValues.put(tag, value);
     642    derivedValues.put(tag, value);
    674643    }
    675644
     
    680649     */
    681650    public void setStreetName(String streetName) {
    682         if (streetName != null && streetName.length() == 0)
    683             return;
    684 
    685         setOSMTag(TagUtils.ADDR_STREET_TAG, streetName);
     651    if (streetName != null && streetName.length() == 0)
     652        return;
     653
     654    setOSMTag(TagUtils.ADDR_STREET_TAG, streetName);
    686655    }
    687656
     
    692661     */
    693662    public void setState(String state) {
    694         if (state != null && state.length() == 0)
    695             return;
    696 
    697         setOSMTag(TagUtils.ADDR_STATE_TAG, state);
     663    if (state != null && state.length() == 0)
     664        return;
     665
     666    setOSMTag(TagUtils.ADDR_STATE_TAG, state);
    698667    }
    699668
     
    704673     */
    705674    public void setCountry(String country) {
    706         if (country != null && country.length() == 0)
    707             return;
    708 
    709         setOSMTag(TagUtils.ADDR_COUNTRY_TAG, country);
     675    if (country != null && country.length() == 0)
     676        return;
     677
     678    setOSMTag(TagUtils.ADDR_COUNTRY_TAG, country);
    710679    }
    711680
     
    716685     */
    717686    public void setPostCode(String postCode) {
    718         if (postCode != null && postCode.length() == 0)
    719             return;
    720 
    721         setOSMTag(TagUtils.ADDR_POSTCODE_TAG, postCode);
    722     }
    723 
    724     /*
    725      * (non-Javadoc)
    726      *
    727      * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#visit(org.
    728      * openstreetmap.josm.plugins.fixAddresses.IProblemVisitor)
    729      */
     687    if (postCode != null && postCode.length() == 0)
     688        return;
     689
     690    setOSMTag(TagUtils.ADDR_POSTCODE_TAG, postCode);
     691    }
     692
    730693    @Override
    731694    public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) {
    732         CheckParameterUtil.ensureParameterNotNull(visitor, "visitor");
    733 
    734         // Check for street
    735         if (!hasStreetName()) {
    736             AddressProblem p = new AddressProblem(this,
    737                     tr("Address has no street"));
    738             if (hasGuessedStreetName()) { // guess exists -> add solution entry
    739                 String tag = TagUtils.ADDR_STREET_TAG;
    740                 addGuessValueSolution(p, tag);
    741             }
    742             addRemoveAddressTagsSolution(p);
    743             visitor.addProblem(p);
    744             // Street name exists, but is invalid -> ask the all knowing trash
    745             // heap
    746         } else if (!trashHeap.isValidStreetName(getStreetName())) {
    747             AddressProblem p = new AddressProblem(this,
    748                     tr("Address has no valid street"));
    749             String match = trashHeap.getClosestStreetName(getStreetName());
    750 
    751             if (!StringUtils.isNullOrEmpty(match)) {
    752                 setGuessedStreetName(match, null);
    753                 addGuessValueSolution(p, TagUtils.ADDR_STREET_TAG);
    754             }
    755             visitor.addProblem(p);
    756         }
    757 
    758         // Check for postal code
    759         if (!hasPostalCode()) {
    760             AddressProblem p = new AddressProblem(this,
    761                     tr("Address has no post code"));
    762             if (hasGuessedStreetName()) {
    763                 String tag = TagUtils.ADDR_POSTCODE_TAG;
    764                 addGuessValueSolution(p, tag);
    765             }
    766             addRemoveAddressTagsSolution(p);
    767             visitor.addProblem(p);
    768         }
    769 
    770         // Check for city
    771         if (!hasCity()) {
    772             AddressProblem p = new AddressProblem(this,
    773                     tr("Address has no city"));
    774             if (hasGuessedStreetName()) {
    775                 String tag = TagUtils.ADDR_CITY_TAG;
    776                 addGuessValueSolution(p, tag);
    777             }
    778             addRemoveAddressTagsSolution(p);
    779             visitor.addProblem(p);
    780         }
    781 
    782         // Check for country
    783         if (!hasCountry()) {
    784             // TODO: Add guess for country
    785             AddressProblem p = new AddressProblem(this,
    786                     tr("Address has no country"));
    787             addRemoveAddressTagsSolution(p);
    788             visitor.addProblem(p);
    789         }
     695    CheckParameterUtil.ensureParameterNotNull(visitor, "visitor");
     696
     697    // Check for street
     698    if (!hasStreetName()) {
     699        AddressProblem p = new AddressProblem(this,
     700            tr("Address has no street"));
     701        if (hasGuessedStreetName()) { // guess exists -> add solution entry
     702        String tag = TagUtils.ADDR_STREET_TAG;
     703        addGuessValueSolution(p, tag);
     704        }
     705        addRemoveAddressTagsSolution(p);
     706        visitor.addProblem(p);
     707        // Street name exists, but is invalid -> ask the all knowing trash
     708        // heap
     709    } else if (!trashHeap.isValidStreetName(getStreetName())) {
     710        AddressProblem p = new AddressProblem(this,
     711            tr("Address has no valid street"));
     712        String match = trashHeap.getClosestStreetName(getStreetName());
     713
     714        if (!StringUtils.isNullOrEmpty(match)) {
     715        setGuessedStreetName(match, null);
     716        addGuessValueSolution(p, TagUtils.ADDR_STREET_TAG);
     717        }
     718        visitor.addProblem(p);
     719    }
     720
     721    // Check for postal code
     722    if (!hasPostalCode()) {
     723        AddressProblem p = new AddressProblem(this,
     724            tr("Address has no post code"));
     725        if (hasGuessedStreetName()) {
     726        String tag = TagUtils.ADDR_POSTCODE_TAG;
     727        addGuessValueSolution(p, tag);
     728        }
     729        addRemoveAddressTagsSolution(p);
     730        visitor.addProblem(p);
     731    }
     732
     733    // Check for city
     734    if (!hasCity()) {
     735        AddressProblem p = new AddressProblem(this,
     736            tr("Address has no city"));
     737        if (hasGuessedStreetName()) {
     738        String tag = TagUtils.ADDR_CITY_TAG;
     739        addGuessValueSolution(p, tag);
     740        }
     741        addRemoveAddressTagsSolution(p);
     742        visitor.addProblem(p);
     743    }
     744
     745    // Check for country
     746    if (!hasCountry()) {
     747        // TODO: Add guess for country
     748        AddressProblem p = new AddressProblem(this,
     749            tr("Address has no country"));
     750        addRemoveAddressTagsSolution(p);
     751        visitor.addProblem(p);
     752    }
    790753    }
    791754
     
    799762     */
    800763    private void addGuessValueSolution(AddressProblem p, String tag) {
    801         AddressSolution s = new AddressSolution(String.format("%s '%s'",
    802                 tr("Assign to"), getGuessedValue(tag)),
    803                 AddressActions.getApplyGuessesAction(), SolutionType.Change);
    804 
    805         p.addSolution(s);
     764    AddressSolution s = new AddressSolution(String.format("%s '%s'",
     765        tr("Assign to"), getGuessedValue(tag)),
     766        AddressActions.getApplyGuessesAction(), SolutionType.Change);
     767
     768    p.addSolution(s);
    806769    }
    807770
     
    813776     */
    814777    private void addRemoveAddressTagsSolution(IProblem problem) {
    815         CheckParameterUtil.ensureParameterNotNull(problem, "problem");
    816 
    817         AddressSolution s = new AddressSolution(tr("Remove all address tags"),
    818                 AddressActions.getRemoveTagsAction(), SolutionType.Remove);
    819         problem.addSolution(s);
    820     }
    821 
    822     /*
    823      * (non-Javadoc)
    824      *
    825      * @see org.openstreetmap.josm.plugins.fixAddresses.OSMEntityBase#toString()
    826      */
     778    CheckParameterUtil.ensureParameterNotNull(problem, "problem");
     779
     780    AddressSolution s = new AddressSolution(tr("Remove all address tags"),
     781        AddressActions.getRemoveTagsAction(), SolutionType.Remove);
     782    problem.addSolution(s);
     783    }
     784
    827785    @Override
    828786    public String toString() {
    829         return OSMAddress.getFormatString(this);
     787    return OSMAddress.getFormatString(this);
    830788    }
    831789
     
    838796     */
    839797    public static String getFormatString(OSMAddress node) {
    840         // TODO: Add further countries here
    841         // DE
    842         String guessed = node.getGuessedStreetName();
    843         String sName = node.getStreetName();
    844         if (!StringUtils.isNullOrEmpty(guessed) && MISSING_TAG.equals(sName)) {
    845             sName = String.format("(%s)", guessed);
    846         }
    847 
    848         return String.format("%s %s, %s-%s %s (%s) ", sName,
    849                 node.getHouseNumber(), node.getCountry(), node.getPostalCode(),
    850                 node.getCity(), node.getState());
     798    // TODO: Add further countries here
     799    // DE
     800    String guessed = node.getGuessedStreetName();
     801    String sName = node.getStreetName();
     802    if (!StringUtils.isNullOrEmpty(guessed) && MISSING_TAG.equals(sName)) {
     803        sName = String.format("(%s)", guessed);
     804    }
     805
     806    return String.format("%s %s, %s-%s %s (%s) ", sName,
     807        node.getHouseNumber(), node.getCountry(), node.getPostalCode(),
     808        node.getCity(), node.getState());
    851809    }
    852810}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMEntityBase.java

    r29971 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    3927 */
    4028public class OSMEntityBase implements IOSMEntity, Comparable<IOSMEntity> {
    41         public static final String ANONYMOUS = tr("No name");
    42         private static List<IAddressEditContainerListener> containerListeners = new ArrayList<IAddressEditContainerListener>();
    43         private List<ICommandListener> cmdListeners = new ArrayList<ICommandListener>();
    44 
    45         protected OsmPrimitive osmObject;
    46 
    47         /**
    48          * @param osmObject
    49          */
    50         public OSMEntityBase(OsmPrimitive osmObject) {
    51                 super();
    52                 this.osmObject = osmObject;
    53         }
    54 
    55         /**
    56          * @param osmObject the osmObject to set
    57          */
    58         protected void setOsmObject(OsmPrimitive osmObject) {
    59                 CheckParameterUtil.ensureParameterNotNull(osmObject, "osmObject");
    60                 this.osmObject = osmObject;
    61         }
    62 
    63         /**
    64          * Adds a change listener.
    65          * @param listener
    66          */
    67         public static void addChangedListener(IAddressEditContainerListener listener) {
    68                 CheckParameterUtil.ensureParameterNotNull(listener, "listener");
    69                 containerListeners.add(listener);
    70         }
    71 
    72         /**
    73          * Removes a change listener.
    74          * @param listener
    75          */
    76         public static void removeChangedListener(IAddressEditContainerListener listener) {
    77                 CheckParameterUtil.ensureParameterNotNull(listener, "listener");
    78                 containerListeners.remove(listener);
    79         }
    80 
    81         /**
    82          * Notifies clients that the address container changed.
    83          */
    84         protected static void fireEntityChanged(IOSMEntity entity) {
    85                 CheckParameterUtil.ensureParameterNotNull(entity, "entity");
    86                 for (IAddressEditContainerListener listener : containerListeners) {
    87                         listener.entityChanged(entity);
    88                 }
    89         }
    90 
    91         /**
    92          * Adds a command listener.
    93          * @param listener
    94          */
    95         public void addCommandListener(ICommandListener listener) {
    96                 CheckParameterUtil.ensureParameterNotNull(listener, "listener");
    97                 cmdListeners.add(listener);
    98         }
    99 
    100         /**
    101          * Removes a command listener.
    102          * @param listener
    103          */
    104         public void removeCommandListener(ICommandListener listener) {
    105                 CheckParameterUtil.ensureParameterNotNull(listener, "listener");
    106                 cmdListeners.remove(listener);
    107         }
    108 
    109         /**
    110          * Notifies clients that an entity has issued a command.
    111          *
    112          * @param source the entity that issued the command.
    113          * @param command the command to execute.
    114          */
    115         protected void fireCommandIssued(Command command) {
    116                 CheckParameterUtil.ensureParameterNotNull(command, "command");
    117                 if (cmdListeners.size() == 0) {
    118                         throw new RuntimeException("Object has no TX context: " + this);
    119                 }
    120 
    121                 for (ICommandListener l : cmdListeners) {
    122                         l.commandIssued(this, command);
    123                 }
    124         }
    125 
    126         public OsmPrimitive getOsmObject() {
    127                 return osmObject;
    128         }
    129 
    130         @Override
    131         public List<IOSMEntity> getChildren() {
    132                 return null;
    133         }
    134 
    135         @Override
    136         /**
    137          * Gets the name of the street or ANONYMOUS, if street has no name.
    138          * @return
    139          */
    140         public String getName() {
    141                 if (TagUtils.hasNameTag(osmObject)) {
    142                         return  TagUtils.getNameValue(osmObject);
    143                 }
    144                 return "";
    145         }
    146 
    147         /* (non-Javadoc)
    148          * @see org.openstreetmap.josm.plugins.addressEdit.INodeEntity#hasName()
    149          */
    150         @Override
    151         public boolean hasName() {
    152                 return TagUtils.hasNameTag(osmObject);
    153         }
    154 
    155         /**
    156          * Internal helper method which changes the given property and
    157          * puts the appropriate command {@link src.org.openstreetmap.josm.command.Command}
    158          * into the undo/redo queue.
    159          * @param tag The tag to change.
    160          * @param newValue The new value for the tag.
    161          * @param cmd The surrounding command sequence
    162          */
    163         protected void setOSMTag(String tag, String newValue) {
    164                 CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    165                
    166 
    167                 if (osmObject != null) {
    168                         String existingValue = osmObject.get(tag);
    169                         // Bugfix #9047: Keep existing values
    170                         if (!StringUtils.isNullOrEmpty(existingValue)) {
    171                             return;
    172                         }
    173                        
    174                         if ((osmObject.hasKey(tag) && newValue == null) || newValue != null) {
    175                                 fireCommandIssued(new ChangePropertyCommand(osmObject, tag, newValue));
    176                                 fireEntityChanged(this);
    177                         }
    178                 }
    179         }
    180 
    181         /**
    182          * Removes the given tag from the OSM object.
    183          *
    184          * @param tag the tag
    185          */
    186         protected void removeOSMTag(String tag) {
    187                 CheckParameterUtil.ensureParameterNotNull(tag, "tag");
    188                 setOSMTag(tag, null); // a value of null removes the tag
    189         }
    190 
    191         /* (non-Javadoc)
    192          * @see java.lang.Object#toString()
    193          */
    194         @Override
    195         public String toString() {
    196                 if (hasName()) {
    197                         return this.getClass().getName() + ": " + getName();
    198                 }
    199                 return this.getClass().getName() + ": " + ANONYMOUS;
    200         }
    201 
    202         /* (non-Javadoc)
    203          * @see java.lang.Comparable#compareTo(java.lang.Object)
    204          */
    205         @Override
    206         public int compareTo(IOSMEntity o) {
    207                 if (o == null || !(o instanceof OSMEntityBase)) return -1;
    208                 return this.getName().compareTo(o.getName());
    209         }
    210 
    211         /* (non-Javadoc)
    212          * @see org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity#visit(org.openstreetmap.josm.plugins.fixAddresses.IAllKnowingTrashHeap, org.openstreetmap.josm.plugins.fixAddresses.IProblemVisitor)
    213          */
    214         @Override
    215         public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) {
    216                 // do nothing
    217         }
    218 
    219         /* (non-Javadoc)
    220          * @see org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity#getCoor()
    221          */
    222         @Override
    223         public LatLon getCoor() {
    224                 OsmPrimitive osm = getOsmObject();
    225                 if (osm == null) return null;
    226 
    227                 if (osm instanceof Node) {
    228                         return ((Node)osm).getCoor();
    229                 // way: return center
    230                 } else if (osm instanceof Way) {
    231                         Way w = (Way) osm;
    232                         BBox bb = w.getBBox();
    233                         return bb.getBottomRight().getCenter(bb.getTopLeft());
    234                 }
    235                 // relations??
    236                 return null;
    237         }
     29    public static final String ANONYMOUS = tr("No name");
     30    private static List<IAddressEditContainerListener> containerListeners = new ArrayList<IAddressEditContainerListener>();
     31    private List<ICommandListener> cmdListeners = new ArrayList<ICommandListener>();
     32
     33    protected OsmPrimitive osmObject;
     34
     35    /**
     36     * @param osmObject
     37     */
     38    public OSMEntityBase(OsmPrimitive osmObject) {
     39        super();
     40        this.osmObject = osmObject;
     41    }
     42
     43    /**
     44     * @param osmObject the osmObject to set
     45     */
     46    protected void setOsmObject(OsmPrimitive osmObject) {
     47        CheckParameterUtil.ensureParameterNotNull(osmObject, "osmObject");
     48        this.osmObject = osmObject;
     49    }
     50
     51    /**
     52     * Adds a change listener.
     53     * @param listener
     54     */
     55    public static void addChangedListener(IAddressEditContainerListener listener) {
     56        CheckParameterUtil.ensureParameterNotNull(listener, "listener");
     57        containerListeners.add(listener);
     58    }
     59
     60    /**
     61     * Removes a change listener.
     62     * @param listener
     63     */
     64    public static void removeChangedListener(IAddressEditContainerListener listener) {
     65        CheckParameterUtil.ensureParameterNotNull(listener, "listener");
     66        containerListeners.remove(listener);
     67    }
     68
     69    /**
     70     * Notifies clients that the address container changed.
     71     */
     72    protected static void fireEntityChanged(IOSMEntity entity) {
     73        CheckParameterUtil.ensureParameterNotNull(entity, "entity");
     74        for (IAddressEditContainerListener listener : containerListeners) {
     75            listener.entityChanged(entity);
     76        }
     77    }
     78
     79    /**
     80     * Adds a command listener.
     81     * @param listener
     82     */
     83    public void addCommandListener(ICommandListener listener) {
     84        CheckParameterUtil.ensureParameterNotNull(listener, "listener");
     85        cmdListeners.add(listener);
     86    }
     87
     88    /**
     89     * Removes a command listener.
     90     * @param listener
     91     */
     92    public void removeCommandListener(ICommandListener listener) {
     93        CheckParameterUtil.ensureParameterNotNull(listener, "listener");
     94        cmdListeners.remove(listener);
     95    }
     96
     97    /**
     98     * Notifies clients that an entity has issued a command.
     99     *
     100     * @param source the entity that issued the command.
     101     * @param command the command to execute.
     102     */
     103    protected void fireCommandIssued(Command command) {
     104        CheckParameterUtil.ensureParameterNotNull(command, "command");
     105        if (cmdListeners.size() == 0) {
     106            throw new RuntimeException("Object has no TX context: " + this);
     107        }
     108
     109        for (ICommandListener l : cmdListeners) {
     110            l.commandIssued(this, command);
     111        }
     112    }
     113
     114    public OsmPrimitive getOsmObject() {
     115        return osmObject;
     116    }
     117
     118    @Override
     119    public List<IOSMEntity> getChildren() {
     120        return null;
     121    }
     122
     123    @Override
     124    /**
     125     * Gets the name of the street or ANONYMOUS, if street has no name.
     126     * @return
     127     */
     128    public String getName() {
     129        if (TagUtils.hasNameTag(osmObject)) {
     130            return  TagUtils.getNameValue(osmObject);
     131        }
     132        return "";
     133    }
     134
     135    @Override
     136    public boolean hasName() {
     137        return TagUtils.hasNameTag(osmObject);
     138    }
     139
     140    /**
     141     * Internal helper method which changes the given property and
     142     * puts the appropriate command {@link src.org.openstreetmap.josm.command.Command}
     143     * into the undo/redo queue.
     144     * @param tag The tag to change.
     145     * @param newValue The new value for the tag.
     146     * @param cmd The surrounding command sequence
     147     */
     148    protected void setOSMTag(String tag, String newValue) {
     149        CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     150       
     151
     152        if (osmObject != null) {
     153                String existingValue = osmObject.get(tag);
     154                // Bugfix #9047: Keep existing values
     155                if (!StringUtils.isNullOrEmpty(existingValue)) {
     156                    return;
     157                }
     158               
     159            if ((osmObject.hasKey(tag) && newValue == null) || newValue != null) {
     160                fireCommandIssued(new ChangePropertyCommand(osmObject, tag, newValue));
     161                fireEntityChanged(this);
     162            }
     163        }
     164    }
     165
     166    /**
     167     * Removes the given tag from the OSM object.
     168     *
     169     * @param tag the tag
     170     */
     171    protected void removeOSMTag(String tag) {
     172        CheckParameterUtil.ensureParameterNotNull(tag, "tag");
     173        setOSMTag(tag, null); // a value of null removes the tag
     174    }
     175
     176    @Override
     177    public String toString() {
     178        if (hasName()) {
     179            return this.getClass().getName() + ": " + getName();
     180        }
     181        return this.getClass().getName() + ": " + ANONYMOUS;
     182    }
     183
     184    @Override
     185    public int compareTo(IOSMEntity o) {
     186        if (o == null || !(o instanceof OSMEntityBase)) return -1;
     187        return this.getName().compareTo(o.getName());
     188    }
     189
     190    @Override
     191    public void visit(IAllKnowingTrashHeap trashHeap, IProblemVisitor visitor) {
     192        // do nothing
     193    }
     194
     195    @Override
     196    public LatLon getCoor() {
     197        OsmPrimitive osm = getOsmObject();
     198        if (osm == null) return null;
     199
     200        if (osm instanceof Node) {
     201            return ((Node)osm).getCoor();
     202        // way: return center
     203        } else if (osm instanceof Way) {
     204            Way w = (Way) osm;
     205            BBox bb = w.getBBox();
     206            return bb.getBottomRight().getCenter(bb.getTopLeft());
     207        }
     208        // relations??
     209        return null;
     210    }
    238211}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMStreet.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2816 */
    2917public class OSMStreet extends OSMEntityBase {
    30         private List<IOSMEntity> children;
    31         private List<OSMAddress> addresses;
     18    private List<IOSMEntity> children;
     19    private List<OSMAddress> addresses;
    3220
    33         /**
    34         * @param osmPrimitive
    35         */
    36         public OSMStreet(OsmPrimitive osmPrimitive) {
    37                 super(osmPrimitive);
    38         }
     21    /**
     22    * @param osmPrimitive
     23    */
     24    public OSMStreet(OsmPrimitive osmPrimitive) {
     25        super(osmPrimitive);
     26    }
    3927
    40         public List<IOSMEntity> getChildren() {
    41                 return children;
    42         }
     28    public List<IOSMEntity> getChildren() {
     29        return children;
     30    }
    4331
    44         /**
    45         * Adds a street segment to the street node.
    46         * @param segment
    47         */
    48         public void addStreetSegment(OSMStreetSegment segment) {
    49                 lazyCreateChildren();
     32    /**
     33    * Adds a street segment to the street node.
     34    * @param segment
     35    */
     36    public void addStreetSegment(OSMStreetSegment segment) {
     37        lazyCreateChildren();
    5038
    51                 children.add(segment);
    52                 Collections.sort(children);
    53         }
     39        children.add(segment);
     40        Collections.sort(children);
     41    }
    5442
    55         /**
    56         * Lazy creation of children list.
    57         */
    58         private void lazyCreateChildren() {
    59                 if (children == null) {
    60                         children = new ArrayList<IOSMEntity>();
    61                 }
    62         }
     43    /**
     44    * Lazy creation of children list.
     45    */
     46    private void lazyCreateChildren() {
     47        if (children == null) {
     48            children = new ArrayList<IOSMEntity>();
     49        }
     50    }
    6351
    64         /**
    65         * Adds an associated address to the street.
    66         *
    67         * @param aNode the address node to add
    68         */
    69         public void addAddress(OSMAddress aNode) {
    70                 lazyCreateAddresses();
    71                 addresses.add(aNode);
    72         }
     52    /**
     53    * Adds an associated address to the street.
     54    *
     55    * @param aNode the address node to add
     56    */
     57    public void addAddress(OSMAddress aNode) {
     58        lazyCreateAddresses();
     59        addresses.add(aNode);
     60    }
    7361
    74         /**
    75         * Lazy creation of address list.
    76         */
    77         private void lazyCreateAddresses() {
    78                 if (addresses == null) {
    79                         addresses = new ArrayList<OSMAddress>();
    80                 }
    81         }
     62    /**
     63    * Lazy creation of address list.
     64    */
     65    private void lazyCreateAddresses() {
     66        if (addresses == null) {
     67            addresses = new ArrayList<OSMAddress>();
     68        }
     69    }
    8270
    83         /**
    84         * Checks for addresses.
    85         *
    86         * @return true, if street has one or more associated addresses.
    87         */
    88         public boolean hasAddresses() {
    89                 return addresses != null && addresses.size() > 0;
    90         }
     71    /**
     72    * Checks for addresses.
     73    *
     74    * @return true, if street has one or more associated addresses.
     75    */
     76    public boolean hasAddresses() {
     77        return addresses != null && addresses.size() > 0;
     78    }
    9179
    92         public List<OSMAddress> getAddresses() {
    93                 return addresses;
    94         }
     80    public List<OSMAddress> getAddresses() {
     81        return addresses;
     82    }
    9583
    96         public void setAddresses(List<OSMAddress> addresses) {
    97                 this.addresses = addresses;
    98         }
     84    public void setAddresses(List<OSMAddress> addresses) {
     85        this.addresses = addresses;
     86    }
    9987
    100         /**
    101         * Gets the number of addresses associated with this street.
    102         * @return
    103         */
    104         public int getNumberOfAddresses() {
    105                 if (addresses == null) return 0;
     88    /**
     89    * Gets the number of addresses associated with this street.
     90    * @return
     91    */
     92    public int getNumberOfAddresses() {
     93        if (addresses == null) return 0;
    10694
    107                 return addresses.size();
    108         }
     95        return addresses.size();
     96    }
    10997
    110         /**
    111         * Gets the number of street segments of this street.
    112         * @return
    113         */
    114         public int getNumberOfSegments() {
    115                 if (children == null) return 0;
     98    /**
     99    * Gets the number of street segments of this street.
     100    * @return
     101    */
     102    public int getNumberOfSegments() {
     103        if (children == null) return 0;
    116104
    117                 int sc = 0;
    118                 for (IOSMEntity node : children) {
    119                         if (node instanceof OSMStreetSegment) {
    120                                 sc++;
    121                         }
    122                 }
    123                 return sc;
    124         }
     105        int sc = 0;
     106        for (IOSMEntity node : children) {
     107            if (node instanceof OSMStreetSegment) {
     108                sc++;
     109            }
     110        }
     111        return sc;
     112    }
    125113
    126         /**
    127         * Gets the road type(s) of this street. If the street has different types,
    128         * they are separated by comma.
    129         * @return
    130         */
    131         public String getType() {
    132                 List<String> types = new ArrayList<String>();
     114    /**
     115    * Gets the road type(s) of this street. If the street has different types,
     116    * they are separated by comma.
     117    * @return
     118    */
     119    public String getType() {
     120        List<String> types = new ArrayList<String>();
    133121
    134                 for (IOSMEntity seg : getChildren()) {
    135                         OsmPrimitive osmPrim = seg.getOsmObject();
    136                         if (TagUtils.hasHighwayTag(osmPrim)) {
    137                                 String val = osmPrim.get(TagUtils.HIGHWAY_TAG);
    138                                 if (!types.contains(val)) {
    139                                         types.add(val);
    140                                 }
    141                         }
    142                 }
     122        for (IOSMEntity seg : getChildren()) {
     123            OsmPrimitive osmPrim = seg.getOsmObject();
     124            if (TagUtils.hasHighwayTag(osmPrim)) {
     125                String val = osmPrim.get(TagUtils.HIGHWAY_TAG);
     126                if (!types.contains(val)) {
     127                    types.add(val);
     128                }
     129            }
     130        }
    143131
    144                 StringBuffer sb = new StringBuffer(20);
    145                 for (String string : types) {
    146                         if (sb.length() > 0) {
    147                                 sb.append(", ");
    148                         }
    149                         sb.append(string);
     132        StringBuffer sb = new StringBuffer(20);
     133        for (String string : types) {
     134            if (sb.length() > 0) {
     135                sb.append(", ");
     136            }
     137            sb.append(string);
    150138
    151                 }
    152                 return sb.toString();
    153         }
     139        }
     140        return sb.toString();
     141    }
    154142
    155         /**
    156         * Checks if the attached way has an associated street relation.
    157         *
    158         * @return true, if this street has an "associatedStreet" relation.
    159         */
    160         public boolean hasAssociatedStreetRelation() {
    161                 OsmPrimitive osm = getOsmObject();
    162                 for (OsmPrimitive refs : osm.getReferrers()) {
    163                         if (refs instanceof Relation) {
    164                                 Relation rel = (Relation) refs;
    165                                 if (TagUtils.isAssociatedStreetRelation(rel)) {
    166                                         return true;
    167                                 }
    168                         }
    169                 }
    170                 return false;
    171         }
     143    /**
     144    * Checks if the attached way has an associated street relation.
     145    *
     146    * @return true, if this street has an "associatedStreet" relation.
     147    */
     148    public boolean hasAssociatedStreetRelation() {
     149        OsmPrimitive osm = getOsmObject();
     150        for (OsmPrimitive refs : osm.getReferrers()) {
     151            if (refs instanceof Relation) {
     152                Relation rel = (Relation) refs;
     153                if (TagUtils.isAssociatedStreetRelation(rel)) {
     154                    return true;
     155                }
     156            }
     157        }
     158        return false;
     159    }
    172160
    173         /* (non-Javadoc)
    174          * @see org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#toString()
    175          */
    176         @Override
    177         public String toString() {
    178                 StringBuffer sb = new StringBuffer(getName());
     161    @Override
     162    public String toString() {
     163        StringBuffer sb = new StringBuffer(getName());
    179164
    180                 if (children != null) {
    181                         sb.append(String.format(", %d segments", children.size()));
    182                 }
     165        if (children != null) {
     166            sb.append(String.format(", %d segments", children.size()));
     167        }
    183168
    184                 if (addresses != null) {
    185                         sb.append(String.format(", %d address entries", addresses.size()));
    186                 }
     169        if (addresses != null) {
     170            sb.append(String.format(", %d address entries", addresses.size()));
     171        }
    187172
    188                 return sb.toString();
    189         }
    190 
     173        return sb.toString();
     174    }
    191175}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMStreetSegment.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2513 *
    2614 */
    27 
    2815public class OSMStreetSegment extends OSMEntityBase {
    2916
    30         public OSMStreetSegment(OsmPrimitive osmObject) {
    31                 super(osmObject);
    32         }
     17    public OSMStreetSegment(OsmPrimitive osmObject) {
     18        super(osmObject);
     19    }
    3320
    34         @Override
    35         public List<IOSMEntity> getChildren() {
    36                 return null;
    37         }
    38 
     21    @Override
     22    public List<IOSMEntity> getChildren() {
     23        return null;
     24    }
    3925}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmFactory.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    208
    219public class OsmFactory {
    22         private static HashMap<String, OSMAddress> addressCache = new HashMap<String, OSMAddress>();
     10    private static HashMap<String, OSMAddress> addressCache = new HashMap<String, OSMAddress>();
    2311
    24         /**
    25         * Creates an address node from an OSM node, if possible.
    26         * @param node
    27         * @return
    28         */
    29         public static OSMAddress createNode(Node node) {
    30                 if (TagUtils.isAddress(node)) {
    31                         String aid = "" + node.getId();
     12    /**
     13    * Creates an address node from an OSM node, if possible.
     14    * @param node
     15    * @return
     16    */
     17    public static OSMAddress createNode(Node node) {
     18        if (TagUtils.isAddress(node)) {
     19            String aid = "" + node.getId();
    3220
    33                         OSMAddress aNode = lookup(aid);
    34                         if (aNode == null) {
    35                                 aNode = new OSMAddress(node);
    36                                 addressCache.put(aid, aNode);
    37                         } else {
    38                                 aNode.setOsmObject(node);
    39                         }
    40                         return aNode;
    41                 }
     21            OSMAddress aNode = lookup(aid);
     22            if (aNode == null) {
     23                aNode = new OSMAddress(node);
     24                addressCache.put(aid, aNode);
     25            } else {
     26                aNode.setOsmObject(node);
     27            }
     28            return aNode;
     29        }
    4230
    43                 return null;
    44         }
     31        return null;
     32    }
    4533
    46         /**
    47         * Creates an node entity from an OSM way, if possible.
    48         * @param way
    49         * @return The new node instance or null; if given way is inappropriate.
    50         */
    51         public static IOSMEntity createNodeFromWay(Way way) {
    52                 if (TagUtils.hasHighwayTag(way)) {
    53                         return new OSMStreetSegment(way);
    54                 }
     34    /**
     35    * Creates an node entity from an OSM way, if possible.
     36    * @param way
     37    * @return The new node instance or null; if given way is inappropriate.
     38    */
     39    public static IOSMEntity createNodeFromWay(Way way) {
     40        if (TagUtils.hasHighwayTag(way)) {
     41            return new OSMStreetSegment(way);
     42        }
    5543
    56                 // Check for building with address
    57                 if (way.isClosed() && TagUtils.hasBuildingTag(way)  && TagUtils.isAddress(way)) {
    58                         String aid = "" + way.getId();
     44        // Check for building with address
     45        if (way.isClosed() && TagUtils.hasBuildingTag(way)  && TagUtils.isAddress(way)) {
     46            String aid = "" + way.getId();
    5947
    60                         OSMAddress aNode = lookup(aid);
    61                         if (aNode == null) {
    62                                 aNode = new OSMAddress(way);
    63                                 addressCache.put(aid, aNode);
    64                         } else {
    65                                 aNode.setOsmObject(way);
    66                         }
     48            OSMAddress aNode = lookup(aid);
     49            if (aNode == null) {
     50                aNode = new OSMAddress(way);
     51                addressCache.put(aid, aNode);
     52            } else {
     53                aNode.setOsmObject(way);
     54            }
    6755
    68                         return aNode;
    69                 }
    70                 return null;
    71         }
     56            return aNode;
     57        }
     58        return null;
     59    }
    7260
    73         private static OSMAddress lookup(String aid) {
    74                 if (addressCache.containsKey(aid)) {
    75                         return addressCache.get(aid);
    76                 }
    77                 return null;
    78         }
     61    private static OSMAddress lookup(String aid) {
     62        if (addressCache.containsKey(aid)) {
     63            return addressCache.get(aid);
     64        }
     65        return null;
     66    }
    7967}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmUtils.java

    r29967 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    3523public class OsmUtils {
    3624
    37         /**
    38         * Instantiates a new osm utils.
    39         */
    40         private OsmUtils() {}
    41 
    42         /** The cached locale. */
    43         private static String cachedLocale = null;
    44 
    45         /**
    46         * Gets the minimum distance of single coordinate to a way.
    47         *
    48         * @param coor the coordinate to get the minimum distance for.
    49         * @param w the w the way to compare against
    50         * @return the minimum distance between the given coordinate and the way
    51         */
    52         public static double getMinimumDistanceToWay(LatLon coor, Way w) {
    53                 if (coor == null || w == null) return Double.POSITIVE_INFINITY;
    54 
    55                 double minDist = Double.MAX_VALUE;
    56                 List<Pair<Node,Node>> x = w.getNodePairs(true);
    57 
    58                 for (Pair<Node, Node> pair : x) {
    59                         LatLon ap = pair.a.getCoor();
    60                         LatLon bp = pair.b.getCoor();
    61 
    62                         double dist = findMinimum(ap, bp, coor);
    63                         if (dist < minDist) {
    64                                 minDist = dist;
    65                         }
    66                 }
    67                 return minDist;
    68         }
    69 
    70         /**
    71         * Find the minimum distance between a point and two way coordinates recursively.
    72         *
    73         * @param a the a the first way point coordinate
    74         * @param b the b the second way point coordinate
    75         * @param c the c the node coordinate
    76         * @return the double the minimum distance in m of the way and the node
    77         */
    78         private static double findMinimum(LatLon a, LatLon b, LatLon c) {
    79                 CheckParameterUtil.ensureParameterNotNull(c, "c");
    80                 CheckParameterUtil.ensureParameterNotNull(b, "b");
    81                 CheckParameterUtil.ensureParameterNotNull(a, "a");
    82 
    83                 LatLon mid = new LatLon((a.lat() + b.lat()) / 2, (a.lon() + b.lon()) / 2);
    84 
    85                 double ac = a.greatCircleDistance(c);
    86                 double bc = b.greatCircleDistance(c);
    87                 double mc = mid.greatCircleDistance(c);
    88 
    89                 double min = Math.min(Math.min(ac, mc), bc);
    90 
    91 
    92                 if (min < 5.0) { // close enough?
    93                         return min;
    94                 }
    95 
    96                 if (mc < ac && mc < bc) {
    97                         // mid point has lower distance than a and b
    98                         if (ac > bc) { // recurse
    99                                 return findMinimum(b, mid, c);
    100                         } else {
    101                                 return findMinimum(a, mid, c);
    102                         }
    103                 } else { // mid point is not closer than a or b
    104                         return Math.min(ac, bc);
    105                 }
    106         }
    107 
    108         /**
    109         * Checks, if the given address has a relation hosting the address values. This method looks
    110         * for a relation of type 'associatedStreet' and checks the members for address values, if present.
    111         * If the member has address values, this methods sets the derived properties of the address
    112         * node accordingly.
    113         *
    114         * @param address The address to check.
    115         * @return true, if an associated relation has been found.
    116         */
    117         public static boolean getValuesFromRelation(OSMAddress address) {
    118                 if (address == null) {
    119                         return false;
    120                 }
    121 
    122                 boolean hasValuesFromRel = false; /* true, if we applied some address props from the relation */
    123                 OsmPrimitive addrNode = address.getOsmObject();
    124 
    125                 // check all referrers of the node
    126                 for (OsmPrimitive osm : addrNode.getReferrers()) {
    127                         if (osm instanceof Relation) {
    128                                 Relation r = (Relation) osm;
    129                                 // Relation has the right type?
    130                                 if (!TagUtils.isAssociatedStreetRelation(r)) continue;
    131 
    132                                 // check for 'street' members
    133                                 for (RelationMember rm : r.getMembers()) {
    134                                         if (TagUtils.isStreetMember(rm)) {
    135                                                 OsmPrimitive street = rm.getMember();
    136                                                 if (TagUtils.hasHighwayTag(street)) {
    137                                                         String streetName = TagUtils.getNameValue(street);
    138                                                         if (!StringUtils.isNullOrEmpty(streetName)) {
    139                                                                 // street name found -> set property
    140                                                                 address.setDerivedValue(TagUtils.ADDR_STREET_TAG, streetName);
    141                                                                 hasValuesFromRel = true;
    142                                                                 break;
    143                                                         } // else: Street has no name: Ooops
    144                                                 } // else: Street member, but no highway tag: Ooops
    145                                         }
    146                                 }
    147 
    148                                 // Check for other address properties
    149                                 if (TagUtils.hasAddrCityTag(r)) { // city
    150                                         address.setDerivedValue(TagUtils.ADDR_CITY_TAG, TagUtils.getAddrCityValue(r));
    151                                         hasValuesFromRel = true;
    152                                 }
    153                                 if (TagUtils.hasAddrCountryTag(r)) { // country
    154                                         address.setDerivedValue(TagUtils.ADDR_COUNTRY_TAG, TagUtils.getAddrCountryValue(r));
    155                                         hasValuesFromRel = true;
    156                                 }
    157                                 if (TagUtils.hasAddrPostcodeTag(r)) { // postcode
    158                                         address.setDerivedValue(TagUtils.ADDR_POSTCODE_TAG, TagUtils.getAddrPostcodeValue(r));
    159                                         hasValuesFromRel = true;
    160                                 }
    161                         }
    162                 }
    163                 return hasValuesFromRel;
    164         }
    165 
    166         /**
    167         * Gets the tag values from an address interpolation ref, if present.
    168         *
    169         * @param address The address
    170         * @return true, if house numbers are given via address interpolation; otherwise false.
    171         */
    172         public static boolean getValuesFromAddressInterpolation(OSMAddress address) {
    173                 if (address == null) return false;
    174 
    175                 OsmPrimitive osmAddr = address.getOsmObject();
    176 
    177                 for (OsmPrimitive osm : osmAddr.getReferrers()) {
    178                         if (osm instanceof Way) {
    179                                 Way w = (Way) osm;
    180                                 if (TagUtils.hasAddrInterpolationTag(w)) {
    181                                         applyDerivedValue(address, w, TagUtils.ADDR_POSTCODE_TAG);
    182                                         applyDerivedValue(address, w, TagUtils.ADDR_CITY_TAG);
    183                                         applyDerivedValue(address, w, TagUtils.ADDR_COUNTRY_TAG);
    184                                         applyDerivedValue(address, w, TagUtils.ADDR_STREET_TAG);
    185                                         applyDerivedValue(address, w, TagUtils.ADDR_STATE_TAG);
    186                                         return true;
    187                                 }
    188                         }
    189                 }
    190 
    191                 return false;
    192         }
    193 
    194         /**
    195         * Gets the local code as string.
    196         *
    197         * @return the string representation of the local.
    198         */
    199         public static String getLocale() {
    200                 // Check if user could prefer imperial system
    201                 if (cachedLocale == null) {
    202                         Locale l = Locale.getDefault();
    203                         cachedLocale = l.toString();
    204                 }
    205                 return cachedLocale;
    206         }
    207 
    208         /**
    209         * Zooms to the given addresses.
    210         *
    211         * @param addressList the address list
    212         */
    213         public static void zoomAddresses(List<OSMAddress> addressList) {
    214                 CheckParameterUtil.ensureParameterNotNull(addressList, "addressList");
    215 
    216                 if (Main.map == null && Main.map.mapView == null) return;   // nothing to do
    217                 if (addressList.size() == 0) return;                        // dto.
    218 
    219                 // compute bounding box
    220                 BoundingXYVisitor bbox = new BoundingXYVisitor();
    221                 for (OSMAddress source : addressList) {
    222                         OsmPrimitive osm = source.getOsmObject();
    223                         Bounds b = new Bounds(osm.getBBox().getTopLeft(), osm.getBBox().getBottomRight());
    224                         bbox.visit(b);
    225                 }
    226 
    227                 if (bbox.getBounds() != null) {
    228                         //  zoom to calculated bounding box
    229                         Main.map.mapView.zoomTo(bbox.getBounds());
    230                 }
    231         }
    232 
    233         /**
    234         * Helper method to set a derived value of an address node.
    235         *
    236         * @param address The address to change
    237         * @param w the way containing the tag for the derived value.
    238         * @param tag the tag to set as applied value.
    239         */
    240         private static void applyDerivedValue(OSMAddress address, Way w, String tag) {
    241                 CheckParameterUtil.ensureParameterNotNull(address, "address");
    242                 CheckParameterUtil.ensureParameterNotNull(w, "way");
    243 
    244                 if (!address.hasTag(tag) && TagUtils.hasTag(w, tag)) {
    245                         address.setDerivedValue(tag, w.get(tag));
    246                 }
    247         }
     25    /**
     26    * Instantiates a new osm utils.
     27    */
     28    private OsmUtils() {}
     29
     30    /** The cached locale. */
     31    private static String cachedLocale = null;
     32
     33    /**
     34    * Gets the minimum distance of single coordinate to a way.
     35    *
     36    * @param coor the coordinate to get the minimum distance for.
     37    * @param w the w the way to compare against
     38    * @return the minimum distance between the given coordinate and the way
     39    */
     40    public static double getMinimumDistanceToWay(LatLon coor, Way w) {
     41        if (coor == null || w == null) return Double.POSITIVE_INFINITY;
     42
     43        double minDist = Double.MAX_VALUE;
     44        List<Pair<Node,Node>> x = w.getNodePairs(true);
     45
     46        for (Pair<Node, Node> pair : x) {
     47            LatLon ap = pair.a.getCoor();
     48            LatLon bp = pair.b.getCoor();
     49
     50            double dist = findMinimum(ap, bp, coor);
     51            if (dist < minDist) {
     52                minDist = dist;
     53            }
     54        }
     55        return minDist;
     56    }
     57
     58    /**
     59    * Find the minimum distance between a point and two way coordinates recursively.
     60    *
     61    * @param a the a the first way point coordinate
     62    * @param b the b the second way point coordinate
     63    * @param c the c the node coordinate
     64    * @return the double the minimum distance in m of the way and the node
     65    */
     66    private static double findMinimum(LatLon a, LatLon b, LatLon c) {
     67        CheckParameterUtil.ensureParameterNotNull(c, "c");
     68        CheckParameterUtil.ensureParameterNotNull(b, "b");
     69        CheckParameterUtil.ensureParameterNotNull(a, "a");
     70
     71        LatLon mid = new LatLon((a.lat() + b.lat()) / 2, (a.lon() + b.lon()) / 2);
     72
     73        double ac = a.greatCircleDistance(c);
     74        double bc = b.greatCircleDistance(c);
     75        double mc = mid.greatCircleDistance(c);
     76
     77        double min = Math.min(Math.min(ac, mc), bc);
     78
     79
     80        if (min < 5.0) { // close enough?
     81            return min;
     82        }
     83
     84        if (mc < ac && mc < bc) {
     85            // mid point has lower distance than a and b
     86            if (ac > bc) { // recurse
     87                return findMinimum(b, mid, c);
     88            } else {
     89                return findMinimum(a, mid, c);
     90            }
     91        } else { // mid point is not closer than a or b
     92            return Math.min(ac, bc);
     93        }
     94    }
     95
     96    /**
     97    * Checks, if the given address has a relation hosting the address values. This method looks
     98    * for a relation of type 'associatedStreet' and checks the members for address values, if present.
     99    * If the member has address values, this methods sets the derived properties of the address
     100    * node accordingly.
     101    *
     102    * @param address The address to check.
     103    * @return true, if an associated relation has been found.
     104    */
     105    public static boolean getValuesFromRelation(OSMAddress address) {
     106        if (address == null) {
     107            return false;
     108        }
     109
     110        boolean hasValuesFromRel = false; /* true, if we applied some address props from the relation */
     111        OsmPrimitive addrNode = address.getOsmObject();
     112
     113        // check all referrers of the node
     114        for (OsmPrimitive osm : addrNode.getReferrers()) {
     115            if (osm instanceof Relation) {
     116                Relation r = (Relation) osm;
     117                // Relation has the right type?
     118                if (!TagUtils.isAssociatedStreetRelation(r)) continue;
     119
     120                // check for 'street' members
     121                for (RelationMember rm : r.getMembers()) {
     122                    if (TagUtils.isStreetMember(rm)) {
     123                        OsmPrimitive street = rm.getMember();
     124                        if (TagUtils.hasHighwayTag(street)) {
     125                            String streetName = TagUtils.getNameValue(street);
     126                            if (!StringUtils.isNullOrEmpty(streetName)) {
     127                                // street name found -> set property
     128                                address.setDerivedValue(TagUtils.ADDR_STREET_TAG, streetName);
     129                                hasValuesFromRel = true;
     130                                break;
     131                            } // else: Street has no name: Ooops
     132                        } // else: Street member, but no highway tag: Ooops
     133                    }
     134                }
     135
     136                // Check for other address properties
     137                if (TagUtils.hasAddrCityTag(r)) { // city
     138                    address.setDerivedValue(TagUtils.ADDR_CITY_TAG, TagUtils.getAddrCityValue(r));
     139                    hasValuesFromRel = true;
     140                }
     141                if (TagUtils.hasAddrCountryTag(r)) { // country
     142                    address.setDerivedValue(TagUtils.ADDR_COUNTRY_TAG, TagUtils.getAddrCountryValue(r));
     143                    hasValuesFromRel = true;
     144                }
     145                if (TagUtils.hasAddrPostcodeTag(r)) { // postcode
     146                    address.setDerivedValue(TagUtils.ADDR_POSTCODE_TAG, TagUtils.getAddrPostcodeValue(r));
     147                    hasValuesFromRel = true;
     148                }
     149            }
     150        }
     151        return hasValuesFromRel;
     152    }
     153
     154    /**
     155    * Gets the tag values from an address interpolation ref, if present.
     156    *
     157    * @param address The address
     158    * @return true, if house numbers are given via address interpolation; otherwise false.
     159    */
     160    public static boolean getValuesFromAddressInterpolation(OSMAddress address) {
     161        if (address == null) return false;
     162
     163        OsmPrimitive osmAddr = address.getOsmObject();
     164
     165        for (OsmPrimitive osm : osmAddr.getReferrers()) {
     166            if (osm instanceof Way) {
     167                Way w = (Way) osm;
     168                if (TagUtils.hasAddrInterpolationTag(w)) {
     169                    applyDerivedValue(address, w, TagUtils.ADDR_POSTCODE_TAG);
     170                    applyDerivedValue(address, w, TagUtils.ADDR_CITY_TAG);
     171                    applyDerivedValue(address, w, TagUtils.ADDR_COUNTRY_TAG);
     172                    applyDerivedValue(address, w, TagUtils.ADDR_STREET_TAG);
     173                    applyDerivedValue(address, w, TagUtils.ADDR_STATE_TAG);
     174                    return true;
     175                }
     176            }
     177        }
     178
     179        return false;
     180    }
     181
     182    /**
     183    * Gets the local code as string.
     184    *
     185    * @return the string representation of the local.
     186    */
     187    public static String getLocale() {
     188        // Check if user could prefer imperial system
     189        if (cachedLocale == null) {
     190            Locale l = Locale.getDefault();
     191            cachedLocale = l.toString();
     192        }
     193        return cachedLocale;
     194    }
     195
     196    /**
     197    * Zooms to the given addresses.
     198    *
     199    * @param addressList the address list
     200    */
     201    public static void zoomAddresses(List<OSMAddress> addressList) {
     202        CheckParameterUtil.ensureParameterNotNull(addressList, "addressList");
     203
     204        if (Main.map == null && Main.map.mapView == null) return;   // nothing to do
     205        if (addressList.size() == 0) return;                        // dto.
     206
     207        // compute bounding box
     208        BoundingXYVisitor bbox = new BoundingXYVisitor();
     209        for (OSMAddress source : addressList) {
     210            OsmPrimitive osm = source.getOsmObject();
     211            Bounds b = new Bounds(osm.getBBox().getTopLeft(), osm.getBBox().getBottomRight());
     212            bbox.visit(b);
     213        }
     214
     215        if (bbox.getBounds() != null) {
     216            //  zoom to calculated bounding box
     217            Main.map.mapView.zoomTo(bbox.getBounds());
     218        }
     219    }
     220
     221    /**
     222    * Helper method to set a derived value of an address node.
     223    *
     224    * @param address The address to change
     225    * @param w the way containing the tag for the derived value.
     226    * @param tag the tag to set as applied value.
     227    */
     228    private static void applyDerivedValue(OSMAddress address, Way w, String tag) {
     229        CheckParameterUtil.ensureParameterNotNull(address, "address");
     230        CheckParameterUtil.ensureParameterNotNull(w, "way");
     231
     232        if (!address.hasTag(tag) && TagUtils.hasTag(w, tag)) {
     233            address.setDerivedValue(tag, w.get(tag));
     234        }
     235    }
    248236}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/PostalCodeChecker.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2311 */
    2412public class PostalCodeChecker {
    25         private static HashMap<String, String> postalCodePatternMap = new HashMap<String, String>();
    26 
    27         static {
    28                 fillMap();
    29         }
    30 
    31         /**
    32         * Checks if given address has a valid postal code.
    33         *
    34         * @param address the address to check the postal code for
    35         * @return true, if postal code is valid (this implies
    36         * also that a country is NOT supported); otherwise false.
    37         */
    38         public static boolean hasValidPostalCode(OSMAddress address) {
    39                 CheckParameterUtil.ensureParameterNotNull(address, "address");
    40 
    41                 if (!address.hasPostalCode()) {
    42                         return false; // no postal code available
    43                 }
    44 
    45                 String ctry = getCountry(address);
    46                 String postalCode = address.getPostalCode();
    47 
    48                 return hasValidPostalCode(ctry, postalCode);
    49         }
    50 
    51         /**
    52         * Checks if postal code is valid for the country reported by the Java VM.
    53         *
    54         * @param postalCode the postal code
    55         * @return true, if successful
    56         */
    57         public static boolean hasValidPostalCode(String postalCode) {
    58                 return hasValidPostalCode(getCountry(), postalCode);
    59         }
    60 
    61         /**
    62         * Checks if given postal code if valid for the specified country.
    63         *
    64         * @param country the country
    65         * @param postalCode the postal code
    66         * @return true, if successful
    67         */
    68         public static boolean hasValidPostalCode(String country, String postalCode) {
    69                 // Get country-specific pattern for postal code
    70                 if (postalCodePatternMap.containsKey(country)) {
    71                         String pattern = postalCodePatternMap.get(country);
    72                         // Check if postal code matches pattern
    73                         return postalCode.matches(pattern);
    74                 } else {
    75                         // we cannot validate; assume postal code as valid until we know better
    76                         return true;
    77                 }
    78         }
    79 
    80         /**
    81         * Checks if validation for the given country is supported.
    82         *
    83         * @param country 2-letter ISO-Code (e. g. "GB", "US", "IT") of the country to check.
    84         * @return true, if is validation supported; otherwise false
    85         */
    86         public static boolean isValidationSupported(String country) {
    87                 CheckParameterUtil.ensureParameterNotNull(country, "country");
    88                 return postalCodePatternMap.containsKey(country.toUpperCase());
    89         }
    90 
    91         /**
    92         * Checks if validation for the given address is supported.
    93         *
    94         * @param address the address to check postal code validation support for.
    95         * @return true, if is validation supported; otherwise false
    96         */
    97         public static boolean isValidationSupported(OSMAddress address) {
    98                 CheckParameterUtil.ensureParameterNotNull(address, "address");
    99 
    100                 String ctry = getCountry(address);
    101                 return postalCodePatternMap.containsKey(ctry);
    102         }
    103 
    104         /**
    105         * Gets the current country.
    106         *
    107         * @return the country of the Java VM.
    108         */
    109         public static String getCountry() {
    110                 return getCountry(null);
    111         }
    112 
    113         /**
    114         * Gets the country of the given address.
    115         *
    116         * @param address the address to get the country for
    117         * @return the country of the address. If the given address has no postal code,
    118         * the default country of the Java VM is returned instead.
    119         */
    120         private static String getCountry(OSMAddress address) {
    121                 String ctry = Locale.getDefault().getCountry();
    122                 if (address != null && address.hasCountry()) {
    123                         // If address has a country, use this one (e. g. a dutch edits UK data)
    124                         ctry = address.getCountry().toUpperCase();
    125                 }
    126                 return ctry;
    127         }
    128 
    129         /**
    130         * Fills the country-postal code pattern map.
    131         */
    132         private static void fillMap() {
    133                 /*
    134                 String[] countries = Locale.getISOCountries();
    135 
    136                 for (int i = 0; i < countries.length; i++) {
    137                         System.out.println("//postalCodePatternMap.put(\"" + countries[i] + "\", \"[0-9]{5}\");");
    138                 }
    139 
    140                 String x = "A9999AAA";
    141 
    142                 if (x.matches("[A-Z]{1}[0-9]{4}[A-Z]{3}")) {
    143                         System.out.println("YES");
    144                 }
    145 
    146                 String xx = "99999-999";
    147                 // "[0-9]{5}\-[0-9]{3}"); //
    148                 if (xx.matches("[0-9]{5}-[0-9]{3}")) {
    149                         System.out.println("YES");
    150                 }
    151 
    152 
    153                 String[] xxx = new String[]{"A9 9AA", "A99 9AA", "A9A 9AA", "AA9 9AA", "AA99 9AA", "AA9A 9AA"};
    154                 for (int i = 0; i < xxx.length; i++) {
    155                         if (!xxx[i].matches("[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}")) {
    156                                 System.err.println(xxx[i]);
    157                         }
    158                 }*/
    159                 // see http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html for country codes
    160                 //
    161 
    162                 //postalCodePatternMap.put("AD", "[0-9]{5}");
    163                 //postalCodePatternMap.put("AE", "[0-9]{5}");
    164                 //postalCodePatternMap.put("AF", "[0-9]{5}");
    165                 //postalCodePatternMap.put("AG", "[0-9]{5}");
    166                 //postalCodePatternMap.put("AI", "[0-9]{5}");
    167                 postalCodePatternMap.put("AL", "[0-9]{5}");
    168                 postalCodePatternMap.put("AM", "[0-9]{4}");
    169                 //postalCodePatternMap.put("AN", "[0-9]{5}");
    170                 //postalCodePatternMap.put("AO", "[0-9]{5}");
    171                 //postalCodePatternMap.put("AQ", "[0-9]{5}");
    172                 postalCodePatternMap.put("AR", "[A-Z]{1}[0-9]{4}[A-Z]{3}"); // Argentina
    173                 //postalCodePatternMap.put("AS", "[0-9]{5}");
    174                 postalCodePatternMap.put("AT", "[0-9]{4}"); // Austria
    175                 postalCodePatternMap.put("AU", "[0-9]{4}"); // Australia
    176                 //postalCodePatternMap.put("AW", "[0-9]{5}");
    177                 //postalCodePatternMap.put("AX", "[0-9]{5}");
    178                 //postalCodePatternMap.put("AZ", "[0-9]{5}");
    179                 //postalCodePatternMap.put("BA", "[0-9]{5}");
    180                 //postalCodePatternMap.put("BB", "[0-9]{5}");
    181                 //postalCodePatternMap.put("BD", "[0-9]{5}");
    182                 //postalCodePatternMap.put("BE", "[0-9]{5}");
    183                 //postalCodePatternMap.put("BF", "[0-9]{5}");
    184                 //postalCodePatternMap.put("BG", "[0-9]{5}");
    185                 //postalCodePatternMap.put("BH", "[0-9]{5}");
    186                 //postalCodePatternMap.put("BI", "[0-9]{5}");
    187                 //postalCodePatternMap.put("BJ", "[0-9]{5}");
    188                 //postalCodePatternMap.put("BL", "[0-9]{5}");
    189                 //postalCodePatternMap.put("BM", "[0-9]{5}");
    190                 //postalCodePatternMap.put("BN", "[0-9]{5}");
    191                 //postalCodePatternMap.put("BO", "[0-9]{5}");
    192                 postalCodePatternMap.put("BR", "[0-9]{5}-[0-9]{3}"); // 99999-999
    193                 //postalCodePatternMap.put("BS", "[0-9]{5}");
    194                 //postalCodePatternMap.put("BT", "[0-9]{5}");
    195                 //postalCodePatternMap.put("BV", "[0-9]{5}");
    196                 //postalCodePatternMap.put("BW", "[0-9]{5}");
    197                 //postalCodePatternMap.put("BY", "[0-9]{5}");
    198                 //postalCodePatternMap.put("BZ", "[0-9]{5}");
    199                 postalCodePatternMap.put("CA", "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"); // Canada A9A 9A9
    200                 //postalCodePatternMap.put("CC", "[0-9]{5}");
    201                 //postalCodePatternMap.put("CD", "[0-9]{5}");
    202                 //postalCodePatternMap.put("CF", "[0-9]{5}");
    203                 //postalCodePatternMap.put("CG", "[0-9]{5}");
    204                 postalCodePatternMap.put("CH", "[0-9]{4}"); // Switzerland
    205                 //postalCodePatternMap.put("CI", "[0-9]{5}");
    206                 //postalCodePatternMap.put("CK", "[0-9]{5}");
    207                 //postalCodePatternMap.put("CL", "[0-9]{5}");
    208                 //postalCodePatternMap.put("CM", "[0-9]{5}");
    209                 postalCodePatternMap.put("CN", "[0-9]{6}"); // China
    210                 //postalCodePatternMap.put("CO", "[0-9]{5}");
    211                 //postalCodePatternMap.put("CR", "[0-9]{5}");
    212                 //postalCodePatternMap.put("CS", "[0-9]{5}");
    213                 //postalCodePatternMap.put("CU", "[0-9]{5}");
    214                 //postalCodePatternMap.put("CV", "[0-9]{5}");
    215                 //postalCodePatternMap.put("CX", "[0-9]{5}");
    216                 //postalCodePatternMap.put("CY", "[0-9]{5}");
    217                 postalCodePatternMap.put("CZ", "[0-9]{3} [0-9]{2}"); // Czech: 999-99
    218                 postalCodePatternMap.put("DE", "[0-9]{5}"); // Germany
    219                 //postalCodePatternMap.put("DJ", "[0-9]{5}");
    220                 postalCodePatternMap.put("DK", "[0-9]{4}"); // Denmark
    221                 //postalCodePatternMap.put("DM", "[0-9]{5}");
    222                 //postalCodePatternMap.put("DO", "[0-9]{5}");
    223                 //postalCodePatternMap.put("DZ", "[0-9]{5}");
    224                 //postalCodePatternMap.put("EC", "[0-9]{5}");
    225                 postalCodePatternMap.put("EE", "[0-9]{5}"); // Estonia
    226                 //postalCodePatternMap.put("EG", "[0-9]{5}");
    227                 //postalCodePatternMap.put("EH", "[0-9]{5}");
    228                 //postalCodePatternMap.put("ER", "[0-9]{5}");
    229                 postalCodePatternMap.put("ES", "[0-9]{5}");
    230                 //postalCodePatternMap.put("ET", "[0-9]{5}");
    231                 postalCodePatternMap.put("FI", "[0-9]{5}");
    232                 //postalCodePatternMap.put("FJ", "[0-9]{5}");
    233                 //postalCodePatternMap.put("FK", "[0-9]{5}");
    234                 //postalCodePatternMap.put("FM", "[0-9]{5}");
    235                 //postalCodePatternMap.put("FO", "[0-9]{5}");
    236                 postalCodePatternMap.put("FR", "[0-9]{5}"); // France
    237                 //postalCodePatternMap.put("GA", "[0-9]{5}");
    238                 postalCodePatternMap.put("GB", "[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}"); // UK
    239                 //postalCodePatternMap.put("GD", "[0-9]{5}");
    240                 //postalCodePatternMap.put("GE", "[0-9]{5}");
    241                 //postalCodePatternMap.put("GF", "[0-9]{5}");
    242                 //postalCodePatternMap.put("GG", "[0-9]{5}");
    243                 //postalCodePatternMap.put("GH", "[0-9]{5}");
    244                 //postalCodePatternMap.put("GI", "[0-9]{5}");
    245                 //postalCodePatternMap.put("GL", "[0-9]{5}");
    246                 //postalCodePatternMap.put("GM", "[0-9]{5}");
    247                 //postalCodePatternMap.put("GN", "[0-9]{5}");
    248                 //postalCodePatternMap.put("GP", "[0-9]{5}");
    249                 //postalCodePatternMap.put("GQ", "[0-9]{5}");
    250                 postalCodePatternMap.put("GR", "[0-9]{5}"); // Greece
    251                 //postalCodePatternMap.put("GS", "[0-9]{5}");
    252                 //postalCodePatternMap.put("GT", "[0-9]{5}");
    253                 //postalCodePatternMap.put("GU", "[0-9]{5}");
    254                 //postalCodePatternMap.put("GW", "[0-9]{5}");
    255                 //postalCodePatternMap.put("GY", "[0-9]{5}");
    256                 //postalCodePatternMap.put("HK", "[0-9]{5}");
    257                 //postalCodePatternMap.put("HM", "[0-9]{5}");
    258                 //postalCodePatternMap.put("HN", "[0-9]{5}");
    259                 postalCodePatternMap.put("HR", "[0-9]{5}"); // Croatia (Hrvatska)
    260                 //postalCodePatternMap.put("HT", "[0-9]{5}");
    261                 postalCodePatternMap.put("HU", "[0-9]{4}"); // Hungary
    262                 //postalCodePatternMap.put("ID", "[0-9]{5}");
    263                 //postalCodePatternMap.put("IE", "[0-9]{5}");
    264                 postalCodePatternMap.put("IL", "[0-9]{5}");
    265                 //postalCodePatternMap.put("IM", "[0-9]{5}");
    266                 //postalCodePatternMap.put("IN", "[0-9]{5}");
    267                 //postalCodePatternMap.put("IO", "[0-9]{5}");
    268                 //postalCodePatternMap.put("IQ", "[0-9]{5}");
    269                 //postalCodePatternMap.put("IR", "[0-9]{5}");
    270                 postalCodePatternMap.put("IS", "[0-9]{3}"); // Iceland
    271                 postalCodePatternMap.put("IT", "[0-9]{5}"); // Italy
    272                 //postalCodePatternMap.put("JE", "[0-9]{5}");
    273                 //postalCodePatternMap.put("JM", "[0-9]{5}");
    274                 //postalCodePatternMap.put("JO", "[0-9]{5}");
    275                 postalCodePatternMap.put("JP", "[0-9]{3}-[0-9]{4}"); // Japan: 999-9999
    276                 //postalCodePatternMap.put("KE", "[0-9]{5}");
    277                 //postalCodePatternMap.put("KG", "[0-9]{5}");
    278                 //postalCodePatternMap.put("KH", "[0-9]{5}");
    279                 //postalCodePatternMap.put("KI", "[0-9]{5}");
    280                 //postalCodePatternMap.put("KM", "[0-9]{5}");
    281                 //postalCodePatternMap.put("KN", "[0-9]{5}");
    282                 //postalCodePatternMap.put("KP", "[0-9]{5}");
    283                 //postalCodePatternMap.put("KR", "[0-9]{5}");
    284                 //postalCodePatternMap.put("KW", "[0-9]{5}");
    285                 //postalCodePatternMap.put("KY", "[0-9]{5}");
    286                 //postalCodePatternMap.put("KZ", "[0-9]{5}");
    287                 postalCodePatternMap.put("LA", "[0-9]{5}");
    288                 //postalCodePatternMap.put("LB", "[0-9]{5}");
    289                 //postalCodePatternMap.put("LC", "[0-9]{5}");
    290                 postalCodePatternMap.put("LI", "[0-9]{4}");
    291                 //postalCodePatternMap.put("LK", "[0-9]{5}");
    292                 //postalCodePatternMap.put("LR", "[0-9]{5}");
    293                 //postalCodePatternMap.put("LS", "[0-9]{5}");
    294                 postalCodePatternMap.put("LT", "[0-9]{5}");
    295                 postalCodePatternMap.put("LU", "[0-9]{4}");
    296                 postalCodePatternMap.put("LV", "[0-9]{4}"); // Latvia
    297                 //postalCodePatternMap.put("LY", "[0-9]{5}");
    298                 //postalCodePatternMap.put("MA", "[0-9]{5}");
    299                 //postalCodePatternMap.put("MC", "[0-9]{5}");
    300                 //postalCodePatternMap.put("MD", "[0-9]{5}");
    301                 postalCodePatternMap.put("ME", "[0-9]{5}"); // Montenegro
    302                 //postalCodePatternMap.put("MF", "[0-9]{5}");
    303                 //postalCodePatternMap.put("MG", "[0-9]{5}");
    304                 //postalCodePatternMap.put("MH", "[0-9]{5}");
    305                 //postalCodePatternMap.put("MK", "[0-9]{5}");
    306                 //postalCodePatternMap.put("ML", "[0-9]{5}");
    307                 //postalCodePatternMap.put("MM", "[0-9]{5}");
    308                 //postalCodePatternMap.put("MN", "[0-9]{5}");
    309                 //postalCodePatternMap.put("MO", "[0-9]{5}");
    310                 //postalCodePatternMap.put("MP", "[0-9]{5}");
    311                 //postalCodePatternMap.put("MQ", "[0-9]{5}");
    312                 //postalCodePatternMap.put("MR", "[0-9]{5}");
    313                 //postalCodePatternMap.put("MS", "[0-9]{5}");
    314                 //postalCodePatternMap.put("MT", "[0-9]{5}");
    315                 //postalCodePatternMap.put("MU", "[0-9]{5}");
    316                 //postalCodePatternMap.put("MV", "[0-9]{5}");
    317                 //postalCodePatternMap.put("MW", "[0-9]{5}");
    318                 postalCodePatternMap.put("MX", "[0-9]{5}"); // Mexico
    319                 //postalCodePatternMap.put("MY", "[0-9]{5}");
    320                 //postalCodePatternMap.put("MZ", "[0-9]{5}");
    321                 //postalCodePatternMap.put("NA", "[0-9]{5}");
    322                 //postalCodePatternMap.put("NC", "[0-9]{5}");
    323                 //postalCodePatternMap.put("NE", "[0-9]{5}");
    324                 //postalCodePatternMap.put("NF", "[0-9]{5}");
    325                 //postalCodePatternMap.put("NG", "[0-9]{5}");
    326                 //postalCodePatternMap.put("NI", "[0-9]{5}");
    327                 postalCodePatternMap.put("NL", "[0-9]{4} [A-Z]{2}"); // Dutch
    328                 postalCodePatternMap.put("NO", "[0-9]{4}"); // Norway
    329                 //postalCodePatternMap.put("NP", "[0-9]{5}");
    330                 //postalCodePatternMap.put("NR", "[0-9]{5}");
    331                 //postalCodePatternMap.put("NU", "[0-9]{5}");
    332                 //postalCodePatternMap.put("NZ", "[0-9]{5}");
    333                 //postalCodePatternMap.put("OM", "[0-9]{5}");
    334                 //postalCodePatternMap.put("PA", "[0-9]{5}");
    335                 //postalCodePatternMap.put("PE", "[0-9]{5}");
    336                 //postalCodePatternMap.put("PF", "[0-9]{5}");
    337                 //postalCodePatternMap.put("PG", "[0-9]{5}");
    338                 //postalCodePatternMap.put("PH", "[0-9]{5}");
    339                 //postalCodePatternMap.put("PK", "[0-9]{5}");
    340                 postalCodePatternMap.put("PL", "[0-9]{2}-[0-9]{3}"); // Poland
    341                 //postalCodePatternMap.put("PM", "[0-9]{5}");
    342                 //postalCodePatternMap.put("PN", "[0-9]{5}");
    343                 //postalCodePatternMap.put("PR", "[0-9]{5}");
    344                 //postalCodePatternMap.put("PS", "[0-9]{5}");
    345                 postalCodePatternMap.put("PT", "[0-9]{4}-[0-9]{3}"); // Portugal
    346                 //postalCodePatternMap.put("PW", "[0-9]{5}");
    347                 //postalCodePatternMap.put("PY", "[0-9]{5}");
    348                 //postalCodePatternMap.put("QA", "[0-9]{5}");
    349                 //postalCodePatternMap.put("RE", "[0-9]{5}");
    350                 postalCodePatternMap.put("RO", "[0-9]{6}"); // Romania
    351                 //postalCodePatternMap.put("RS", "[0-9]{5}");
    352                 postalCodePatternMap.put("RU", "[0-9]{6}"); // Russia
    353                 //postalCodePatternMap.put("RW", "[0-9]{5}");
    354                 //postalCodePatternMap.put("SA", "[0-9]{5}");
    355                 //postalCodePatternMap.put("SB", "[0-9]{5}");
    356                 //postalCodePatternMap.put("SC", "[0-9]{5}");
    357                 //postalCodePatternMap.put("SD", "[0-9]{5}");
    358                 postalCodePatternMap.put("SE", "[0-9]{3} [0-9]{2}"); // Sweden: 999-99
    359                 //postalCodePatternMap.put("SG", "[0-9]{5}");
    360                 //postalCodePatternMap.put("SH", "[0-9]{5}");
    361                 postalCodePatternMap.put("SI", "[0-9]{4}");
    362                 //postalCodePatternMap.put("SJ", "[0-9]{5}");
    363                 postalCodePatternMap.put("SK", "[0-9]{3} [0-9]{2}"); // Slovakia: 999-99
    364                 postalCodePatternMap.put("SL", "[0-9]{4}"); // Slowenia
    365                 postalCodePatternMap.put("SM", "[0-9]{5}"); // san marino -> Italy
    366                 //postalCodePatternMap.put("SN", "[0-9]{5}");
    367                 //postalCodePatternMap.put("SO", "[0-9]{5}");
    368                 //postalCodePatternMap.put("SR", "[0-9]{5}");
    369                 //postalCodePatternMap.put("ST", "[0-9]{5}");
    370                 //postalCodePatternMap.put("SV", "[0-9]{5}");
    371                 //postalCodePatternMap.put("SY", "[0-9]{5}");
    372                 //postalCodePatternMap.put("SZ", "[0-9]{5}");
    373                 //postalCodePatternMap.put("TC", "[0-9]{5}");
    374                 //postalCodePatternMap.put("TD", "[0-9]{5}");
    375                 //postalCodePatternMap.put("TF", "[0-9]{5}");
    376                 //postalCodePatternMap.put("TG", "[0-9]{5}");
    377                 //postalCodePatternMap.put("TH", "[0-9]{5}");
    378                 //postalCodePatternMap.put("TJ", "[0-9]{5}");
    379                 //postalCodePatternMap.put("TK", "[0-9]{5}");
    380                 //postalCodePatternMap.put("TL", "[0-9]{5}");
    381                 //postalCodePatternMap.put("TM", "[0-9]{5}");
    382                 //postalCodePatternMap.put("TN", "[0-9]{5}");
    383                 //postalCodePatternMap.put("TO", "[0-9]{5}");
    384                 postalCodePatternMap.put("TR", "[0-9]{5}"); // turkye
    385                 //postalCodePatternMap.put("TT", "[0-9]{5}");
    386                 //postalCodePatternMap.put("TV", "[0-9]{5}");
    387                 //postalCodePatternMap.put("TW", "[0-9]{5}");
    388                 //postalCodePatternMap.put("TZ", "[0-9]{5}");
    389                 postalCodePatternMap.put("UA", "[0-9]{5}"); // Ukraine
    390                 //postalCodePatternMap.put("UG", "[0-9]{5}");
    391                 //postalCodePatternMap.put("UM", "[0-9]{5}");
    392                 postalCodePatternMap.put("US", "([A-Z]{2} )?[0-9]{5}"); // USA: support "99999" and "IL 99999"
    393                 //postalCodePatternMap.put("UY", "[0-9]{5}");
    394                 //postalCodePatternMap.put("UZ", "[0-9]{5}");
    395                 //postalCodePatternMap.put("VA", "[0-9]{5}");
    396                 //postalCodePatternMap.put("VC", "[0-9]{5}");
    397                 //postalCodePatternMap.put("VE", "[0-9]{5}");
    398                 //postalCodePatternMap.put("VG", "[0-9]{5}");
    399                 //postalCodePatternMap.put("VI", "[0-9]{5}");
    400                 //postalCodePatternMap.put("VN", "[0-9]{5}");
    401                 //postalCodePatternMap.put("VU", "[0-9]{5}");
    402                 //postalCodePatternMap.put("WF", "[0-9]{5}");
    403                 //postalCodePatternMap.put("WS", "[0-9]{5}");
    404                 //postalCodePatternMap.put("YE", "[0-9]{5}");
    405                 //postalCodePatternMap.put("YT", "[0-9]{5}");
    406                 //postalCodePatternMap.put("ZA", "[0-9]{5}");
    407                 //postalCodePatternMap.put("ZM", "[0-9]{5}");
    408                 //postalCodePatternMap.put("ZW", "[0-9]{5}");
    409         }
     13    private static HashMap<String, String> postalCodePatternMap = new HashMap<String, String>();
     14
     15    static {
     16        fillMap();
     17    }
     18
     19    /**
     20    * Checks if given address has a valid postal code.
     21    *
     22    * @param address the address to check the postal code for
     23    * @return true, if postal code is valid (this implies
     24    * also that a country is NOT supported); otherwise false.
     25    */
     26    public static boolean hasValidPostalCode(OSMAddress address) {
     27        CheckParameterUtil.ensureParameterNotNull(address, "address");
     28
     29        if (!address.hasPostalCode()) {
     30            return false; // no postal code available
     31        }
     32
     33        String ctry = getCountry(address);
     34        String postalCode = address.getPostalCode();
     35
     36        return hasValidPostalCode(ctry, postalCode);
     37    }
     38
     39    /**
     40    * Checks if postal code is valid for the country reported by the Java VM.
     41    *
     42    * @param postalCode the postal code
     43    * @return true, if successful
     44    */
     45    public static boolean hasValidPostalCode(String postalCode) {
     46        return hasValidPostalCode(getCountry(), postalCode);
     47    }
     48
     49    /**
     50    * Checks if given postal code if valid for the specified country.
     51    *
     52    * @param country the country
     53    * @param postalCode the postal code
     54    * @return true, if successful
     55    */
     56    public static boolean hasValidPostalCode(String country, String postalCode) {
     57        // Get country-specific pattern for postal code
     58        if (postalCodePatternMap.containsKey(country)) {
     59            String pattern = postalCodePatternMap.get(country);
     60            // Check if postal code matches pattern
     61            return postalCode.matches(pattern);
     62        } else {
     63            // we cannot validate; assume postal code as valid until we know better
     64            return true;
     65        }
     66    }
     67
     68    /**
     69    * Checks if validation for the given country is supported.
     70    *
     71    * @param country 2-letter ISO-Code (e. g. "GB", "US", "IT") of the country to check.
     72    * @return true, if is validation supported; otherwise false
     73    */
     74    public static boolean isValidationSupported(String country) {
     75        CheckParameterUtil.ensureParameterNotNull(country, "country");
     76        return postalCodePatternMap.containsKey(country.toUpperCase());
     77    }
     78
     79    /**
     80    * Checks if validation for the given address is supported.
     81    *
     82    * @param address the address to check postal code validation support for.
     83    * @return true, if is validation supported; otherwise false
     84    */
     85    public static boolean isValidationSupported(OSMAddress address) {
     86        CheckParameterUtil.ensureParameterNotNull(address, "address");
     87
     88        String ctry = getCountry(address);
     89        return postalCodePatternMap.containsKey(ctry);
     90    }
     91
     92    /**
     93    * Gets the current country.
     94    *
     95    * @return the country of the Java VM.
     96    */
     97    public static String getCountry() {
     98        return getCountry(null);
     99    }
     100
     101    /**
     102    * Gets the country of the given address.
     103    *
     104    * @param address the address to get the country for
     105    * @return the country of the address. If the given address has no postal code,
     106    * the default country of the Java VM is returned instead.
     107    */
     108    private static String getCountry(OSMAddress address) {
     109        String ctry = Locale.getDefault().getCountry();
     110        if (address != null && address.hasCountry()) {
     111            // If address has a country, use this one (e. g. a dutch edits UK data)
     112            ctry = address.getCountry().toUpperCase();
     113        }
     114        return ctry;
     115    }
     116
     117    /**
     118    * Fills the country-postal code pattern map.
     119    */
     120    private static void fillMap() {
     121        /*
     122        String[] countries = Locale.getISOCountries();
     123
     124        for (int i = 0; i < countries.length; i++) {
     125            System.out.println("//postalCodePatternMap.put(\"" + countries[i] + "\", \"[0-9]{5}\");");
     126        }
     127
     128        String x = "A9999AAA";
     129
     130        if (x.matches("[A-Z]{1}[0-9]{4}[A-Z]{3}")) {
     131            System.out.println("YES");
     132        }
     133
     134        String xx = "99999-999";
     135        // "[0-9]{5}\-[0-9]{3}"); //
     136        if (xx.matches("[0-9]{5}-[0-9]{3}")) {
     137            System.out.println("YES");
     138        }
     139
     140
     141        String[] xxx = new String[]{"A9 9AA", "A99 9AA", "A9A 9AA", "AA9 9AA", "AA99 9AA", "AA9A 9AA"};
     142        for (int i = 0; i < xxx.length; i++) {
     143            if (!xxx[i].matches("[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}")) {
     144                System.err.println(xxx[i]);
     145            }
     146        }*/
     147        // see http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html for country codes
     148        //
     149
     150        //postalCodePatternMap.put("AD", "[0-9]{5}");
     151        //postalCodePatternMap.put("AE", "[0-9]{5}");
     152        //postalCodePatternMap.put("AF", "[0-9]{5}");
     153        //postalCodePatternMap.put("AG", "[0-9]{5}");
     154        //postalCodePatternMap.put("AI", "[0-9]{5}");
     155        postalCodePatternMap.put("AL", "[0-9]{5}");
     156        postalCodePatternMap.put("AM", "[0-9]{4}");
     157        //postalCodePatternMap.put("AN", "[0-9]{5}");
     158        //postalCodePatternMap.put("AO", "[0-9]{5}");
     159        //postalCodePatternMap.put("AQ", "[0-9]{5}");
     160        postalCodePatternMap.put("AR", "[A-Z]{1}[0-9]{4}[A-Z]{3}"); // Argentina
     161        //postalCodePatternMap.put("AS", "[0-9]{5}");
     162        postalCodePatternMap.put("AT", "[0-9]{4}"); // Austria
     163        postalCodePatternMap.put("AU", "[0-9]{4}"); // Australia
     164        //postalCodePatternMap.put("AW", "[0-9]{5}");
     165        //postalCodePatternMap.put("AX", "[0-9]{5}");
     166        //postalCodePatternMap.put("AZ", "[0-9]{5}");
     167        //postalCodePatternMap.put("BA", "[0-9]{5}");
     168        //postalCodePatternMap.put("BB", "[0-9]{5}");
     169        //postalCodePatternMap.put("BD", "[0-9]{5}");
     170        //postalCodePatternMap.put("BE", "[0-9]{5}");
     171        //postalCodePatternMap.put("BF", "[0-9]{5}");
     172        //postalCodePatternMap.put("BG", "[0-9]{5}");
     173        //postalCodePatternMap.put("BH", "[0-9]{5}");
     174        //postalCodePatternMap.put("BI", "[0-9]{5}");
     175        //postalCodePatternMap.put("BJ", "[0-9]{5}");
     176        //postalCodePatternMap.put("BL", "[0-9]{5}");
     177        //postalCodePatternMap.put("BM", "[0-9]{5}");
     178        //postalCodePatternMap.put("BN", "[0-9]{5}");
     179        //postalCodePatternMap.put("BO", "[0-9]{5}");
     180        postalCodePatternMap.put("BR", "[0-9]{5}-[0-9]{3}"); // 99999-999
     181        //postalCodePatternMap.put("BS", "[0-9]{5}");
     182        //postalCodePatternMap.put("BT", "[0-9]{5}");
     183        //postalCodePatternMap.put("BV", "[0-9]{5}");
     184        //postalCodePatternMap.put("BW", "[0-9]{5}");
     185        //postalCodePatternMap.put("BY", "[0-9]{5}");
     186        //postalCodePatternMap.put("BZ", "[0-9]{5}");
     187        postalCodePatternMap.put("CA", "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"); // Canada A9A 9A9
     188        //postalCodePatternMap.put("CC", "[0-9]{5}");
     189        //postalCodePatternMap.put("CD", "[0-9]{5}");
     190        //postalCodePatternMap.put("CF", "[0-9]{5}");
     191        //postalCodePatternMap.put("CG", "[0-9]{5}");
     192        postalCodePatternMap.put("CH", "[0-9]{4}"); // Switzerland
     193        //postalCodePatternMap.put("CI", "[0-9]{5}");
     194        //postalCodePatternMap.put("CK", "[0-9]{5}");
     195        //postalCodePatternMap.put("CL", "[0-9]{5}");
     196        //postalCodePatternMap.put("CM", "[0-9]{5}");
     197        postalCodePatternMap.put("CN", "[0-9]{6}"); // China
     198        //postalCodePatternMap.put("CO", "[0-9]{5}");
     199        //postalCodePatternMap.put("CR", "[0-9]{5}");
     200        //postalCodePatternMap.put("CS", "[0-9]{5}");
     201        //postalCodePatternMap.put("CU", "[0-9]{5}");
     202        //postalCodePatternMap.put("CV", "[0-9]{5}");
     203        //postalCodePatternMap.put("CX", "[0-9]{5}");
     204        //postalCodePatternMap.put("CY", "[0-9]{5}");
     205        postalCodePatternMap.put("CZ", "[0-9]{3} [0-9]{2}"); // Czech: 999-99
     206        postalCodePatternMap.put("DE", "[0-9]{5}"); // Germany
     207        //postalCodePatternMap.put("DJ", "[0-9]{5}");
     208        postalCodePatternMap.put("DK", "[0-9]{4}"); // Denmark
     209        //postalCodePatternMap.put("DM", "[0-9]{5}");
     210        //postalCodePatternMap.put("DO", "[0-9]{5}");
     211        //postalCodePatternMap.put("DZ", "[0-9]{5}");
     212        //postalCodePatternMap.put("EC", "[0-9]{5}");
     213        postalCodePatternMap.put("EE", "[0-9]{5}"); // Estonia
     214        //postalCodePatternMap.put("EG", "[0-9]{5}");
     215        //postalCodePatternMap.put("EH", "[0-9]{5}");
     216        //postalCodePatternMap.put("ER", "[0-9]{5}");
     217        postalCodePatternMap.put("ES", "[0-9]{5}");
     218        //postalCodePatternMap.put("ET", "[0-9]{5}");
     219        postalCodePatternMap.put("FI", "[0-9]{5}");
     220        //postalCodePatternMap.put("FJ", "[0-9]{5}");
     221        //postalCodePatternMap.put("FK", "[0-9]{5}");
     222        //postalCodePatternMap.put("FM", "[0-9]{5}");
     223        //postalCodePatternMap.put("FO", "[0-9]{5}");
     224        postalCodePatternMap.put("FR", "[0-9]{5}"); // France
     225        //postalCodePatternMap.put("GA", "[0-9]{5}");
     226        postalCodePatternMap.put("GB", "[A-Z]{1,2}[0-9]{1,2}[A-Z]? [0-9]{1}[A-Z]{2}"); // UK
     227        //postalCodePatternMap.put("GD", "[0-9]{5}");
     228        //postalCodePatternMap.put("GE", "[0-9]{5}");
     229        //postalCodePatternMap.put("GF", "[0-9]{5}");
     230        //postalCodePatternMap.put("GG", "[0-9]{5}");
     231        //postalCodePatternMap.put("GH", "[0-9]{5}");
     232        //postalCodePatternMap.put("GI", "[0-9]{5}");
     233        //postalCodePatternMap.put("GL", "[0-9]{5}");
     234        //postalCodePatternMap.put("GM", "[0-9]{5}");
     235        //postalCodePatternMap.put("GN", "[0-9]{5}");
     236        //postalCodePatternMap.put("GP", "[0-9]{5}");
     237        //postalCodePatternMap.put("GQ", "[0-9]{5}");
     238        postalCodePatternMap.put("GR", "[0-9]{5}"); // Greece
     239        //postalCodePatternMap.put("GS", "[0-9]{5}");
     240        //postalCodePatternMap.put("GT", "[0-9]{5}");
     241        //postalCodePatternMap.put("GU", "[0-9]{5}");
     242        //postalCodePatternMap.put("GW", "[0-9]{5}");
     243        //postalCodePatternMap.put("GY", "[0-9]{5}");
     244        //postalCodePatternMap.put("HK", "[0-9]{5}");
     245        //postalCodePatternMap.put("HM", "[0-9]{5}");
     246        //postalCodePatternMap.put("HN", "[0-9]{5}");
     247        postalCodePatternMap.put("HR", "[0-9]{5}"); // Croatia (Hrvatska)
     248        //postalCodePatternMap.put("HT", "[0-9]{5}");
     249        postalCodePatternMap.put("HU", "[0-9]{4}"); // Hungary
     250        //postalCodePatternMap.put("ID", "[0-9]{5}");
     251        //postalCodePatternMap.put("IE", "[0-9]{5}");
     252        postalCodePatternMap.put("IL", "[0-9]{5}");
     253        //postalCodePatternMap.put("IM", "[0-9]{5}");
     254        //postalCodePatternMap.put("IN", "[0-9]{5}");
     255        //postalCodePatternMap.put("IO", "[0-9]{5}");
     256        //postalCodePatternMap.put("IQ", "[0-9]{5}");
     257        //postalCodePatternMap.put("IR", "[0-9]{5}");
     258        postalCodePatternMap.put("IS", "[0-9]{3}"); // Iceland
     259        postalCodePatternMap.put("IT", "[0-9]{5}"); // Italy
     260        //postalCodePatternMap.put("JE", "[0-9]{5}");
     261        //postalCodePatternMap.put("JM", "[0-9]{5}");
     262        //postalCodePatternMap.put("JO", "[0-9]{5}");
     263        postalCodePatternMap.put("JP", "[0-9]{3}-[0-9]{4}"); // Japan: 999-9999
     264        //postalCodePatternMap.put("KE", "[0-9]{5}");
     265        //postalCodePatternMap.put("KG", "[0-9]{5}");
     266        //postalCodePatternMap.put("KH", "[0-9]{5}");
     267        //postalCodePatternMap.put("KI", "[0-9]{5}");
     268        //postalCodePatternMap.put("KM", "[0-9]{5}");
     269        //postalCodePatternMap.put("KN", "[0-9]{5}");
     270        //postalCodePatternMap.put("KP", "[0-9]{5}");
     271        //postalCodePatternMap.put("KR", "[0-9]{5}");
     272        //postalCodePatternMap.put("KW", "[0-9]{5}");
     273        //postalCodePatternMap.put("KY", "[0-9]{5}");
     274        //postalCodePatternMap.put("KZ", "[0-9]{5}");
     275        postalCodePatternMap.put("LA", "[0-9]{5}");
     276        //postalCodePatternMap.put("LB", "[0-9]{5}");
     277        //postalCodePatternMap.put("LC", "[0-9]{5}");
     278        postalCodePatternMap.put("LI", "[0-9]{4}");
     279        //postalCodePatternMap.put("LK", "[0-9]{5}");
     280        //postalCodePatternMap.put("LR", "[0-9]{5}");
     281        //postalCodePatternMap.put("LS", "[0-9]{5}");
     282        postalCodePatternMap.put("LT", "[0-9]{5}");
     283        postalCodePatternMap.put("LU", "[0-9]{4}");
     284        postalCodePatternMap.put("LV", "[0-9]{4}"); // Latvia
     285        //postalCodePatternMap.put("LY", "[0-9]{5}");
     286        //postalCodePatternMap.put("MA", "[0-9]{5}");
     287        //postalCodePatternMap.put("MC", "[0-9]{5}");
     288        //postalCodePatternMap.put("MD", "[0-9]{5}");
     289        postalCodePatternMap.put("ME", "[0-9]{5}"); // Montenegro
     290        //postalCodePatternMap.put("MF", "[0-9]{5}");
     291        //postalCodePatternMap.put("MG", "[0-9]{5}");
     292        //postalCodePatternMap.put("MH", "[0-9]{5}");
     293        //postalCodePatternMap.put("MK", "[0-9]{5}");
     294        //postalCodePatternMap.put("ML", "[0-9]{5}");
     295        //postalCodePatternMap.put("MM", "[0-9]{5}");
     296        //postalCodePatternMap.put("MN", "[0-9]{5}");
     297        //postalCodePatternMap.put("MO", "[0-9]{5}");
     298        //postalCodePatternMap.put("MP", "[0-9]{5}");
     299        //postalCodePatternMap.put("MQ", "[0-9]{5}");
     300        //postalCodePatternMap.put("MR", "[0-9]{5}");
     301        //postalCodePatternMap.put("MS", "[0-9]{5}");
     302        //postalCodePatternMap.put("MT", "[0-9]{5}");
     303        //postalCodePatternMap.put("MU", "[0-9]{5}");
     304        //postalCodePatternMap.put("MV", "[0-9]{5}");
     305        //postalCodePatternMap.put("MW", "[0-9]{5}");
     306        postalCodePatternMap.put("MX", "[0-9]{5}"); // Mexico
     307        //postalCodePatternMap.put("MY", "[0-9]{5}");
     308        //postalCodePatternMap.put("MZ", "[0-9]{5}");
     309        //postalCodePatternMap.put("NA", "[0-9]{5}");
     310        //postalCodePatternMap.put("NC", "[0-9]{5}");
     311        //postalCodePatternMap.put("NE", "[0-9]{5}");
     312        //postalCodePatternMap.put("NF", "[0-9]{5}");
     313        //postalCodePatternMap.put("NG", "[0-9]{5}");
     314        //postalCodePatternMap.put("NI", "[0-9]{5}");
     315        postalCodePatternMap.put("NL", "[0-9]{4} [A-Z]{2}"); // Dutch
     316        postalCodePatternMap.put("NO", "[0-9]{4}"); // Norway
     317        //postalCodePatternMap.put("NP", "[0-9]{5}");
     318        //postalCodePatternMap.put("NR", "[0-9]{5}");
     319        //postalCodePatternMap.put("NU", "[0-9]{5}");
     320        //postalCodePatternMap.put("NZ", "[0-9]{5}");
     321        //postalCodePatternMap.put("OM", "[0-9]{5}");
     322        //postalCodePatternMap.put("PA", "[0-9]{5}");
     323        //postalCodePatternMap.put("PE", "[0-9]{5}");
     324        //postalCodePatternMap.put("PF", "[0-9]{5}");
     325        //postalCodePatternMap.put("PG", "[0-9]{5}");
     326        //postalCodePatternMap.put("PH", "[0-9]{5}");
     327        //postalCodePatternMap.put("PK", "[0-9]{5}");
     328        postalCodePatternMap.put("PL", "[0-9]{2}-[0-9]{3}"); // Poland
     329        //postalCodePatternMap.put("PM", "[0-9]{5}");
     330        //postalCodePatternMap.put("PN", "[0-9]{5}");
     331        //postalCodePatternMap.put("PR", "[0-9]{5}");
     332        //postalCodePatternMap.put("PS", "[0-9]{5}");
     333        postalCodePatternMap.put("PT", "[0-9]{4}-[0-9]{3}"); // Portugal
     334        //postalCodePatternMap.put("PW", "[0-9]{5}");
     335        //postalCodePatternMap.put("PY", "[0-9]{5}");
     336        //postalCodePatternMap.put("QA", "[0-9]{5}");
     337        //postalCodePatternMap.put("RE", "[0-9]{5}");
     338        postalCodePatternMap.put("RO", "[0-9]{6}"); // Romania
     339        //postalCodePatternMap.put("RS", "[0-9]{5}");
     340        postalCodePatternMap.put("RU", "[0-9]{6}"); // Russia
     341        //postalCodePatternMap.put("RW", "[0-9]{5}");
     342        //postalCodePatternMap.put("SA", "[0-9]{5}");
     343        //postalCodePatternMap.put("SB", "[0-9]{5}");
     344        //postalCodePatternMap.put("SC", "[0-9]{5}");
     345        //postalCodePatternMap.put("SD", "[0-9]{5}");
     346        postalCodePatternMap.put("SE", "[0-9]{3} [0-9]{2}"); // Sweden: 999-99
     347        //postalCodePatternMap.put("SG", "[0-9]{5}");
     348        //postalCodePatternMap.put("SH", "[0-9]{5}");
     349        postalCodePatternMap.put("SI", "[0-9]{4}");
     350        //postalCodePatternMap.put("SJ", "[0-9]{5}");
     351        postalCodePatternMap.put("SK", "[0-9]{3} [0-9]{2}"); // Slovakia: 999-99
     352        postalCodePatternMap.put("SL", "[0-9]{4}"); // Slowenia
     353        postalCodePatternMap.put("SM", "[0-9]{5}"); // san marino -> Italy
     354        //postalCodePatternMap.put("SN", "[0-9]{5}");
     355        //postalCodePatternMap.put("SO", "[0-9]{5}");
     356        //postalCodePatternMap.put("SR", "[0-9]{5}");
     357        //postalCodePatternMap.put("ST", "[0-9]{5}");
     358        //postalCodePatternMap.put("SV", "[0-9]{5}");
     359        //postalCodePatternMap.put("SY", "[0-9]{5}");
     360        //postalCodePatternMap.put("SZ", "[0-9]{5}");
     361        //postalCodePatternMap.put("TC", "[0-9]{5}");
     362        //postalCodePatternMap.put("TD", "[0-9]{5}");
     363        //postalCodePatternMap.put("TF", "[0-9]{5}");
     364        //postalCodePatternMap.put("TG", "[0-9]{5}");
     365        //postalCodePatternMap.put("TH", "[0-9]{5}");
     366        //postalCodePatternMap.put("TJ", "[0-9]{5}");
     367        //postalCodePatternMap.put("TK", "[0-9]{5}");
     368        //postalCodePatternMap.put("TL", "[0-9]{5}");
     369        //postalCodePatternMap.put("TM", "[0-9]{5}");
     370        //postalCodePatternMap.put("TN", "[0-9]{5}");
     371        //postalCodePatternMap.put("TO", "[0-9]{5}");
     372        postalCodePatternMap.put("TR", "[0-9]{5}"); // turkye
     373        //postalCodePatternMap.put("TT", "[0-9]{5}");
     374        //postalCodePatternMap.put("TV", "[0-9]{5}");
     375        //postalCodePatternMap.put("TW", "[0-9]{5}");
     376        //postalCodePatternMap.put("TZ", "[0-9]{5}");
     377        postalCodePatternMap.put("UA", "[0-9]{5}"); // Ukraine
     378        //postalCodePatternMap.put("UG", "[0-9]{5}");
     379        //postalCodePatternMap.put("UM", "[0-9]{5}");
     380        postalCodePatternMap.put("US", "([A-Z]{2} )?[0-9]{5}"); // USA: support "99999" and "IL 99999"
     381        //postalCodePatternMap.put("UY", "[0-9]{5}");
     382        //postalCodePatternMap.put("UZ", "[0-9]{5}");
     383        //postalCodePatternMap.put("VA", "[0-9]{5}");
     384        //postalCodePatternMap.put("VC", "[0-9]{5}");
     385        //postalCodePatternMap.put("VE", "[0-9]{5}");
     386        //postalCodePatternMap.put("VG", "[0-9]{5}");
     387        //postalCodePatternMap.put("VI", "[0-9]{5}");
     388        //postalCodePatternMap.put("VN", "[0-9]{5}");
     389        //postalCodePatternMap.put("VU", "[0-9]{5}");
     390        //postalCodePatternMap.put("WF", "[0-9]{5}");
     391        //postalCodePatternMap.put("WS", "[0-9]{5}");
     392        //postalCodePatternMap.put("YE", "[0-9]{5}");
     393        //postalCodePatternMap.put("YT", "[0-9]{5}");
     394        //postalCodePatternMap.put("ZA", "[0-9]{5}");
     395        //postalCodePatternMap.put("ZM", "[0-9]{5}");
     396        //postalCodePatternMap.put("ZW", "[0-9]{5}");
     397    }
    410398}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/ProblemType.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
    164public enum ProblemType {
    17         Warning,
    18         Error,
     5    Warning,
     6    Error,
    197}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/SolutionType.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    197 */
    208public enum SolutionType {
    21         Remove,
    22         Change,
    23         Add
     9    Remove,
     10    Change,
     11    Add
    2412}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/StringUtils.java

    r26509 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    175
    186public class StringUtils {
    19         /**
    20         * Checks, if a string is either null or empty.
    21         *
    22         * @param txt
    23         *            Text to check
    24         * @return True, if string is null or empty; otherwise false
    25         */
    26         public static boolean isNullOrEmpty(String txt) {
    27                 return txt == null || txt.length() == 0;
    28         }
     7    /**
     8    * Checks, if a string is either null or empty.
     9    *
     10    * @param txt
     11    *            Text to check
     12    * @return True, if string is null or empty; otherwise false
     13    */
     14    public static boolean isNullOrEmpty(String txt) {
     15        return txt == null || txt.length() == 0;
     16    }
    2917
    30         /**
    31         * Gets the length of the longest common substring of a and b
    32         *
    33         * @param a
    34         *            First string
    35         * @param b
    36         *            Second string
    37         * @return The length of the longest common substring or 0, if no common
    38         *         sequence exists or one of the arguments are invalid. For
    39         *         algorithm details please refer to {@link http
    40         *         ://www.ics.uci.edu/~eppstein/161/960229.html}
    41         */
    42         public static int lcsLength(String a, String b) {
    43                 if (StringUtils.isNullOrEmpty(a))
    44                         return 0;
    45                 if (StringUtils.isNullOrEmpty(b))
    46                         return 0;
     18    /**
     19    * Gets the length of the longest common substring of a and b
     20    *
     21    * @param a
     22    *            First string
     23    * @param b
     24    *            Second string
     25    * @return The length of the longest common substring or 0, if no common
     26    *         sequence exists or one of the arguments are invalid. For
     27    *         algorithm details please refer to {@link http
     28    *         ://www.ics.uci.edu/~eppstein/161/960229.html}
     29    */
     30    public static int lcsLength(String a, String b) {
     31        if (StringUtils.isNullOrEmpty(a))
     32            return 0;
     33        if (StringUtils.isNullOrEmpty(b))
     34            return 0;
    4735
    48                 int[][] L = createLCSTable(a, b);
    49                 return L[0][0];
    50         }
     36        int[][] L = createLCSTable(a, b);
     37        return L[0][0];
     38    }
    5139
    52         /**
    53         * Internal use only
    54         */
    55         private static int[][] createLCSTable(String a, String b) {
    56                 if (StringUtils.isNullOrEmpty(a))
    57                         return null;
    58                 if (StringUtils.isNullOrEmpty(b))
    59                         return null;
     40    /**
     41    * Internal use only
     42    */
     43    private static int[][] createLCSTable(String a, String b) {
     44        if (StringUtils.isNullOrEmpty(a))
     45            return null;
     46        if (StringUtils.isNullOrEmpty(b))
     47            return null;
    6048
    61                 int m = a.length();
    62                 int n = b.length();
    63                 int[][] l = new int[m + 1][n + 1];
    64                 for (int i = 0; i < l.length; i++) {
    65                         l[i] = new int[n + 1];
    66                 }
     49        int m = a.length();
     50        int n = b.length();
     51        int[][] l = new int[m + 1][n + 1];
     52        for (int i = 0; i < l.length; i++) {
     53            l[i] = new int[n + 1];
     54        }
    6755
    68                 int i, j;
    69                 for (i = m - 1; i >= 0; i--) {
    70                         for (j = n - 1; j >= 0; j--) {
    71                                 /*
    72                                 * if (i >= m || j >= n) { l[i][j] = 0; } else
    73                                 */if (a.charAt(i) == b.charAt(j)) {
    74                                         l[i][j] = 1 + l[i + 1][j + 1];
    75                                 } else {
    76                                         l[i][j] = Math.max(l[i + 1][j], l[i][j + 1]);
    77                                 }
    78                         }
    79                 }
    80                 return l;
    81         }
     56        int i, j;
     57        for (i = m - 1; i >= 0; i--) {
     58            for (j = n - 1; j >= 0; j--) {
     59                /*
     60                * if (i >= m || j >= n) { l[i][j] = 0; } else
     61                */if (a.charAt(i) == b.charAt(j)) {
     62                    l[i][j] = 1 + l[i + 1][j + 1];
     63                } else {
     64                    l[i][j] = Math.max(l[i + 1][j], l[i][j + 1]);
     65                }
     66            }
     67        }
     68        return l;
     69    }
    8270
    83         /**
    84         * Gets the longest common substring of a and b.
    85         *
    86         * @param a The first string.
    87         * @param b The second string.
    88         * @return
    89         */
    90         public static String getLongestCommonSubstring(String a, String b) {
    91                 if (StringUtils.isNullOrEmpty(a))
    92                         return null;
    93                 if (StringUtils.isNullOrEmpty(b))
    94                         return null;
     71    /**
     72    * Gets the longest common substring of a and b.
     73    *
     74    * @param a The first string.
     75    * @param b The second string.
     76    * @return
     77    */
     78    public static String getLongestCommonSubstring(String a, String b) {
     79        if (StringUtils.isNullOrEmpty(a))
     80            return null;
     81        if (StringUtils.isNullOrEmpty(b))
     82            return null;
    9583
    96                 StringBuffer sb = new StringBuffer();
    97                 int[][] l = createLCSTable(a, b);
    98                 int m = a.length();
    99                 int n = b.length();
    100                 int i = 0;
    101                 int j = 0;
    102                 while (i < m && j < n) {
    103                         char aa = a.charAt(i);
    104                         char bb = b.charAt(j);
    105                         if (aa == bb) {
    106                                 sb.append(aa);
    107                                 i++;
    108                                 j++;
    109                         } else if (l[i + 1][j] >= l[i][j + 1]) {
    110                                 i++;
    111                         } else {
    112                                 j++;
    113                         }
    114                 }
     84        StringBuffer sb = new StringBuffer();
     85        int[][] l = createLCSTable(a, b);
     86        int m = a.length();
     87        int n = b.length();
     88        int i = 0;
     89        int j = 0;
     90        while (i < m && j < n) {
     91            char aa = a.charAt(i);
     92            char bb = b.charAt(j);
     93            if (aa == bb) {
     94                sb.append(aa);
     95                i++;
     96                j++;
     97            } else if (l[i + 1][j] >= l[i][j + 1]) {
     98                i++;
     99            } else {
     100                j++;
     101            }
     102        }
    115103
    116                 l = null;
    117                 return sb.toString();
    118         }
     104        l = null;
     105        return sb.toString();
     106    }
    119107
    120         /**
    121         * @param needle The string to find the best match for.
    122         * @param haystack The list of strings to pick the best match from.
    123         * @return The string of the list with the longest common substring to needle or
    124         * <tt>null</tt>, if either <tt>needle</tt> or <tt>haystack</tt> is empty or null.
    125         */
    126         public static String findBestMatch(String needle, List<String> haystack) {
    127                 String bestMatch = null;
    128                 double maxRatio = Double.MIN_VALUE;
     108    /**
     109    * @param needle The string to find the best match for.
     110    * @param haystack The list of strings to pick the best match from.
     111    * @return The string of the list with the longest common substring to needle or
     112    * <tt>null</tt>, if either <tt>needle</tt> or <tt>haystack</tt> is empty or null.
     113    */
     114    public static String findBestMatch(String needle, List<String> haystack) {
     115        String bestMatch = null;
     116        double maxRatio = Double.MIN_VALUE;
    129117
    130                 if (StringUtils.isNullOrEmpty(needle)) {
    131                         return null;
    132                 }
    133                 if (haystack == null || haystack.size() == 0) {
    134                         return null;
    135                 }
     118        if (StringUtils.isNullOrEmpty(needle)) {
     119            return null;
     120        }
     121        if (haystack == null || haystack.size() == 0) {
     122            return null;
     123        }
    136124
    137                 int lNeedle = needle.length();
    138                 for (String curString : haystack) {
    139                         int ll = lcsLength(needle, curString);
    140                         double ratio = ll / (double)lNeedle;
    141                         if (ratio > maxRatio) {
    142                                 maxRatio = ratio;
    143                                 bestMatch = curString;
    144                         }
     125        int lNeedle = needle.length();
     126        for (String curString : haystack) {
     127            int ll = lcsLength(needle, curString);
     128            double ratio = ll / (double)lNeedle;
     129            if (ratio > maxRatio) {
     130                maxRatio = ratio;
     131                bestMatch = curString;
     132            }
    145133
    146                 }
     134        }
    147135
    148                 return bestMatch;
    149         }
     136        return bestMatch;
     137    }
    150138}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java

    r27338 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses;
    153
     
    2715 */
    2816public final class TagUtils {
    29         private static String COUNTRIES_REQUIRE_STATE[] = {
    30                 "en_US",    /* USA */
    31                 "en_AU" /* Australia */
    32         };
    33 
    34         /**
    35         * Checks if the given OSM object has a (non-empty) value for the given tag.
    36         *
    37         * @param osm the osm object to inspect.
    38         * @param tag the tag to look for.
    39         * @return true, if osm object has a non-empty value for this tag
    40         */
    41         public static boolean hasTag(OsmPrimitive osm, String tag) {
    42                 return osm != null && !StringUtils.isNullOrEmpty(osm.get(tag));
    43         }
    44 
    45         /**
    46         * Checks if the given OSM primitive is an address node.
    47         * @return
    48         */
    49         public static boolean isAddress(OsmPrimitive osmObject) {
    50                 return  TagUtils.hasAddrCityTag(osmObject) || TagUtils.hasAddrCountryTag(osmObject) ||
    51                                 TagUtils.hasAddrHousenumberTag(osmObject) || TagUtils.hasAddrPostcodeTag(osmObject) ||
    52                                 TagUtils.hasAddrStateTag(osmObject) || TagUtils.hasAddrStreetTag(osmObject);
    53         }
    54 
    55         /**
    56         * Check if OSM primitive has a tag 'parking'.
    57         *
    58         * @param osmPrimitive
    59         *            The OSM entity to check.
    60         */
    61         public static boolean hasParkingTag(OsmPrimitive osmPrimitive) {
    62                 return osmPrimitive != null ? osmPrimitive.hasKey(PARKING_TAG) : false;
    63         }
    64 
    65         /**
    66         * Gets the value of tag 'parking'.
    67         *
    68         * @param osmPrimitive
    69         *            The OSM entity to check.
    70         */
    71         public static String getParkingValue(OsmPrimitive osmPrimitive) {
    72                 return osmPrimitive != null ? osmPrimitive.get(PARKING_TAG) : null;
    73         }
    74 
    75         /**
    76         * Check if OSM primitive has a tag 'shop'.
    77         *
    78         * @param osmPrimitive
    79         *            The OSM entity to check.
    80         */
    81         public static boolean hasShopTag(OsmPrimitive osmPrimitive) {
    82                 return osmPrimitive != null ? osmPrimitive.hasKey(SHOP_TAG) : false;
    83         }
    84 
    85         /**
    86         * Gets the value of tag 'shop'.
    87         *
    88         * @param osmPrimitive
    89         *            The OSM entity to check.
    90         */
    91         public static String getShopValue(OsmPrimitive osmPrimitive) {
    92                 return osmPrimitive != null ? osmPrimitive.get(SHOP_TAG) : null;
    93         }
    94 
    95         /**
    96         * Check if OSM primitive has a tag 'craft'.
    97         *
    98         * @param osmPrimitive
    99         *            The OSM entity to check.
    100         */
    101         public static boolean hasCraftTag(OsmPrimitive osmPrimitive) {
    102                 return osmPrimitive != null ? osmPrimitive.hasKey(CRAFT_TAG) : false;
    103         }
    104 
    105         /**
    106         * Gets the value of tag 'craft'.
    107         *
    108         * @param osmPrimitive
    109         *            The OSM entity to check.
    110         */
    111         public static String getCraftValue(OsmPrimitive osmPrimitive) {
    112                 return osmPrimitive != null ? osmPrimitive.get(CRAFT_TAG) : null;
    113         }
    114 
    115         /**
    116         * Check if OSM primitive has a tag 'surface'.
    117         *
    118         * @param osmPrimitive
    119         *            The OSM entity to check.
    120         */
    121         public static boolean hasSurfaceTag(OsmPrimitive osmPrimitive) {
    122                 return osmPrimitive != null ? osmPrimitive.hasKey(SURFACE_TAG) : false;
    123         }
    124 
    125         /**
    126         * Gets the value of tag 'surface'.
    127         *
    128         * @param osmPrimitive
    129         *            The OSM entity to check.
    130         */
    131         public static String getSurfaceValue(OsmPrimitive osmPrimitive) {
    132                 return osmPrimitive != null ? osmPrimitive.get(SURFACE_TAG) : null;
    133         }
    134 
    135         /**
    136         * Check if OSM primitive has a tag 'cuisine'.
    137         *
    138         * @param osmPrimitive
    139         *            The OSM entity to check.
    140         */
    141         public static boolean hasCuisineTag(OsmPrimitive osmPrimitive) {
    142                 return osmPrimitive != null ? osmPrimitive.hasKey(CUISINE_TAG) : false;
    143         }
    144 
    145         /**
    146         * Gets the value of tag 'cuisine'.
    147         *
    148         * @param osmPrimitive
    149         *            The OSM entity to check.
    150         */
    151         public static String getCuisineValue(OsmPrimitive osmPrimitive) {
    152                 return osmPrimitive != null ? osmPrimitive.get(CUISINE_TAG) : null;
    153         }
    154 
    155         /**
    156         * Check if OSM primitive has a tag 'wood'.
    157         *
    158         * @param osmPrimitive
    159         *            The OSM entity to check.
    160         */
    161         public static boolean hasWoodTag(OsmPrimitive osmPrimitive) {
    162                 return osmPrimitive != null ? osmPrimitive.hasKey(WOOD_TAG) : false;
    163         }
    164 
    165         /**
    166         * Gets the value of tag 'wood'.
    167         *
    168         * @param osmPrimitive
    169         *            The OSM entity to check.
    170         */
    171         public static String getWoodValue(OsmPrimitive osmPrimitive) {
    172                 return osmPrimitive != null ? osmPrimitive.get(WOOD_TAG) : null;
    173         }
    174 
    175         /**
    176         * Check if OSM primitive has a tag 'foot'.
    177         *
    178         * @param osmPrimitive
    179         *            The OSM entity to check.
    180         */
    181         public static boolean hasFootTag(OsmPrimitive osmPrimitive) {
    182                 return osmPrimitive != null ? osmPrimitive.hasKey(FOOT_TAG) : false;
    183         }
    184 
    185         /**
    186         * Gets the value of tag 'foot'.
    187         *
    188         * @param osmPrimitive
    189         *            The OSM entity to check.
    190         */
    191         public static String getFootValue(OsmPrimitive osmPrimitive) {
    192                 return osmPrimitive != null ? osmPrimitive.get(FOOT_TAG) : null;
    193         }
    194 
    195         /**
    196         * Check if OSM primitive has a tag 'name:de'.
    197         *
    198         * @param osmPrimitive
    199         *            The OSM entity to check.
    200         */
    201         public static boolean hasNameDeTag(OsmPrimitive osmPrimitive) {
    202                 return osmPrimitive != null ? osmPrimitive.hasKey(NAME_DE_TAG) : false;
    203         }
    204 
    205         /**
    206         * Gets the value of tag 'name:de'.
    207         *
    208         * @param osmPrimitive
    209         *            The OSM entity to check.
    210         */
    211         public static String getNameDeValue(OsmPrimitive osmPrimitive) {
    212                 return osmPrimitive != null ? osmPrimitive.get(NAME_DE_TAG) : null;
    213         }
    214 
    215         /**
    216         * Check if OSM primitive has a tag 'nat_ref'.
    217         *
    218         * @param osmPrimitive
    219         *            The OSM entity to check.
    220         */
    221         public static boolean hasNatRefTag(OsmPrimitive osmPrimitive) {
    222                 return osmPrimitive != null ? osmPrimitive.hasKey(NAT_REF_TAG) : false;
    223         }
    224 
    225         /**
    226         * Gets the value of tag 'nat_ref'.
    227         *
    228         * @param osmPrimitive
    229         *            The OSM entity to check.
    230         */
    231         public static String getNatRefValue(OsmPrimitive osmPrimitive) {
    232                 return osmPrimitive != null ? osmPrimitive.get(NAT_REF_TAG) : null;
    233         }
    234 
    235         /**
    236         * Check if OSM primitive has a tag 'note:de'.
    237         *
    238         * @param osmPrimitive
    239         *            The OSM entity to check.
    240         */
    241         public static boolean hasNoteDeTag(OsmPrimitive osmPrimitive) {
    242                 return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_DE_TAG) : false;
    243         }
    244 
    245         /**
    246         * Gets the value of tag 'note:de'.
    247         *
    248         * @param osmPrimitive
    249         *            The OSM entity to check.
    250         */
    251         public static String getNoteDeValue(OsmPrimitive osmPrimitive) {
    252                 return osmPrimitive != null ? osmPrimitive.get(NOTE_DE_TAG) : null;
    253         }
    254 
    255         /**
    256         * Check if OSM primitive has a tag 'addr:street'.
    257         *
    258         * @param osmPrimitive
    259         *            The OSM entity to check.
    260         */
    261         public static boolean hasAddrStreetTag(OsmPrimitive osmPrimitive) {
    262                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STREET_TAG)
    263                                 : false;
    264         }
    265 
    266         /**
    267         * Gets the value of tag 'addr:street'.
    268         *
    269         * @param osmPrimitive
    270         *            The OSM entity to check.
    271         */
    272         public static String getAddrStreetValue(OsmPrimitive osmPrimitive) {
    273                 return osmPrimitive != null ? osmPrimitive.get(ADDR_STREET_TAG) : null;
    274         }
    275 
    276         /**
    277         * Check if OSM primitive has a tag 'type'.
    278         *
    279         * @param osmPrimitive
    280         *            The OSM entity to check.
    281         */
    282         public static boolean hasTypeTag(OsmPrimitive osmPrimitive) {
    283                 return osmPrimitive != null ? osmPrimitive.hasKey(TYPE_TAG) : false;
    284         }
    285 
    286         /**
    287         * Gets the value of tag 'type'.
    288         *
    289         * @param osmPrimitive
    290         *            The OSM entity to check.
    291         */
    292         public static String getTypeValue(OsmPrimitive osmPrimitive) {
    293                 return osmPrimitive != null ? osmPrimitive.get(TYPE_TAG) : null;
    294         }
    295 
    296         /**
    297         * Check if OSM primitive has a tag 'addr:city'.
    298         *
    299         * @param osmPrimitive
    300         *            The OSM entity to check.
    301         */
    302         public static boolean hasAddrCityTag(OsmPrimitive osmPrimitive) {
    303                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_CITY_TAG)
    304                                 : false;
    305         }
    306 
    307         /**
    308         * Gets the value of tag 'addr:city'.
    309         *
    310         * @param osmPrimitive
    311         *            The OSM entity to check.
    312         */
    313         public static String getAddrCityValue(OsmPrimitive osmPrimitive) {
    314                 return osmPrimitive != null ? osmPrimitive.get(ADDR_CITY_TAG) : null;
    315         }
    316 
    317         /**
    318         * Check if OSM primitive has a tag 'boundary'.
    319         *
    320         * @param osmPrimitive
    321         *            The OSM entity to check.
    322         */
    323         public static boolean hasBoundaryTag(OsmPrimitive osmPrimitive) {
    324                 return osmPrimitive != null ? osmPrimitive.hasKey(BOUNDARY_TAG) : false;
    325         }
    326 
    327         /**
    328         * Gets the value of tag 'boundary'.
    329         *
    330         * @param osmPrimitive
    331         *            The OSM entity to check.
    332         */
    333         public static String getBoundaryValue(OsmPrimitive osmPrimitive) {
    334                 return osmPrimitive != null ? osmPrimitive.get(BOUNDARY_TAG) : null;
    335         }
    336 
    337         /**
    338         * Check if OSM primitive has a tag 'smoothness'.
    339         *
    340         * @param osmPrimitive
    341         *            The OSM entity to check.
    342         */
    343         public static boolean hasSmoothnessTag(OsmPrimitive osmPrimitive) {
    344                 return osmPrimitive != null ? osmPrimitive.hasKey(SMOOTHNESS_TAG)
    345                                 : false;
    346         }
    347 
    348         /**
    349         * Gets the value of tag 'smoothness'.
    350         *
    351         * @param osmPrimitive
    352         *            The OSM entity to check.
    353         */
    354         public static String getSmoothnessValue(OsmPrimitive osmPrimitive) {
    355                 return osmPrimitive != null ? osmPrimitive.get(SMOOTHNESS_TAG) : null;
    356         }
    357 
    358         /**
    359         * Check if OSM primitive has a tag 'opening_hours'.
    360         *
    361         * @param osmPrimitive
    362         *            The OSM entity to check.
    363         */
    364         public static boolean hasOpeningHoursTag(OsmPrimitive osmPrimitive) {
    365                 return osmPrimitive != null ? osmPrimitive.hasKey(OPENING_HOURS_TAG)
    366                                 : false;
    367         }
    368 
    369         /**
    370         * Gets the value of tag 'opening_hours'.
    371         *
    372         * @param osmPrimitive
    373         *            The OSM entity to check.
    374         */
    375         public static String getOpeningHoursValue(OsmPrimitive osmPrimitive) {
    376                 return osmPrimitive != null ? osmPrimitive.get(OPENING_HOURS_TAG)
    377                                 : null;
    378         }
    379 
    380         /**
    381         * Check if OSM primitive has a tag 'bicycle'.
    382         *
    383         * @param osmPrimitive
    384         *            The OSM entity to check.
    385         */
    386         public static boolean hasBicycleTag(OsmPrimitive osmPrimitive) {
    387                 return osmPrimitive != null ? osmPrimitive.hasKey(BICYCLE_TAG) : false;
    388         }
    389 
    390         /**
    391         * Gets the value of tag 'bicycle'.
    392         *
    393         * @param osmPrimitive
    394         *            The OSM entity to check.
    395         */
    396         public static String getBicycleValue(OsmPrimitive osmPrimitive) {
    397                 return osmPrimitive != null ? osmPrimitive.get(BICYCLE_TAG) : null;
    398         }
    399 
    400         /**
    401         * Check if OSM primitive has a tag 'religion'.
    402         *
    403         * @param osmPrimitive
    404         *            The OSM entity to check.
    405         */
    406         public static boolean hasReligionTag(OsmPrimitive osmPrimitive) {
    407                 return osmPrimitive != null ? osmPrimitive.hasKey(RELIGION_TAG) : false;
    408         }
    409 
    410         /**
    411         * Gets the value of tag 'religion'.
    412         *
    413         * @param osmPrimitive
    414         *            The OSM entity to check.
    415         */
    416         public static String getReligionValue(OsmPrimitive osmPrimitive) {
    417                 return osmPrimitive != null ? osmPrimitive.get(RELIGION_TAG) : null;
    418         }
    419 
    420         /**
    421         * Check if OSM primitive has a tag 'barrier'.
    422         *
    423         * @param osmPrimitive
    424         *            The OSM entity to check.
    425         */
    426         public static boolean hasBarrierTag(OsmPrimitive osmPrimitive) {
    427                 return osmPrimitive != null ? osmPrimitive.hasKey(BARRIER_TAG) : false;
    428         }
    429 
    430         /**
    431         * Gets the value of tag 'barrier'.
    432         *
    433         * @param osmPrimitive
    434         *            The OSM entity to check.
    435         */
    436         public static String getBarrierValue(OsmPrimitive osmPrimitive) {
    437                 return osmPrimitive != null ? osmPrimitive.get(BARRIER_TAG) : null;
    438         }
    439 
    440         /**
    441         * Check if OSM primitive has a tag 'power'.
    442         *
    443         * @param osmPrimitive
    444         *            The OSM entity to check.
    445         */
    446         public static boolean hasPowerTag(OsmPrimitive osmPrimitive) {
    447                 return osmPrimitive != null ? osmPrimitive.hasKey(POWER_TAG) : false;
    448         }
    449 
    450         /**
    451         * Gets the value of tag 'power'.
    452         *
    453         * @param osmPrimitive
    454         *            The OSM entity to check.
    455         */
    456         public static String getPowerValue(OsmPrimitive osmPrimitive) {
    457                 return osmPrimitive != null ? osmPrimitive.get(POWER_TAG) : null;
    458         }
    459 
    460         /**
    461         * Check if OSM primitive has a tag 'landuse'.
    462         *
    463         * @param osmPrimitive
    464         *            The OSM entity to check.
    465         */
    466         public static boolean hasLanduseTag(OsmPrimitive osmPrimitive) {
    467                 return osmPrimitive != null ? osmPrimitive.hasKey(LANDUSE_TAG) : false;
    468         }
    469 
    470         /**
    471         * Gets the value of tag 'landuse'.
    472         *
    473         * @param osmPrimitive
    474         *            The OSM entity to check.
    475         */
    476         public static String getLanduseValue(OsmPrimitive osmPrimitive) {
    477                 return osmPrimitive != null ? osmPrimitive.get(LANDUSE_TAG) : null;
    478         }
    479 
    480         /**
    481         * Check if OSM primitive has a tag 'fireplace'.
    482         *
    483         * @param osmPrimitive
    484         *            The OSM entity to check.
    485         */
    486         public static boolean hasFireplaceTag(OsmPrimitive osmPrimitive) {
    487                 return osmPrimitive != null ? osmPrimitive.hasKey(FIREPLACE_TAG)
    488                                 : false;
    489         }
    490 
    491         /**
    492         * Gets the value of tag 'fireplace'.
    493         *
    494         * @param osmPrimitive
    495         *            The OSM entity to check.
    496         */
    497         public static String getFireplaceValue(OsmPrimitive osmPrimitive) {
    498                 return osmPrimitive != null ? osmPrimitive.get(FIREPLACE_TAG) : null;
    499         }
    500 
    501         /**
    502         * Check if OSM primitive has a tag 'int_ref'.
    503         *
    504         * @param osmPrimitive
    505         *            The OSM entity to check.
    506         */
    507         public static boolean hasIntRefTag(OsmPrimitive osmPrimitive) {
    508                 return osmPrimitive != null ? osmPrimitive.hasKey(INT_REF_TAG) : false;
    509         }
    510 
    511         /**
    512         * Gets the value of tag 'int_ref'.
    513         *
    514         * @param osmPrimitive
    515         *            The OSM entity to check.
    516         */
    517         public static String getIntRefValue(OsmPrimitive osmPrimitive) {
    518                 return osmPrimitive != null ? osmPrimitive.get(INT_REF_TAG) : null;
    519         }
    520 
    521         /**
    522         * Check if OSM primitive has a tag 'whitewater:section_grade'.
    523         *
    524         * @param osmPrimitive
    525         *            The OSM entity to check.
    526         */
    527         public static boolean hasWhitewaterSectionGradeTag(OsmPrimitive osmPrimitive) {
    528                 return osmPrimitive != null ? osmPrimitive
    529                                 .hasKey(WHITEWATER_SECTION_GRADE_TAG) : false;
    530         }
    531 
    532         /**
    533         * Gets the value of tag 'whitewater:section_grade'.
    534         *
    535         * @param osmPrimitive
    536         *            The OSM entity to check.
    537         */
    538         public static String getWhitewaterSectionGradeValue(
    539                         OsmPrimitive osmPrimitive) {
    540                 return osmPrimitive != null ? osmPrimitive
    541                                 .get(WHITEWATER_SECTION_GRADE_TAG) : null;
    542         }
    543 
    544         /**
    545         * Check if OSM primitive has a tag 'denomination'.
    546         *
    547         * @param osmPrimitive
    548         *            The OSM entity to check.
    549         */
    550         public static boolean hasDenominationTag(OsmPrimitive osmPrimitive) {
    551                 return osmPrimitive != null ? osmPrimitive.hasKey(DENOMINATION_TAG)
    552                                 : false;
    553         }
    554 
    555         /**
    556         * Gets the value of tag 'denomination'.
    557         *
    558         * @param osmPrimitive
    559         *            The OSM entity to check.
    560         */
    561         public static String getDenominationValue(OsmPrimitive osmPrimitive) {
    562                 return osmPrimitive != null ? osmPrimitive.get(DENOMINATION_TAG) : null;
    563         }
    564 
    565         /**
    566         * Check if OSM primitive has a tag 'addr:postcode'.
    567         *
    568         * @param osmPrimitive
    569         *            The OSM entity to check.
    570         */
    571         public static boolean hasAddrPostcodeTag(OsmPrimitive osmPrimitive) {
    572                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_POSTCODE_TAG)
    573                                 : false;
    574         }
    575 
    576         /**
    577         * Gets the value of tag 'addr:postcode'.
    578         *
    579         * @param osmPrimitive
    580         *            The OSM entity to check.
    581         */
    582         public static String getAddrPostcodeValue(OsmPrimitive osmPrimitive) {
    583                 return osmPrimitive != null ? osmPrimitive.get(ADDR_POSTCODE_TAG)
    584                                 : null;
    585         }
    586 
    587         /**
    588         * Check if OSM primitive has a tag 'wires'.
    589         *
    590         * @param osmPrimitive
    591         *            The OSM entity to check.
    592         */
    593         public static boolean hasWiresTag(OsmPrimitive osmPrimitive) {
    594                 return osmPrimitive != null ? osmPrimitive.hasKey(WIRES_TAG) : false;
    595         }
    596 
    597         /**
    598         * Gets the value of tag 'wires'.
    599         *
    600         * @param osmPrimitive
    601         *            The OSM entity to check.
    602         */
    603         public static String getWiresValue(OsmPrimitive osmPrimitive) {
    604                 return osmPrimitive != null ? osmPrimitive.get(WIRES_TAG) : null;
    605         }
    606 
    607         /**
    608         * Check if OSM primitive has a tag 'loc_ref'.
    609         *
    610         * @param osmPrimitive
    611         *            The OSM entity to check.
    612         */
    613         public static boolean hasLocRefTag(OsmPrimitive osmPrimitive) {
    614                 return osmPrimitive != null ? osmPrimitive.hasKey(LOC_REF_TAG) : false;
    615         }
    616 
    617         /**
    618         * Gets the value of tag 'loc_ref'.
    619         *
    620         * @param osmPrimitive
    621         *            The OSM entity to check.
    622         */
    623         public static String getLocRefValue(OsmPrimitive osmPrimitive) {
    624                 return osmPrimitive != null ? osmPrimitive.get(LOC_REF_TAG) : null;
    625         }
    626 
    627         /**
    628         * Check if OSM primitive has a tag 'width'.
    629         *
    630         * @param osmPrimitive
    631         *            The OSM entity to check.
    632         */
    633         public static boolean hasWidthTag(OsmPrimitive osmPrimitive) {
    634                 return osmPrimitive != null ? osmPrimitive.hasKey(WIDTH_TAG) : false;
    635         }
    636 
    637         /**
    638         * Gets the value of tag 'width'.
    639         *
    640         * @param osmPrimitive
    641         *            The OSM entity to check.
    642         */
    643         public static String getWidthValue(OsmPrimitive osmPrimitive) {
    644                 return osmPrimitive != null ? osmPrimitive.get(WIDTH_TAG) : null;
    645         }
    646 
    647         /**
    648         * Check if OSM primitive has a tag 'tourism'.
    649         *
    650         * @param osmPrimitive
    651         *            The OSM entity to check.
    652         */
    653         public static boolean hasTourismTag(OsmPrimitive osmPrimitive) {
    654                 return osmPrimitive != null ? osmPrimitive.hasKey(TOURISM_TAG) : false;
    655         }
    656 
    657         /**
    658         * Gets the value of tag 'tourism'.
    659         *
    660         * @param osmPrimitive
    661         *            The OSM entity to check.
    662         */
    663         public static String getTourismValue(OsmPrimitive osmPrimitive) {
    664                 return osmPrimitive != null ? osmPrimitive.get(TOURISM_TAG) : null;
    665         }
    666 
    667         /**
    668         * Check if OSM primitive has a tag 'leisure'.
    669         *
    670         * @param osmPrimitive
    671         *            The OSM entity to check.
    672         */
    673         public static boolean hasLeisureTag(OsmPrimitive osmPrimitive) {
    674                 return osmPrimitive != null ? osmPrimitive.hasKey(LEISURE_TAG) : false;
    675         }
    676 
    677         /**
    678         * Gets the value of tag 'leisure'.
    679         *
    680         * @param osmPrimitive
    681         *            The OSM entity to check.
    682         */
    683         public static String getLeisureValue(OsmPrimitive osmPrimitive) {
    684                 return osmPrimitive != null ? osmPrimitive.get(LEISURE_TAG) : null;
    685         }
    686 
    687         /**
    688         * Check if OSM primitive has a tag 'electrified'.
    689         *
    690         * @param osmPrimitive
    691         *            The OSM entity to check.
    692         */
    693         public static boolean hasElectrifiedTag(OsmPrimitive osmPrimitive) {
    694                 return osmPrimitive != null ? osmPrimitive.hasKey(ELECTRIFIED_TAG)
    695                                 : false;
    696         }
    697 
    698         /**
    699         * Gets the value of tag 'electrified'.
    700         *
    701         * @param osmPrimitive
    702         *            The OSM entity to check.
    703         */
    704         public static String getElectrifiedValue(OsmPrimitive osmPrimitive) {
    705                 return osmPrimitive != null ? osmPrimitive.get(ELECTRIFIED_TAG) : null;
    706         }
    707 
    708         /**
    709         * Check if OSM primitive has a tag 'junction'.
    710         *
    711         * @param osmPrimitive
    712         *            The OSM entity to check.
    713         */
    714         public static boolean hasJunctionTag(OsmPrimitive osmPrimitive) {
    715                 return osmPrimitive != null ? osmPrimitive.hasKey(JUNCTION_TAG) : false;
    716         }
    717 
    718         /**
    719         * Gets the value of tag 'junction'.
    720         *
    721         * @param osmPrimitive
    722         *            The OSM entity to check.
    723         */
    724         public static String getJunctionValue(OsmPrimitive osmPrimitive) {
    725                 return osmPrimitive != null ? osmPrimitive.get(JUNCTION_TAG) : null;
    726         }
    727 
    728         /**
    729         * Check if OSM primitive has a tag 'railway'.
    730         *
    731         * @param osmPrimitive
    732         *            The OSM entity to check.
    733         */
    734         public static boolean hasRailwayTag(OsmPrimitive osmPrimitive) {
    735                 return osmPrimitive != null ? osmPrimitive.hasKey(RAILWAY_TAG) : false;
    736         }
    737 
    738         /**
    739         * Gets the value of tag 'railway'.
    740         *
    741         * @param osmPrimitive
    742         *            The OSM entity to check.
    743         */
    744         public static String getRailwayValue(OsmPrimitive osmPrimitive) {
    745                 return osmPrimitive != null ? osmPrimitive.get(RAILWAY_TAG) : null;
    746         }
    747 
    748         /**
    749         * Check if OSM primitive has a tag 'voltage'.
    750         *
    751         * @param osmPrimitive
    752         *            The OSM entity to check.
    753         */
    754         public static boolean hasVoltageTag(OsmPrimitive osmPrimitive) {
    755                 return osmPrimitive != null ? osmPrimitive.hasKey(VOLTAGE_TAG) : false;
    756         }
    757 
    758         /**
    759         * Gets the value of tag 'voltage'.
    760         *
    761         * @param osmPrimitive
    762         *            The OSM entity to check.
    763         */
    764         public static String getVoltageValue(OsmPrimitive osmPrimitive) {
    765                 return osmPrimitive != null ? osmPrimitive.get(VOLTAGE_TAG) : null;
    766         }
    767 
    768         /**
    769         * Check if OSM primitive has a tag 'bridge'.
    770         *
    771         * @param osmPrimitive
    772         *            The OSM entity to check.
    773         */
    774         public static boolean hasBridgeTag(OsmPrimitive osmPrimitive) {
    775                 return osmPrimitive != null ? osmPrimitive.hasKey(BRIDGE_TAG) : false;
    776         }
    777 
    778         /**
    779         * Gets the value of tag 'bridge'.
    780         *
    781         * @param osmPrimitive
    782         *            The OSM entity to check.
    783         */
    784         public static String getBridgeValue(OsmPrimitive osmPrimitive) {
    785                 return osmPrimitive != null ? osmPrimitive.get(BRIDGE_TAG) : null;
    786         }
    787 
    788         /**
    789         * Check if OSM primitive has a tag 'motor_vehicle'.
    790         *
    791         * @param osmPrimitive
    792         *            The OSM entity to check.
    793         */
    794         public static boolean hasMotorVehicleTag(OsmPrimitive osmPrimitive) {
    795                 return osmPrimitive != null ? osmPrimitive.hasKey(MOTOR_VEHICLE_TAG)
    796                                 : false;
    797         }
    798 
    799         /**
    800         * Gets the value of tag 'motor_vehicle'.
    801         *
    802         * @param osmPrimitive
    803         *            The OSM entity to check.
    804         */
    805         public static String getMotorVehicleValue(OsmPrimitive osmPrimitive) {
    806                 return osmPrimitive != null ? osmPrimitive.get(MOTOR_VEHICLE_TAG)
    807                                 : null;
    808         }
    809 
    810         /**
    811         * Check if OSM primitive has a tag 'comment'.
    812         *
    813         * @param osmPrimitive
    814         *            The OSM entity to check.
    815         */
    816         public static boolean hasCommentTag(OsmPrimitive osmPrimitive) {
    817                 return osmPrimitive != null ? osmPrimitive.hasKey(COMMENT_TAG) : false;
    818         }
    819 
    820         /**
    821         * Gets the value of tag 'comment'.
    822         *
    823         * @param osmPrimitive
    824         *            The OSM entity to check.
    825         */
    826         public static String getCommentValue(OsmPrimitive osmPrimitive) {
    827                 return osmPrimitive != null ? osmPrimitive.get(COMMENT_TAG) : null;
    828         }
    829 
    830         /**
    831         * Check if OSM primitive has a tag 'maxspeed'.
    832         *
    833         * @param osmPrimitive
    834         *            The OSM entity to check.
    835         */
    836         public static boolean hasMaxspeedTag(OsmPrimitive osmPrimitive) {
    837                 return osmPrimitive != null ? osmPrimitive.hasKey(MAXSPEED_TAG) : false;
    838         }
    839 
    840         /**
    841         * Gets the value of tag 'maxspeed'.
    842         *
    843         * @param osmPrimitive
    844         *            The OSM entity to check.
    845         */
    846         public static String getMaxspeedValue(OsmPrimitive osmPrimitive) {
    847                 return osmPrimitive != null ? osmPrimitive.get(MAXSPEED_TAG) : null;
    848         }
    849 
    850         /**
    851         * Check if OSM primitive has a tag 'natural'.
    852         *
    853         * @param osmPrimitive
    854         *            The OSM entity to check.
    855         */
    856         public static boolean hasNaturalTag(OsmPrimitive osmPrimitive) {
    857                 return osmPrimitive != null ? osmPrimitive.hasKey(NATURAL_TAG) : false;
    858         }
    859 
    860         /**
    861         * Gets the value of tag 'natural'.
    862         *
    863         * @param osmPrimitive
    864         *            The OSM entity to check.
    865         */
    866         public static String getNaturalValue(OsmPrimitive osmPrimitive) {
    867                 return osmPrimitive != null ? osmPrimitive.get(NATURAL_TAG) : null;
    868         }
    869 
    870         /**
    871         * Check if OSM primitive has a tag 'sac_scale'.
    872         *
    873         * @param osmPrimitive
    874         *            The OSM entity to check.
    875         */
    876         public static boolean hasSacScaleTag(OsmPrimitive osmPrimitive) {
    877                 return osmPrimitive != null ? osmPrimitive.hasKey(SAC_SCALE_TAG)
    878                                 : false;
    879         }
    880 
    881         /**
    882         * Gets the value of tag 'sac_scale'.
    883         *
    884         * @param osmPrimitive
    885         *            The OSM entity to check.
    886         */
    887         public static String getSacScaleValue(OsmPrimitive osmPrimitive) {
    888                 return osmPrimitive != null ? osmPrimitive.get(SAC_SCALE_TAG) : null;
    889         }
    890 
    891         /**
    892         * Check if OSM primitive has a tag 'tunnel'.
    893         *
    894         * @param osmPrimitive
    895         *            The OSM entity to check.
    896         */
    897         public static boolean hasTunnelTag(OsmPrimitive osmPrimitive) {
    898                 return osmPrimitive != null ? osmPrimitive.hasKey(TUNNEL_TAG) : false;
    899         }
    900 
    901         /**
    902         * Gets the value of tag 'tunnel'.
    903         *
    904         * @param osmPrimitive
    905         *            The OSM entity to check.
    906         */
    907         public static String getTunnelValue(OsmPrimitive osmPrimitive) {
    908                 return osmPrimitive != null ? osmPrimitive.get(TUNNEL_TAG) : null;
    909         }
    910 
    911         /**
    912         * Check if OSM primitive has a tag 'waterway'.
    913         *
    914         * @param osmPrimitive
    915         *            The OSM entity to check.
    916         */
    917         public static boolean hasWaterwayTag(OsmPrimitive osmPrimitive) {
    918                 return osmPrimitive != null ? osmPrimitive.hasKey(WATERWAY_TAG) : false;
    919         }
    920 
    921         /**
    922         * Gets the value of tag 'waterway'.
    923         *
    924         * @param osmPrimitive
    925         *            The OSM entity to check.
    926         */
    927         public static String getWaterwayValue(OsmPrimitive osmPrimitive) {
    928                 return osmPrimitive != null ? osmPrimitive.get(WATERWAY_TAG) : null;
    929         }
    930 
    931         /**
    932         * Check if OSM primitive has a tag 'trail_visibility'.
    933         *
    934         * @param osmPrimitive
    935         *            The OSM entity to check.
    936         */
    937         public static boolean hasTrailVisibilityTag(OsmPrimitive osmPrimitive) {
    938                 return osmPrimitive != null ? osmPrimitive.hasKey(TRAIL_VISIBILITY_TAG)
    939                                 : false;
    940         }
    941 
    942         /**
    943         * Gets the value of tag 'trail_visibility'.
    944         *
    945         * @param osmPrimitive
    946         *            The OSM entity to check.
    947         */
    948         public static String getTrailVisibilityValue(OsmPrimitive osmPrimitive) {
    949                 return osmPrimitive != null ? osmPrimitive.get(TRAIL_VISIBILITY_TAG)
    950                                 : null;
    951         }
    952 
    953         /**
    954         * Check if OSM primitive has a tag 'highway'.
    955         *
    956         * @param osmPrimitive
    957         *            The OSM entity to check.
    958         */
    959         public static boolean hasHighwayTag(OsmPrimitive osmPrimitive) {
    960                 return osmPrimitive != null ? osmPrimitive.hasKey(HIGHWAY_TAG) : false;
    961         }
    962 
    963         /**
    964         * Gets the value of tag 'highway'.
    965         *
    966         * @param osmPrimitive
    967         *            The OSM entity to check.
    968         */
    969         public static String getHighwayValue(OsmPrimitive osmPrimitive) {
    970                 return osmPrimitive != null ? osmPrimitive.get(HIGHWAY_TAG) : null;
    971         }
    972 
    973         /**
    974         * Check if OSM primitive has a tag 'vehicle'.
    975         *
    976         * @param osmPrimitive
    977         *            The OSM entity to check.
    978         */
    979         public static boolean hasVehicleTag(OsmPrimitive osmPrimitive) {
    980                 return osmPrimitive != null ? osmPrimitive.hasKey(VEHICLE_TAG) : false;
    981         }
    982 
    983         /**
    984         * Gets the value of tag 'vehicle'.
    985         *
    986         * @param osmPrimitive
    987         *            The OSM entity to check.
    988         */
    989         public static String getVehicleValue(OsmPrimitive osmPrimitive) {
    990                 return osmPrimitive != null ? osmPrimitive.get(VEHICLE_TAG) : null;
    991         }
    992 
    993         /**
    994         * Check if OSM primitive has a tag 'horse'.
    995         *
    996         * @param osmPrimitive
    997         *            The OSM entity to check.
    998         */
    999         public static boolean hasHorseTag(OsmPrimitive osmPrimitive) {
    1000                 return osmPrimitive != null ? osmPrimitive.hasKey(HORSE_TAG) : false;
    1001         }
    1002 
    1003         /**
    1004         * Gets the value of tag 'horse'.
    1005         *
    1006         * @param osmPrimitive
    1007         *            The OSM entity to check.
    1008         */
    1009         public static String getHorseValue(OsmPrimitive osmPrimitive) {
    1010                 return osmPrimitive != null ? osmPrimitive.get(HORSE_TAG) : null;
    1011         }
    1012 
    1013         /**
    1014         * Check if OSM primitive has a tag 'goods'.
    1015         *
    1016         * @param osmPrimitive
    1017         *            The OSM entity to check.
    1018         */
    1019         public static boolean hasGoodsTag(OsmPrimitive osmPrimitive) {
    1020                 return osmPrimitive != null ? osmPrimitive.hasKey(GOODS_TAG) : false;
    1021         }
    1022 
    1023         /**
    1024         * Gets the value of tag 'goods'.
    1025         *
    1026         * @param osmPrimitive
    1027         *            The OSM entity to check.
    1028         */
    1029         public static String getGoodsValue(OsmPrimitive osmPrimitive) {
    1030                 return osmPrimitive != null ? osmPrimitive.get(GOODS_TAG) : null;
    1031         }
    1032 
    1033         /**
    1034         * Check if OSM primitive has a tag 'frequency'.
    1035         *
    1036         * @param osmPrimitive
    1037         *            The OSM entity to check.
    1038         */
    1039         public static boolean hasFrequencyTag(OsmPrimitive osmPrimitive) {
    1040                 return osmPrimitive != null ? osmPrimitive.hasKey(FREQUENCY_TAG)
    1041                                 : false;
    1042         }
    1043 
    1044         /**
    1045         * Gets the value of tag 'frequency'.
    1046         *
    1047         * @param osmPrimitive
    1048         *            The OSM entity to check.
    1049         */
    1050         public static String getFrequencyValue(OsmPrimitive osmPrimitive) {
    1051                 return osmPrimitive != null ? osmPrimitive.get(FREQUENCY_TAG) : null;
    1052         }
    1053 
    1054         /**
    1055         * Check if OSM primitive has a tag 'man_made'.
    1056         *
    1057         * @param osmPrimitive
    1058         *            The OSM entity to check.
    1059         */
    1060         public static boolean hasManMadeTag(OsmPrimitive osmPrimitive) {
    1061                 return osmPrimitive != null ? osmPrimitive.hasKey(MAN_MADE_TAG) : false;
    1062         }
    1063 
    1064         /**
    1065         * Gets the value of tag 'man_made'.
    1066         *
    1067         * @param osmPrimitive
    1068         *            The OSM entity to check.
    1069         */
    1070         public static String getManMadeValue(OsmPrimitive osmPrimitive) {
    1071                 return osmPrimitive != null ? osmPrimitive.get(MAN_MADE_TAG) : null;
    1072         }
    1073 
    1074         /**
    1075         * Check if OSM primitive has a tag 'addr:housenumber'.
    1076         *
    1077         * @param osmPrimitive
    1078         *            The OSM entity to check.
    1079         */
    1080         public static boolean hasAddrHousenumberTag(OsmPrimitive osmPrimitive) {
    1081                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENUMBER_TAG)
    1082                                 : false;
    1083         }
    1084 
    1085         /**
    1086         * Gets the value of tag 'addr:housenumber'.
    1087         *
    1088         * @param osmPrimitive
    1089         *            The OSM entity to check.
    1090         */
    1091         public static String getAddrHousenumberValue(OsmPrimitive osmPrimitive) {
    1092                 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENUMBER_TAG)
    1093                                 : null;
    1094         }
    1095 
    1096         /**
    1097         * Check if OSM primitive has a tag 'addr:housename'.
    1098         *
    1099         * @param osmPrimitive
    1100         *            The OSM entity to check.
    1101         */
    1102         public static boolean hasAddrHousenameTag(OsmPrimitive osmPrimitive) {
    1103                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENAME_TAG)
    1104                                 : false;
    1105         }
    1106 
    1107         /**
    1108         * Gets the value of tag 'addr:housename'.
    1109         *
    1110         * @param osmPrimitive
    1111         *            The OSM entity to check.
    1112         */
    1113         public static String getAddrHousenameValue(OsmPrimitive osmPrimitive) {
    1114                 return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENAME_TAG)
    1115                                 : null;
    1116         }
    1117 
    1118         /**
    1119         * Check if OSM primitive has a tag 'area'.
    1120         *
    1121         * @param osmPrimitive
    1122         *            The OSM entity to check.
    1123         */
    1124         public static boolean hasAreaTag(OsmPrimitive osmPrimitive) {
    1125                 return osmPrimitive != null ? osmPrimitive.hasKey(AREA_TAG) : false;
    1126         }
    1127 
    1128         /**
    1129         * Gets the value of tag 'area'.
    1130         *
    1131         * @param osmPrimitive
    1132         *            The OSM entity to check.
    1133         */
    1134         public static String getAreaValue(OsmPrimitive osmPrimitive) {
    1135                 return osmPrimitive != null ? osmPrimitive.get(AREA_TAG) : null;
    1136         }
    1137 
    1138         /**
    1139         * Check if OSM primitive has a tag 'building:levels'.
    1140         *
    1141         * @param osmPrimitive
    1142         *            The OSM entity to check.
    1143         */
    1144         public static boolean hasBuildingLevelsTag(OsmPrimitive osmPrimitive) {
    1145                 return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_LEVELS_TAG)
    1146                                 : false;
    1147         }
    1148 
    1149         /**
    1150         * Gets the value of tag 'building:levels'.
    1151         *
    1152         * @param osmPrimitive
    1153         *            The OSM entity to check.
    1154         */
    1155         public static String getBuildingLevelsValue(OsmPrimitive osmPrimitive) {
    1156                 return osmPrimitive != null ? osmPrimitive.get(BUILDING_LEVELS_TAG)
    1157                                 : null;
    1158         }
    1159 
    1160         /**
    1161         * Check if OSM primitive has a tag 'wheelchair'.
    1162         *
    1163         * @param osmPrimitive
    1164         *            The OSM entity to check.
    1165         */
    1166         public static boolean hasWheelchairTag(OsmPrimitive osmPrimitive) {
    1167                 return osmPrimitive != null ? osmPrimitive.hasKey(WHEELCHAIR_TAG)
    1168                                 : false;
    1169         }
    1170 
    1171         /**
    1172         * Gets the value of tag 'wheelchair'.
    1173         *
    1174         * @param osmPrimitive
    1175         *            The OSM entity to check.
    1176         */
    1177         public static String getWheelchairValue(OsmPrimitive osmPrimitive) {
    1178                 return osmPrimitive != null ? osmPrimitive.get(WHEELCHAIR_TAG) : null;
    1179         }
    1180 
    1181         /**
    1182         * Check if OSM primitive has a tag 'name'.
    1183         *
    1184         * @param osmPrimitive
    1185         *            The OSM entity to check.
    1186         */
    1187         public static boolean hasNameTag(OsmPrimitive osmPrimitive) {
    1188                 return osmPrimitive != null ? osmPrimitive.hasKey(NAME_TAG) : false;
    1189         }
    1190 
    1191         /**
    1192         * Gets the value of tag 'name'.
    1193         *
    1194         * @param osmPrimitive
    1195         *            The OSM entity to check.
    1196         */
    1197         public static String getNameValue(OsmPrimitive osmPrimitive) {
    1198                 return osmPrimitive != null ? osmPrimitive.get(NAME_TAG) : null;
    1199         }
    1200 
    1201         /**
    1202         * Check if OSM primitive has a tag 'oneway'.
    1203         *
    1204         * @param osmPrimitive
    1205         *            The OSM entity to check.
    1206         */
    1207         public static boolean hasOnewayTag(OsmPrimitive osmPrimitive) {
    1208                 return osmPrimitive != null ? osmPrimitive.hasKey(ONEWAY_TAG) : false;
    1209         }
    1210 
    1211         /**
    1212         * Gets the value of tag 'oneway'.
    1213         *
    1214         * @param osmPrimitive
    1215         *            The OSM entity to check.
    1216         */
    1217         public static String getOnewayValue(OsmPrimitive osmPrimitive) {
    1218                 return osmPrimitive != null ? osmPrimitive.get(ONEWAY_TAG) : null;
    1219         }
    1220 
    1221         /**
    1222         * Check if OSM primitive has a tag 'FIXME'.
    1223         *
    1224         * @param osmPrimitive
    1225         *            The OSM entity to check.
    1226         */
    1227         public static boolean hasFIXMETag(OsmPrimitive osmPrimitive) {
    1228                 return osmPrimitive != null ? osmPrimitive.hasKey(FIXME_TAG) : false;
    1229         }
    1230 
    1231         /**
    1232         * Gets the value of tag 'FIXME'.
    1233         *
    1234         * @param osmPrimitive
    1235         *            The OSM entity to check.
    1236         */
    1237         public static String getFIXMEValue(OsmPrimitive osmPrimitive) {
    1238                 return osmPrimitive != null ? osmPrimitive.get(FIXME_TAG) : null;
    1239         }
    1240 
    1241         /**
    1242         * Check if OSM primitive has a tag 'capacity'.
    1243         *
    1244         * @param osmPrimitive
    1245         *            The OSM entity to check.
    1246         */
    1247         public static boolean hasCapacityTag(OsmPrimitive osmPrimitive) {
    1248                 return osmPrimitive != null ? osmPrimitive.hasKey(CAPACITY_TAG) : false;
    1249         }
    1250 
    1251         /**
    1252         * Gets the value of tag 'capacity'.
    1253         *
    1254         * @param osmPrimitive
    1255         *            The OSM entity to check.
    1256         */
    1257         public static String getCapacityValue(OsmPrimitive osmPrimitive) {
    1258                 return osmPrimitive != null ? osmPrimitive.get(CAPACITY_TAG) : null;
    1259         }
    1260 
    1261         /**
    1262         * Check if OSM primitive has a tag 'motorcycle'.
    1263         *
    1264         * @param osmPrimitive
    1265         *            The OSM entity to check.
    1266         */
    1267         public static boolean hasMotorcycleTag(OsmPrimitive osmPrimitive) {
    1268                 return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCYCLE_TAG)
    1269                                 : false;
    1270         }
    1271 
    1272         /**
    1273         * Gets the value of tag 'motorcycle'.
    1274         *
    1275         * @param osmPrimitive
    1276         *            The OSM entity to check.
    1277         */
    1278         public static String getMotorcycleValue(OsmPrimitive osmPrimitive) {
    1279                 return osmPrimitive != null ? osmPrimitive.get(MOTORCYCLE_TAG) : null;
    1280         }
    1281 
    1282         /**
    1283         * Check if OSM primitive has a tag 'hgv'.
    1284         *
    1285         * @param osmPrimitive
    1286         *            The OSM entity to check.
    1287         */
    1288         public static boolean hasHgvTag(OsmPrimitive osmPrimitive) {
    1289                 return osmPrimitive != null ? osmPrimitive.hasKey(HGV_TAG) : false;
    1290         }
    1291 
    1292         /**
    1293         * Gets the value of tag 'hgv'.
    1294         *
    1295         * @param osmPrimitive
    1296         *            The OSM entity to check.
    1297         */
    1298         public static String getHgvValue(OsmPrimitive osmPrimitive) {
    1299                 return osmPrimitive != null ? osmPrimitive.get(HGV_TAG) : null;
    1300         }
    1301 
    1302         /**
    1303         * Check if OSM primitive has a tag 'construction'.
    1304         *
    1305         * @param osmPrimitive
    1306         *            The OSM entity to check.
    1307         */
    1308         public static boolean hasConstructionTag(OsmPrimitive osmPrimitive) {
    1309                 return osmPrimitive != null ? osmPrimitive.hasKey(CONSTRUCTION_TAG)
    1310                                 : false;
    1311         }
    1312 
    1313         /**
    1314         * Gets the value of tag 'construction'.
    1315         *
    1316         * @param osmPrimitive
    1317         *            The OSM entity to check.
    1318         */
    1319         public static String getConstructionValue(OsmPrimitive osmPrimitive) {
    1320                 return osmPrimitive != null ? osmPrimitive.get(CONSTRUCTION_TAG) : null;
    1321         }
    1322 
    1323         /**
    1324         * Check if OSM primitive has a tag 'addr:state'.
    1325         *
    1326         * @param osmPrimitive
    1327         *            The OSM entity to check.
    1328         */
    1329         public static boolean hasAddrStateTag(OsmPrimitive osmPrimitive) {
    1330                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STATE_TAG)
    1331                                 : false;
    1332         }
    1333 
    1334         /**
    1335         * Gets the value of tag 'addr:state'.
    1336         *
    1337         * @param osmPrimitive
    1338         *            The OSM entity to check.
    1339         */
    1340         public static String getAddrStateValue(OsmPrimitive osmPrimitive) {
    1341                 return osmPrimitive != null ? osmPrimitive.get(ADDR_STATE_TAG) : null;
    1342         }
    1343 
    1344         /**
    1345         * Check if OSM primitive has a tag 'lanes'.
    1346         *
    1347         * @param osmPrimitive
    1348         *            The OSM entity to check.
    1349         */
    1350         public static boolean hasLanesTag(OsmPrimitive osmPrimitive) {
    1351                 return osmPrimitive != null ? osmPrimitive.hasKey(LANES_TAG) : false;
    1352         }
    1353 
    1354         /**
    1355         * Gets the value of tag 'lanes'.
    1356         *
    1357         * @param osmPrimitive
    1358         *            The OSM entity to check.
    1359         */
    1360         public static String getLanesValue(OsmPrimitive osmPrimitive) {
    1361                 return osmPrimitive != null ? osmPrimitive.get(LANES_TAG) : null;
    1362         }
    1363 
    1364         /**
    1365         * Check if OSM primitive has a tag 'note'.
    1366         *
    1367         * @param osmPrimitive
    1368         *            The OSM entity to check.
    1369         */
    1370         public static boolean hasNoteTag(OsmPrimitive osmPrimitive) {
    1371                 return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_TAG) : false;
    1372         }
    1373 
    1374         /**
    1375         * Gets the value of tag 'note'.
    1376         *
    1377         * @param osmPrimitive
    1378         *            The OSM entity to check.
    1379         */
    1380         public static String getNoteValue(OsmPrimitive osmPrimitive) {
    1381                 return osmPrimitive != null ? osmPrimitive.get(NOTE_TAG) : null;
    1382         }
    1383 
    1384         /**
    1385         * Check if OSM primitive has a tag 'lit'.
    1386         *
    1387         * @param osmPrimitive
    1388         *            The OSM entity to check.
    1389         */
    1390         public static boolean hasLitTag(OsmPrimitive osmPrimitive) {
    1391                 return osmPrimitive != null ? osmPrimitive.hasKey(LIT_TAG) : false;
    1392         }
    1393 
    1394         /**
    1395         * Gets the value of tag 'lit'.
    1396         *
    1397         * @param osmPrimitive
    1398         *            The OSM entity to check.
    1399         */
    1400         public static String getLitValue(OsmPrimitive osmPrimitive) {
    1401                 return osmPrimitive != null ? osmPrimitive.get(LIT_TAG) : null;
    1402         }
    1403 
    1404         /**
    1405         * Check if OSM primitive has a tag 'building'.
    1406         *
    1407         * @param osmPrimitive
    1408         *            The OSM entity to check.
    1409         */
    1410         public static boolean hasBuildingTag(OsmPrimitive osmPrimitive) {
    1411                 return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_TAG) : false;
    1412         }
    1413 
    1414         /**
    1415         * Gets the value of tag 'building'.
    1416         *
    1417         * @param osmPrimitive
    1418         *            The OSM entity to check.
    1419         */
    1420         public static String getBuildingValue(OsmPrimitive osmPrimitive) {
    1421                 return osmPrimitive != null ? osmPrimitive.get(BUILDING_TAG) : null;
    1422         }
    1423 
    1424         /**
    1425         * Check if OSM primitive has a tag 'segregated'.
    1426         *
    1427         * @param osmPrimitive
    1428         *            The OSM entity to check.
    1429         */
    1430         public static boolean hasSegregatedTag(OsmPrimitive osmPrimitive) {
    1431                 return osmPrimitive != null ? osmPrimitive.hasKey(SEGREGATED_TAG)
    1432                                 : false;
    1433         }
    1434 
    1435         /**
    1436         * Gets the value of tag 'segregated'.
    1437         *
    1438         * @param osmPrimitive
    1439         *            The OSM entity to check.
    1440         */
    1441         public static String getSegregatedValue(OsmPrimitive osmPrimitive) {
    1442                 return osmPrimitive != null ? osmPrimitive.get(SEGREGATED_TAG) : null;
    1443         }
    1444 
    1445         /**
    1446         * Check if OSM primitive has a tag 'addr:inclusion'.
    1447         *
    1448         * @param osmPrimitive
    1449         *            The OSM entity to check.
    1450         */
    1451         public static boolean hasAddrInclusionTag(OsmPrimitive osmPrimitive) {
    1452                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_INCLUSION_TAG)
    1453                                 : false;
    1454         }
    1455 
    1456         /**
    1457         * Gets the value of tag 'addr:inclusion'.
    1458         *
    1459         * @param osmPrimitive
    1460         *            The OSM entity to check.
    1461         */
    1462         public static String getAddrInclusionValue(OsmPrimitive osmPrimitive) {
    1463                 return osmPrimitive != null ? osmPrimitive.get(ADDR_INCLUSION_TAG)
    1464                                 : null;
    1465         }
    1466 
    1467         /**
    1468         * Check if OSM primitive has a tag 'layer'.
    1469         *
    1470         * @param osmPrimitive
    1471         *            The OSM entity to check.
    1472         */
    1473         public static boolean hasLayerTag(OsmPrimitive osmPrimitive) {
    1474                 return osmPrimitive != null ? osmPrimitive.hasKey(LAYER_TAG) : false;
    1475         }
    1476 
    1477         /**
    1478         * Gets the value of tag 'layer'.
    1479         *
    1480         * @param osmPrimitive
    1481         *            The OSM entity to check.
    1482         */
    1483         public static String getLayerValue(OsmPrimitive osmPrimitive) {
    1484                 return osmPrimitive != null ? osmPrimitive.get(LAYER_TAG) : null;
    1485         }
    1486 
    1487         /**
    1488         * Check if OSM primitive has a tag 'sport'.
    1489         *
    1490         * @param osmPrimitive
    1491         *            The OSM entity to check.
    1492         */
    1493         public static boolean hasSportTag(OsmPrimitive osmPrimitive) {
    1494                 return osmPrimitive != null ? osmPrimitive.hasKey(SPORT_TAG) : false;
    1495         }
    1496 
    1497         /**
    1498         * Gets the value of tag 'sport'.
    1499         *
    1500         * @param osmPrimitive
    1501         *            The OSM entity to check.
    1502         */
    1503         public static String getSportValue(OsmPrimitive osmPrimitive) {
    1504                 return osmPrimitive != null ? osmPrimitive.get(SPORT_TAG) : null;
    1505         }
    1506 
    1507         /**
    1508         * Check if OSM primitive has a tag 'addr:interpolation'.
    1509         *
    1510         * @param osmPrimitive
    1511         *            The OSM entity to check.
    1512         */
    1513         public static boolean hasAddrInterpolationTag(OsmPrimitive osmPrimitive) {
    1514                 return osmPrimitive != null ? osmPrimitive
    1515                                 .hasKey(ADDR_INTERPOLATION_TAG) : false;
    1516         }
    1517 
    1518         /**
    1519         * Gets the value of tag 'addr:interpolation'.
    1520         *
    1521         * @param osmPrimitive
    1522         *            The OSM entity to check.
    1523         */
    1524         public static String getAddrInterpolationValue(OsmPrimitive osmPrimitive) {
    1525                 return osmPrimitive != null ? osmPrimitive.get(ADDR_INTERPOLATION_TAG)
    1526                                 : null;
    1527         }
    1528 
    1529         /**
    1530         * Check if OSM primitive has a tag 'cutting'.
    1531         *
    1532         * @param osmPrimitive
    1533         *            The OSM entity to check.
    1534         */
    1535         public static boolean hasCuttingTag(OsmPrimitive osmPrimitive) {
    1536                 return osmPrimitive != null ? osmPrimitive.hasKey(CUTTING_TAG) : false;
    1537         }
    1538 
    1539         /**
    1540         * Gets the value of tag 'cutting'.
    1541         *
    1542         * @param osmPrimitive
    1543         *            The OSM entity to check.
    1544         */
    1545         public static String getCuttingValue(OsmPrimitive osmPrimitive) {
    1546                 return osmPrimitive != null ? osmPrimitive.get(CUTTING_TAG) : null;
    1547         }
    1548 
    1549         /**
    1550         * Check if OSM primitive has a tag 'amenity'.
    1551         *
    1552         * @param osmPrimitive
    1553         *            The OSM entity to check.
    1554         */
    1555         public static boolean hasAmenityTag(OsmPrimitive osmPrimitive) {
    1556                 return osmPrimitive != null ? osmPrimitive.hasKey(AMENITY_TAG) : false;
    1557         }
    1558 
    1559         /**
    1560         * Gets the value of tag 'amenity'.
    1561         *
    1562         * @param osmPrimitive
    1563         *            The OSM entity to check.
    1564         */
    1565         public static String getAmenityValue(OsmPrimitive osmPrimitive) {
    1566                 return osmPrimitive != null ? osmPrimitive.get(AMENITY_TAG) : null;
    1567         }
    1568 
    1569         /**
    1570         * Check if OSM primitive has a tag 'access'.
    1571         *
    1572         * @param osmPrimitive
    1573         *            The OSM entity to check.
    1574         */
    1575         public static boolean hasAccessTag(OsmPrimitive osmPrimitive) {
    1576                 return osmPrimitive != null ? osmPrimitive.hasKey(ACCESS_TAG) : false;
    1577         }
    1578 
    1579         /**
    1580         * Gets the value of tag 'access'.
    1581         *
    1582         * @param osmPrimitive
    1583         *            The OSM entity to check.
    1584         */
    1585         public static String getAccessValue(OsmPrimitive osmPrimitive) {
    1586                 return osmPrimitive != null ? osmPrimitive.get(ACCESS_TAG) : null;
    1587         }
    1588 
    1589         /**
    1590         * Check if OSM primitive has a tag 'agricultural'.
    1591         *
    1592         * @param osmPrimitive
    1593         *            The OSM entity to check.
    1594         */
    1595         public static boolean hasAgriculturalTag(OsmPrimitive osmPrimitive) {
    1596                 return osmPrimitive != null ? osmPrimitive.hasKey(AGRICULTURAL_TAG)
    1597                                 : false;
    1598         }
    1599 
    1600         /**
    1601         * Gets the value of tag 'agricultural'.
    1602         *
    1603         * @param osmPrimitive
    1604         *            The OSM entity to check.
    1605         */
    1606         public static String getAgriculturalValue(OsmPrimitive osmPrimitive) {
    1607                 return osmPrimitive != null ? osmPrimitive.get(AGRICULTURAL_TAG) : null;
    1608         }
    1609 
    1610         /**
    1611         * Check if OSM primitive has a tag 'capacity:disabled'.
    1612         *
    1613         * @param osmPrimitive
    1614         *            The OSM entity to check.
    1615         */
    1616         public static boolean hasCapacityDisabledTag(OsmPrimitive osmPrimitive) {
    1617                 return osmPrimitive != null ? osmPrimitive
    1618                                 .hasKey(CAPACITY_DISABLED_TAG) : false;
    1619         }
    1620 
    1621         /**
    1622         * Gets the value of tag 'capacity:disabled'.
    1623         *
    1624         * @param osmPrimitive
    1625         *            The OSM entity to check.
    1626         */
    1627         public static String getCapacityDisabledValue(OsmPrimitive osmPrimitive) {
    1628                 return osmPrimitive != null ? osmPrimitive.get(CAPACITY_DISABLED_TAG)
    1629                                 : null;
    1630         }
    1631 
    1632         /**
    1633         * Check if OSM primitive has a tag 'operator'.
    1634         *
    1635         * @param osmPrimitive
    1636         *            The OSM entity to check.
    1637         */
    1638         public static boolean hasOperatorTag(OsmPrimitive osmPrimitive) {
    1639                 return osmPrimitive != null ? osmPrimitive.hasKey(OPERATOR_TAG) : false;
    1640         }
    1641 
    1642         /**
    1643         * Gets the value of tag 'operator'.
    1644         *
    1645         * @param osmPrimitive
    1646         *            The OSM entity to check.
    1647         */
    1648         public static String getOperatorValue(OsmPrimitive osmPrimitive) {
    1649                 return osmPrimitive != null ? osmPrimitive.get(OPERATOR_TAG) : null;
    1650         }
    1651 
    1652         /**
    1653         * Check if OSM primitive has a tag 'ref'.
    1654         *
    1655         * @param osmPrimitive
    1656         *            The OSM entity to check.
    1657         */
    1658         public static boolean hasRefTag(OsmPrimitive osmPrimitive) {
    1659                 return osmPrimitive != null ? osmPrimitive.hasKey(REF_TAG) : false;
    1660         }
    1661 
    1662         /**
    1663         * Gets the value of tag 'ref'.
    1664         *
    1665         * @param osmPrimitive
    1666         *            The OSM entity to check.
    1667         */
    1668         public static String getRefValue(OsmPrimitive osmPrimitive) {
    1669                 return osmPrimitive != null ? osmPrimitive.get(REF_TAG) : null;
    1670         }
    1671 
    1672         /**
    1673         * Check if OSM primitive has a tag 'noexit'.
    1674         *
    1675         * @param osmPrimitive
    1676         *            The OSM entity to check.
    1677         */
    1678         public static boolean hasNoexitTag(OsmPrimitive osmPrimitive) {
    1679                 return osmPrimitive != null ? osmPrimitive.hasKey(NOEXIT_TAG) : false;
    1680         }
    1681 
    1682         /**
    1683         * Gets the value of tag 'noexit'.
    1684         *
    1685         * @param osmPrimitive
    1686         *            The OSM entity to check.
    1687         */
    1688         public static String getNoexitValue(OsmPrimitive osmPrimitive) {
    1689                 return osmPrimitive != null ? osmPrimitive.get(NOEXIT_TAG) : null;
    1690         }
    1691 
    1692         /**
    1693         * Check if OSM primitive has a tag 'admin_level'.
    1694         *
    1695         * @param osmPrimitive
    1696         *            The OSM entity to check.
    1697         */
    1698         public static boolean hasAdminLevelTag(OsmPrimitive osmPrimitive) {
    1699                 return osmPrimitive != null ? osmPrimitive.hasKey(ADMIN_LEVEL_TAG)
    1700                                 : false;
    1701         }
    1702 
    1703         /**
    1704         * Gets the value of tag 'admin_level'.
    1705         *
    1706         * @param osmPrimitive
    1707         *            The OSM entity to check.
    1708         */
    1709         public static String getAdminLevelValue(OsmPrimitive osmPrimitive) {
    1710                 return osmPrimitive != null ? osmPrimitive.get(ADMIN_LEVEL_TAG) : null;
    1711         }
    1712 
    1713         /**
    1714         * Check if OSM primitive has a tag 'source'.
    1715         *
    1716         * @param osmPrimitive
    1717         *            The OSM entity to check.
    1718         */
    1719         public static boolean hasSourceTag(OsmPrimitive osmPrimitive) {
    1720                 return osmPrimitive != null ? osmPrimitive.hasKey(SOURCE_TAG) : false;
    1721         }
    1722 
    1723         /**
    1724         * Gets the value of tag 'source'.
    1725         *
    1726         * @param osmPrimitive
    1727         *            The OSM entity to check.
    1728         */
    1729         public static String getSourceValue(OsmPrimitive osmPrimitive) {
    1730                 return osmPrimitive != null ? osmPrimitive.get(SOURCE_TAG) : null;
    1731         }
    1732 
    1733         /**
    1734         * Check if OSM primitive has a tag 'tracktype'.
    1735         *
    1736         * @param osmPrimitive
    1737         *            The OSM entity to check.
    1738         */
    1739         public static boolean hasTracktypeTag(OsmPrimitive osmPrimitive) {
    1740                 return osmPrimitive != null ? osmPrimitive.hasKey(TRACKTYPE_TAG)
    1741                                 : false;
    1742         }
    1743 
    1744         /**
    1745         * Gets the value of tag 'tracktype'.
    1746         *
    1747         * @param osmPrimitive
    1748         *            The OSM entity to check.
    1749         */
    1750         public static String getTracktypeValue(OsmPrimitive osmPrimitive) {
    1751                 return osmPrimitive != null ? osmPrimitive.get(TRACKTYPE_TAG) : null;
    1752         }
    1753 
    1754         /**
    1755         * Check if OSM primitive has a tag 'addr:country'.
    1756         *
    1757         * @param osmPrimitive
    1758         *            The OSM entity to check.
    1759         */
    1760         public static boolean hasAddrCountryTag(OsmPrimitive osmPrimitive) {
    1761                 return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_COUNTRY_TAG)
    1762                                 : false;
    1763         }
    1764 
    1765         /**
    1766         * Gets the value of tag 'addr:country'.
    1767         *
    1768         * @param osmPrimitive
    1769         *            The OSM entity to check.
    1770         */
    1771         public static String getAddrCountryValue(OsmPrimitive osmPrimitive) {
    1772                 return osmPrimitive != null ? osmPrimitive.get(ADDR_COUNTRY_TAG) : null;
    1773         }
    1774 
    1775         /**
    1776         * Check if OSM primitive has a tag 'route'.
    1777         *
    1778         * @param osmPrimitive
    1779         *            The OSM entity to check.
    1780         */
    1781         public static boolean hasRouteTag(OsmPrimitive osmPrimitive) {
    1782                 return osmPrimitive != null ? osmPrimitive.hasKey(ROUTE_TAG) : false;
    1783         }
    1784 
    1785         /**
    1786         * Gets the value of tag 'route'.
    1787         *
    1788         * @param osmPrimitive
    1789         *            The OSM entity to check.
    1790         */
    1791         public static String getRouteValue(OsmPrimitive osmPrimitive) {
    1792                 return osmPrimitive != null ? osmPrimitive.get(ROUTE_TAG) : null;
    1793         }
    1794 
    1795         /**
    1796         * Check if OSM primitive has a tag 'cables'.
    1797         *
    1798         * @param osmPrimitive
    1799         *            The OSM entity to check.
    1800         */
    1801         public static boolean hasCablesTag(OsmPrimitive osmPrimitive) {
    1802                 return osmPrimitive != null ? osmPrimitive.hasKey(CABLES_TAG) : false;
    1803         }
    1804 
    1805         /**
    1806         * Gets the value of tag 'cables'.
    1807         *
    1808         * @param osmPrimitive
    1809         *            The OSM entity to check.
    1810         */
    1811         public static String getCablesValue(OsmPrimitive osmPrimitive) {
    1812                 return osmPrimitive != null ? osmPrimitive.get(CABLES_TAG) : null;
    1813         }
    1814 
    1815         /**
    1816         * Check if OSM primitive has a tag 'service'.
    1817         *
    1818         * @param osmPrimitive
    1819         *            The OSM entity to check.
    1820         */
    1821         public static boolean hasServiceTag(OsmPrimitive osmPrimitive) {
    1822                 return osmPrimitive != null ? osmPrimitive.hasKey(SERVICE_TAG) : false;
    1823         }
    1824 
    1825         /**
    1826         * Gets the value of tag 'service'.
    1827         *
    1828         * @param osmPrimitive
    1829         *            The OSM entity to check.
    1830         */
    1831         public static String getServiceValue(OsmPrimitive osmPrimitive) {
    1832                 return osmPrimitive != null ? osmPrimitive.get(SERVICE_TAG) : null;
    1833         }
    1834 
    1835         /**
    1836         * Check if OSM primitive has a tag 'motorcar'.
    1837         *
    1838         * @param osmPrimitive
    1839         *            The OSM entity to check.
    1840         */
    1841         public static boolean hasMotorcarTag(OsmPrimitive osmPrimitive) {
    1842                 return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCAR_TAG) : false;
    1843         }
    1844 
    1845         /**
    1846         * Gets the value of tag 'motorcar'.
    1847         *
    1848         * @param osmPrimitive
    1849         *            The OSM entity to check.
    1850         */
    1851         public static String getMotorcarValue(OsmPrimitive osmPrimitive) {
    1852                 return osmPrimitive != null ? osmPrimitive.get(MOTORCAR_TAG) : null;
    1853         }
    1854 
    1855         /**
    1856         * Check if OSM primitive has a tag 'whitewater'.
    1857         *
    1858         * @param osmPrimitive
    1859         *            The OSM entity to check.
    1860         */
    1861         public static boolean hasWhitewaterTag(OsmPrimitive osmPrimitive) {
    1862                 return osmPrimitive != null ? osmPrimitive.hasKey(WHITEWATER_TAG)
    1863                                 : false;
    1864         }
    1865 
    1866         /**
    1867         * Gets the value of tag 'whitewater'.
    1868         *
    1869         * @param osmPrimitive
    1870         *            The OSM entity to check.
    1871         */
    1872         public static String getWhitewaterValue(OsmPrimitive osmPrimitive) {
    1873                 return osmPrimitive != null ? osmPrimitive.get(WHITEWATER_TAG) : null;
    1874         }
    1875 
    1876         /**
    1877         * Check if OSM primitive has a tag 'embankment'.
    1878         *
    1879         * @param osmPrimitive
    1880         *            The OSM entity to check.
    1881         */
    1882         public static boolean hasEmbankmentTag(OsmPrimitive osmPrimitive) {
    1883                 return osmPrimitive != null ? osmPrimitive.hasKey(EMBANKMENT_TAG)
    1884                                 : false;
    1885         }
    1886 
    1887         /**
    1888         * Gets the value of tag 'embankment'.
    1889         *
    1890         * @param osmPrimitive
    1891         *            The OSM entity to check.
    1892         */
    1893         public static String getEmbankmentValue(OsmPrimitive osmPrimitive) {
    1894                 return osmPrimitive != null ? osmPrimitive.get(EMBANKMENT_TAG) : null;
    1895         }
    1896 
    1897         /**
    1898         * Checks if the given street supporting housenumbers. Usually motor ways and primary roads have
    1899         * no addresses, also no paths or tracks.
    1900         *
    1901         * @param w the w
    1902         * @return true, if is street supporting housenumbers
    1903         */
    1904         public static boolean isStreetSupportingHousenumbers(Way w) {
    1905                 if (w == null) return false;
    1906                 if (!hasHighwayTag(w)) {
    1907                         return false;
    1908                 }
    1909 
    1910                 // TODO: Should be configurable
    1911 
    1912                 /* Allow everything until this can be configured */
    1913                 return true;
    1914                 /*
    1915                 String hwType = getHighwayValue(w);
    1916                 return  !(TagUtils.HIGHWAY_MOTORWAY_LINK_VALUE.equals(hwType) ||
    1917                                 TagUtils.HIGHWAY_MOTORWAY_VALUE.equals(hwType) ||
    1918                                 TagUtils.HIGHWAY_FOOTWAY_VALUE.equals(hwType) ||
    1919                                 TagUtils.HIGHWAY_TRACK_VALUE.equals(hwType)
    1920                                 );*/
    1921         }
    1922 
    1923         // Relation support
    1924 
    1925         /**
    1926         * Check if OSM relation is a 'associatedStreet' relation.
    1927         *
    1928         * @param osmPrimitive
    1929         *            The OSM entity to check.
    1930         */
    1931         public static boolean isAssociatedStreetRelation(Relation rel) {
    1932                 return rel != null &&
    1933                         rel.hasKey(RELATION_TYPE) &&
    1934                         ASSOCIATEDSTREET_RELATION_TYPE.equals(rel.get(RELATION_TYPE));
    1935         }
    1936 
    1937         /**
    1938         * Checks if given relation member has role "street".
    1939         *
    1940         * @param relMember the relation member
    1941         * @return true, if is street member
    1942         */
    1943         public static boolean isStreetMember(RelationMember relMember) {
    1944                 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole());
    1945         }
    1946 
    1947         /**
    1948         * Checks if given relation member has role "house".
    1949         *
    1950         * @param relMember the relation member
    1951         * @return true, if is street member
    1952         */
    1953         public static boolean isHouseMember(RelationMember relMember) {
    1954                 return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole());
    1955         }
    1956 
    1957         /**
    1958         * Checks if "addr:state" tag is required.
    1959         *
    1960         * @return true, if is state required
    1961         */
    1962         public static boolean isStateRequired() {
    1963                 String loc = OsmUtils.getLocale();
    1964 
    1965                 for (int i = 0; i < COUNTRIES_REQUIRE_STATE.length; i++) {
    1966                         if (COUNTRIES_REQUIRE_STATE[i].equals(loc)) {
    1967                                 return true;
    1968                         }
    1969                 }
    1970 
    1971                 return false;
    1972         }
    1973 
    1974         public static final String PARKING_TAG = "parking";
    1975         public static final String SHOP_TAG = "shop";
    1976         public static final String CRAFT_TAG = "craft";
    1977         public static final String SURFACE_TAG = "surface";
    1978         public static final String CUISINE_TAG = "cuisine";
    1979         public static final String WOOD_TAG = "wood";
    1980         public static final String FOOT_TAG = "foot";
    1981         public static final String NAME_DE_TAG = "name:de";
    1982         public static final String NAT_REF_TAG = "nat_ref";
    1983         public static final String NOTE_DE_TAG = "note:de";
    1984         public static final String ADDR_STREET_TAG = "addr:street";
    1985         public static final String TYPE_TAG = "type";
    1986         public static final String ADDR_CITY_TAG = "addr:city";
    1987         public static final String BOUNDARY_TAG = "boundary";
    1988         public static final String SMOOTHNESS_TAG = "smoothness";
    1989         public static final String OPENING_HOURS_TAG = "opening_hours";
    1990         public static final String BICYCLE_TAG = "bicycle";
    1991         public static final String RELIGION_TAG = "religion";
    1992         public static final String BARRIER_TAG = "barrier";
    1993         public static final String POWER_TAG = "power";
    1994         public static final String LANDUSE_TAG = "landuse";
    1995         public static final String FIREPLACE_TAG = "fireplace";
    1996         public static final String INT_REF_TAG = "int_ref";
    1997         public static final String WHITEWATER_SECTION_GRADE_TAG = "whitewater:section_grade";
    1998         public static final String DENOMINATION_TAG = "denomination";
    1999         public static final String ADDR_POSTCODE_TAG = "addr:postcode";
    2000         public static final String WIRES_TAG = "wires";
    2001         public static final String LOC_REF_TAG = "loc_ref";
    2002         public static final String WIDTH_TAG = "width";
    2003         public static final String TOURISM_TAG = "tourism";
    2004         public static final String LEISURE_TAG = "leisure";
    2005         public static final String ELECTRIFIED_TAG = "electrified";
    2006         public static final String JUNCTION_TAG = "junction";
    2007         public static final String RAILWAY_TAG = "railway";
    2008         public static final String VOLTAGE_TAG = "voltage";
    2009         public static final String BRIDGE_TAG = "bridge";
    2010         public static final String MOTOR_VEHICLE_TAG = "motor_vehicle";
    2011         public static final String COMMENT_TAG = "comment";
    2012         public static final String MAXSPEED_TAG = "maxspeed";
    2013         public static final String NATURAL_TAG = "natural";
    2014         public static final String BUILDING_HEIGHT_TAG = "building:height";
    2015         public static final String SAC_SCALE_TAG = "sac_scale";
    2016         public static final String TUNNEL_TAG = "tunnel";
    2017         public static final String WATERWAY_TAG = "waterway";
    2018         public static final String TRAIL_VISIBILITY_TAG = "trail_visibility";
    2019         public static final String HIGHWAY_TAG = "highway";
    2020         public static final String VEHICLE_TAG = "vehicle";
    2021         public static final String HORSE_TAG = "horse";
    2022         public static final String GOODS_TAG = "goods";
    2023         public static final String FREQUENCY_TAG = "frequency";
    2024         public static final String MAN_MADE_TAG = "man_made";
    2025         public static final String ADDR_HOUSENUMBER_TAG = "addr:housenumber";
    2026         public static final String AREA_TAG = "area";
    2027         public static final String BUILDING_LEVELS_TAG = "building:levels";
    2028         public static final String WHEELCHAIR_TAG = "wheelchair";
    2029         public static final String NAME_TAG = "name";
    2030         public static final String ONEWAY_TAG = "oneway";
    2031         public static final String FIXME_TAG = "FIXME";
    2032         public static final String CAPACITY_TAG = "capacity";
    2033         public static final String MOTORCYCLE_TAG = "motorcycle";
    2034         public static final String HGV_TAG = "hgv";
    2035         public static final String CONSTRUCTION_TAG = "construction";
    2036         public static final String ADDR_STATE_TAG = "addr:state";
    2037         public static final String LANES_TAG = "lanes";
    2038         public static final String NOTE_TAG = "note";
    2039         public static final String LIT_TAG = "lit";
    2040         public static final String BUILDING_TAG = "building";
    2041         public static final String SEGREGATED_TAG = "segregated";
    2042         public static final String ADDR_INCLUSION_TAG = "addr:inclusion";
    2043         public static final String LAYER_TAG = "layer";
    2044         public static final String SPORT_TAG = "sport";
    2045         public static final String ADDR_INTERPOLATION_TAG = "addr:interpolation";
    2046         public static final String CUTTING_TAG = "cutting";
    2047         public static final String AMENITY_TAG = "amenity";
    2048         public static final String ACCESS_TAG = "access";
    2049         public static final String AGRICULTURAL_TAG = "agricultural";
    2050         public static final String CAPACITY_DISABLED_TAG = "capacity:disabled";
    2051         public static final String OPERATOR_TAG = "operator";
    2052         public static final String REF_TAG = "ref";
    2053         public static final String NOEXIT_TAG = "noexit";
    2054         public static final String ADMIN_LEVEL_TAG = "admin_level";
    2055         public static final String SOURCE_TAG = "source";
    2056         public static final String TRACKTYPE_TAG = "tracktype";
    2057         public static final String ADDR_COUNTRY_TAG = "addr:country";
    2058         public static final String ROUTE_TAG = "route";
    2059         public static final String CABLES_TAG = "cables";
    2060         public static final String SERVICE_TAG = "service";
    2061         public static final String MOTORCAR_TAG = "motorcar";
    2062         public static final String WHITEWATER_TAG = "whitewater";
    2063         public static final String EMBANKMENT_TAG = "embankment";
    2064         public static final String ADDR_HOUSENAME_TAG = "addr:housename";
    2065 
    2066         /* Highway types */
    2067         public static final String HIGHWAY_CYCLEWAY_VALUE = "cycleway";
    2068         public static final String HIGHWAY_FOOTWAY_VALUE = "footway";
    2069         public static final String HIGHWAY_MOTORWAY_LINK_VALUE = "motorway_link";
    2070         public static final String HIGHWAY_MOTORWAY_VALUE = "motorway";
    2071         public static final String HIGHWAY_PATH_VALUE = "path";
    2072         public static final String HIGHWAY_RESIDENTIAL_VALUE = "residential";
    2073         public static final String HIGHWAY_LIVING_STREET_VALUE = "living_street";
    2074         public static final String HIGHWAY_ROAD_VALUE = "road";
    2075         public static final String HIGHWAY_SECONDARY_VALUE = "secondary";
    2076         public static final String HIGHWAY_SERVICE_VALUE = "service";
    2077         public static final String HIGHWAY_STEPS_VALUE = "steps";
    2078         public static final String HIGHWAY_TERTIARY_VALUE = "tertiary";
    2079         public static final String HIGHWAY_TRACK_VALUE = "track";
    2080         public static final String HIGHWAY_TRUNK_LINK_VALUE = "trunk_link";
    2081         public static final String HIGHWAY_TRUNK_VALUE = "trunk";
    2082         public static final String HIGHWAY_UNCLASSIFIED_VALUE = "unclassified";
    2083 
    2084         /* Relation keys */
    2085 
    2086         // Associated street: See http://wiki.openstreetmap.org/wiki/Proposed_features/De:Hausnummern
    2087         public static final String RELATION_TYPE = "type";
    2088         public static final String ASSOCIATEDSTREET_RELATION_TYPE = "associatedStreet";
    2089         public static final String STREET_RELATION_ROLE = "street";
    2090         public static final String HOUSE_RELATION_ROLE = "house";
     17    private static String COUNTRIES_REQUIRE_STATE[] = {
     18        "en_US",    /* USA */
     19        "en_AU" /* Australia */
     20    };
     21
     22    /**
     23    * Checks if the given OSM object has a (non-empty) value for the given tag.
     24    *
     25    * @param osm the osm object to inspect.
     26    * @param tag the tag to look for.
     27    * @return true, if osm object has a non-empty value for this tag
     28    */
     29    public static boolean hasTag(OsmPrimitive osm, String tag) {
     30        return osm != null && !StringUtils.isNullOrEmpty(osm.get(tag));
     31    }
     32
     33    /**
     34    * Checks if the given OSM primitive is an address node.
     35    * @return
     36    */
     37    public static boolean isAddress(OsmPrimitive osmObject) {
     38        return  TagUtils.hasAddrCityTag(osmObject) || TagUtils.hasAddrCountryTag(osmObject) ||
     39                TagUtils.hasAddrHousenumberTag(osmObject) || TagUtils.hasAddrPostcodeTag(osmObject) ||
     40                TagUtils.hasAddrStateTag(osmObject) || TagUtils.hasAddrStreetTag(osmObject);
     41    }
     42
     43    /**
     44    * Check if OSM primitive has a tag 'parking'.
     45    *
     46    * @param osmPrimitive
     47    *            The OSM entity to check.
     48    */
     49    public static boolean hasParkingTag(OsmPrimitive osmPrimitive) {
     50        return osmPrimitive != null ? osmPrimitive.hasKey(PARKING_TAG) : false;
     51    }
     52
     53    /**
     54    * Gets the value of tag 'parking'.
     55    *
     56    * @param osmPrimitive
     57    *            The OSM entity to check.
     58    */
     59    public static String getParkingValue(OsmPrimitive osmPrimitive) {
     60        return osmPrimitive != null ? osmPrimitive.get(PARKING_TAG) : null;
     61    }
     62
     63    /**
     64    * Check if OSM primitive has a tag 'shop'.
     65    *
     66    * @param osmPrimitive
     67    *            The OSM entity to check.
     68    */
     69    public static boolean hasShopTag(OsmPrimitive osmPrimitive) {
     70        return osmPrimitive != null ? osmPrimitive.hasKey(SHOP_TAG) : false;
     71    }
     72
     73    /**
     74    * Gets the value of tag 'shop'.
     75    *
     76    * @param osmPrimitive
     77    *            The OSM entity to check.
     78    */
     79    public static String getShopValue(OsmPrimitive osmPrimitive) {
     80        return osmPrimitive != null ? osmPrimitive.get(SHOP_TAG) : null;
     81    }
     82
     83    /**
     84    * Check if OSM primitive has a tag 'craft'.
     85    *
     86    * @param osmPrimitive
     87    *            The OSM entity to check.
     88    */
     89    public static boolean hasCraftTag(OsmPrimitive osmPrimitive) {
     90        return osmPrimitive != null ? osmPrimitive.hasKey(CRAFT_TAG) : false;
     91    }
     92
     93    /**
     94    * Gets the value of tag 'craft'.
     95    *
     96    * @param osmPrimitive
     97    *            The OSM entity to check.
     98    */
     99    public static String getCraftValue(OsmPrimitive osmPrimitive) {
     100        return osmPrimitive != null ? osmPrimitive.get(CRAFT_TAG) : null;
     101    }
     102
     103    /**
     104    * Check if OSM primitive has a tag 'surface'.
     105    *
     106    * @param osmPrimitive
     107    *            The OSM entity to check.
     108    */
     109    public static boolean hasSurfaceTag(OsmPrimitive osmPrimitive) {
     110        return osmPrimitive != null ? osmPrimitive.hasKey(SURFACE_TAG) : false;
     111    }
     112
     113    /**
     114    * Gets the value of tag 'surface'.
     115    *
     116    * @param osmPrimitive
     117    *            The OSM entity to check.
     118    */
     119    public static String getSurfaceValue(OsmPrimitive osmPrimitive) {
     120        return osmPrimitive != null ? osmPrimitive.get(SURFACE_TAG) : null;
     121    }
     122
     123    /**
     124    * Check if OSM primitive has a tag 'cuisine'.
     125    *
     126    * @param osmPrimitive
     127    *            The OSM entity to check.
     128    */
     129    public static boolean hasCuisineTag(OsmPrimitive osmPrimitive) {
     130        return osmPrimitive != null ? osmPrimitive.hasKey(CUISINE_TAG) : false;
     131    }
     132
     133    /**
     134    * Gets the value of tag 'cuisine'.
     135    *
     136    * @param osmPrimitive
     137    *            The OSM entity to check.
     138    */
     139    public static String getCuisineValue(OsmPrimitive osmPrimitive) {
     140        return osmPrimitive != null ? osmPrimitive.get(CUISINE_TAG) : null;
     141    }
     142
     143    /**
     144    * Check if OSM primitive has a tag 'wood'.
     145    *
     146    * @param osmPrimitive
     147    *            The OSM entity to check.
     148    */
     149    public static boolean hasWoodTag(OsmPrimitive osmPrimitive) {
     150        return osmPrimitive != null ? osmPrimitive.hasKey(WOOD_TAG) : false;
     151    }
     152
     153    /**
     154    * Gets the value of tag 'wood'.
     155    *
     156    * @param osmPrimitive
     157    *            The OSM entity to check.
     158    */
     159    public static String getWoodValue(OsmPrimitive osmPrimitive) {
     160        return osmPrimitive != null ? osmPrimitive.get(WOOD_TAG) : null;
     161    }
     162
     163    /**
     164    * Check if OSM primitive has a tag 'foot'.
     165    *
     166    * @param osmPrimitive
     167    *            The OSM entity to check.
     168    */
     169    public static boolean hasFootTag(OsmPrimitive osmPrimitive) {
     170        return osmPrimitive != null ? osmPrimitive.hasKey(FOOT_TAG) : false;
     171    }
     172
     173    /**
     174    * Gets the value of tag 'foot'.
     175    *
     176    * @param osmPrimitive
     177    *            The OSM entity to check.
     178    */
     179    public static String getFootValue(OsmPrimitive osmPrimitive) {
     180        return osmPrimitive != null ? osmPrimitive.get(FOOT_TAG) : null;
     181    }
     182
     183    /**
     184    * Check if OSM primitive has a tag 'name:de'.
     185    *
     186    * @param osmPrimitive
     187    *            The OSM entity to check.
     188    */
     189    public static boolean hasNameDeTag(OsmPrimitive osmPrimitive) {
     190        return osmPrimitive != null ? osmPrimitive.hasKey(NAME_DE_TAG) : false;
     191    }
     192
     193    /**
     194    * Gets the value of tag 'name:de'.
     195    *
     196    * @param osmPrimitive
     197    *            The OSM entity to check.
     198    */
     199    public static String getNameDeValue(OsmPrimitive osmPrimitive) {
     200        return osmPrimitive != null ? osmPrimitive.get(NAME_DE_TAG) : null;
     201    }
     202
     203    /**
     204    * Check if OSM primitive has a tag 'nat_ref'.
     205    *
     206    * @param osmPrimitive
     207    *            The OSM entity to check.
     208    */
     209    public static boolean hasNatRefTag(OsmPrimitive osmPrimitive) {
     210        return osmPrimitive != null ? osmPrimitive.hasKey(NAT_REF_TAG) : false;
     211    }
     212
     213    /**
     214    * Gets the value of tag 'nat_ref'.
     215    *
     216    * @param osmPrimitive
     217    *            The OSM entity to check.
     218    */
     219    public static String getNatRefValue(OsmPrimitive osmPrimitive) {
     220        return osmPrimitive != null ? osmPrimitive.get(NAT_REF_TAG) : null;
     221    }
     222
     223    /**
     224    * Check if OSM primitive has a tag 'note:de'.
     225    *
     226    * @param osmPrimitive
     227    *            The OSM entity to check.
     228    */
     229    public static boolean hasNoteDeTag(OsmPrimitive osmPrimitive) {
     230        return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_DE_TAG) : false;
     231    }
     232
     233    /**
     234    * Gets the value of tag 'note:de'.
     235    *
     236    * @param osmPrimitive
     237    *            The OSM entity to check.
     238    */
     239    public static String getNoteDeValue(OsmPrimitive osmPrimitive) {
     240        return osmPrimitive != null ? osmPrimitive.get(NOTE_DE_TAG) : null;
     241    }
     242
     243    /**
     244    * Check if OSM primitive has a tag 'addr:street'.
     245    *
     246    * @param osmPrimitive
     247    *            The OSM entity to check.
     248    */
     249    public static boolean hasAddrStreetTag(OsmPrimitive osmPrimitive) {
     250        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STREET_TAG)
     251                : false;
     252    }
     253
     254    /**
     255    * Gets the value of tag 'addr:street'.
     256    *
     257    * @param osmPrimitive
     258    *            The OSM entity to check.
     259    */
     260    public static String getAddrStreetValue(OsmPrimitive osmPrimitive) {
     261        return osmPrimitive != null ? osmPrimitive.get(ADDR_STREET_TAG) : null;
     262    }
     263
     264    /**
     265    * Check if OSM primitive has a tag 'type'.
     266    *
     267    * @param osmPrimitive
     268    *            The OSM entity to check.
     269    */
     270    public static boolean hasTypeTag(OsmPrimitive osmPrimitive) {
     271        return osmPrimitive != null ? osmPrimitive.hasKey(TYPE_TAG) : false;
     272    }
     273
     274    /**
     275    * Gets the value of tag 'type'.
     276    *
     277    * @param osmPrimitive
     278    *            The OSM entity to check.
     279    */
     280    public static String getTypeValue(OsmPrimitive osmPrimitive) {
     281        return osmPrimitive != null ? osmPrimitive.get(TYPE_TAG) : null;
     282    }
     283
     284    /**
     285    * Check if OSM primitive has a tag 'addr:city'.
     286    *
     287    * @param osmPrimitive
     288    *            The OSM entity to check.
     289    */
     290    public static boolean hasAddrCityTag(OsmPrimitive osmPrimitive) {
     291        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_CITY_TAG)
     292                : false;
     293    }
     294
     295    /**
     296    * Gets the value of tag 'addr:city'.
     297    *
     298    * @param osmPrimitive
     299    *            The OSM entity to check.
     300    */
     301    public static String getAddrCityValue(OsmPrimitive osmPrimitive) {
     302        return osmPrimitive != null ? osmPrimitive.get(ADDR_CITY_TAG) : null;
     303    }
     304
     305    /**
     306    * Check if OSM primitive has a tag 'boundary'.
     307    *
     308    * @param osmPrimitive
     309    *            The OSM entity to check.
     310    */
     311    public static boolean hasBoundaryTag(OsmPrimitive osmPrimitive) {
     312        return osmPrimitive != null ? osmPrimitive.hasKey(BOUNDARY_TAG) : false;
     313    }
     314
     315    /**
     316    * Gets the value of tag 'boundary'.
     317    *
     318    * @param osmPrimitive
     319    *            The OSM entity to check.
     320    */
     321    public static String getBoundaryValue(OsmPrimitive osmPrimitive) {
     322        return osmPrimitive != null ? osmPrimitive.get(BOUNDARY_TAG) : null;
     323    }
     324
     325    /**
     326    * Check if OSM primitive has a tag 'smoothness'.
     327    *
     328    * @param osmPrimitive
     329    *            The OSM entity to check.
     330    */
     331    public static boolean hasSmoothnessTag(OsmPrimitive osmPrimitive) {
     332        return osmPrimitive != null ? osmPrimitive.hasKey(SMOOTHNESS_TAG)
     333                : false;
     334    }
     335
     336    /**
     337    * Gets the value of tag 'smoothness'.
     338    *
     339    * @param osmPrimitive
     340    *            The OSM entity to check.
     341    */
     342    public static String getSmoothnessValue(OsmPrimitive osmPrimitive) {
     343        return osmPrimitive != null ? osmPrimitive.get(SMOOTHNESS_TAG) : null;
     344    }
     345
     346    /**
     347    * Check if OSM primitive has a tag 'opening_hours'.
     348    *
     349    * @param osmPrimitive
     350    *            The OSM entity to check.
     351    */
     352    public static boolean hasOpeningHoursTag(OsmPrimitive osmPrimitive) {
     353        return osmPrimitive != null ? osmPrimitive.hasKey(OPENING_HOURS_TAG)
     354                : false;
     355    }
     356
     357    /**
     358    * Gets the value of tag 'opening_hours'.
     359    *
     360    * @param osmPrimitive
     361    *            The OSM entity to check.
     362    */
     363    public static String getOpeningHoursValue(OsmPrimitive osmPrimitive) {
     364        return osmPrimitive != null ? osmPrimitive.get(OPENING_HOURS_TAG)
     365                : null;
     366    }
     367
     368    /**
     369    * Check if OSM primitive has a tag 'bicycle'.
     370    *
     371    * @param osmPrimitive
     372    *            The OSM entity to check.
     373    */
     374    public static boolean hasBicycleTag(OsmPrimitive osmPrimitive) {
     375        return osmPrimitive != null ? osmPrimitive.hasKey(BICYCLE_TAG) : false;
     376    }
     377
     378    /**
     379    * Gets the value of tag 'bicycle'.
     380    *
     381    * @param osmPrimitive
     382    *            The OSM entity to check.
     383    */
     384    public static String getBicycleValue(OsmPrimitive osmPrimitive) {
     385        return osmPrimitive != null ? osmPrimitive.get(BICYCLE_TAG) : null;
     386    }
     387
     388    /**
     389    * Check if OSM primitive has a tag 'religion'.
     390    *
     391    * @param osmPrimitive
     392    *            The OSM entity to check.
     393    */
     394    public static boolean hasReligionTag(OsmPrimitive osmPrimitive) {
     395        return osmPrimitive != null ? osmPrimitive.hasKey(RELIGION_TAG) : false;
     396    }
     397
     398    /**
     399    * Gets the value of tag 'religion'.
     400    *
     401    * @param osmPrimitive
     402    *            The OSM entity to check.
     403    */
     404    public static String getReligionValue(OsmPrimitive osmPrimitive) {
     405        return osmPrimitive != null ? osmPrimitive.get(RELIGION_TAG) : null;
     406    }
     407
     408    /**
     409    * Check if OSM primitive has a tag 'barrier'.
     410    *
     411    * @param osmPrimitive
     412    *            The OSM entity to check.
     413    */
     414    public static boolean hasBarrierTag(OsmPrimitive osmPrimitive) {
     415        return osmPrimitive != null ? osmPrimitive.hasKey(BARRIER_TAG) : false;
     416    }
     417
     418    /**
     419    * Gets the value of tag 'barrier'.
     420    *
     421    * @param osmPrimitive
     422    *            The OSM entity to check.
     423    */
     424    public static String getBarrierValue(OsmPrimitive osmPrimitive) {
     425        return osmPrimitive != null ? osmPrimitive.get(BARRIER_TAG) : null;
     426    }
     427
     428    /**
     429    * Check if OSM primitive has a tag 'power'.
     430    *
     431    * @param osmPrimitive
     432    *            The OSM entity to check.
     433    */
     434    public static boolean hasPowerTag(OsmPrimitive osmPrimitive) {
     435        return osmPrimitive != null ? osmPrimitive.hasKey(POWER_TAG) : false;
     436    }
     437
     438    /**
     439    * Gets the value of tag 'power'.
     440    *
     441    * @param osmPrimitive
     442    *            The OSM entity to check.
     443    */
     444    public static String getPowerValue(OsmPrimitive osmPrimitive) {
     445        return osmPrimitive != null ? osmPrimitive.get(POWER_TAG) : null;
     446    }
     447
     448    /**
     449    * Check if OSM primitive has a tag 'landuse'.
     450    *
     451    * @param osmPrimitive
     452    *            The OSM entity to check.
     453    */
     454    public static boolean hasLanduseTag(OsmPrimitive osmPrimitive) {
     455        return osmPrimitive != null ? osmPrimitive.hasKey(LANDUSE_TAG) : false;
     456    }
     457
     458    /**
     459    * Gets the value of tag 'landuse'.
     460    *
     461    * @param osmPrimitive
     462    *            The OSM entity to check.
     463    */
     464    public static String getLanduseValue(OsmPrimitive osmPrimitive) {
     465        return osmPrimitive != null ? osmPrimitive.get(LANDUSE_TAG) : null;
     466    }
     467
     468    /**
     469    * Check if OSM primitive has a tag 'fireplace'.
     470    *
     471    * @param osmPrimitive
     472    *            The OSM entity to check.
     473    */
     474    public static boolean hasFireplaceTag(OsmPrimitive osmPrimitive) {
     475        return osmPrimitive != null ? osmPrimitive.hasKey(FIREPLACE_TAG)
     476                : false;
     477    }
     478
     479    /**
     480    * Gets the value of tag 'fireplace'.
     481    *
     482    * @param osmPrimitive
     483    *            The OSM entity to check.
     484    */
     485    public static String getFireplaceValue(OsmPrimitive osmPrimitive) {
     486        return osmPrimitive != null ? osmPrimitive.get(FIREPLACE_TAG) : null;
     487    }
     488
     489    /**
     490    * Check if OSM primitive has a tag 'int_ref'.
     491    *
     492    * @param osmPrimitive
     493    *            The OSM entity to check.
     494    */
     495    public static boolean hasIntRefTag(OsmPrimitive osmPrimitive) {
     496        return osmPrimitive != null ? osmPrimitive.hasKey(INT_REF_TAG) : false;
     497    }
     498
     499    /**
     500    * Gets the value of tag 'int_ref'.
     501    *
     502    * @param osmPrimitive
     503    *            The OSM entity to check.
     504    */
     505    public static String getIntRefValue(OsmPrimitive osmPrimitive) {
     506        return osmPrimitive != null ? osmPrimitive.get(INT_REF_TAG) : null;
     507    }
     508
     509    /**
     510    * Check if OSM primitive has a tag 'whitewater:section_grade'.
     511    *
     512    * @param osmPrimitive
     513    *            The OSM entity to check.
     514    */
     515    public static boolean hasWhitewaterSectionGradeTag(OsmPrimitive osmPrimitive) {
     516        return osmPrimitive != null ? osmPrimitive
     517                .hasKey(WHITEWATER_SECTION_GRADE_TAG) : false;
     518    }
     519
     520    /**
     521    * Gets the value of tag 'whitewater:section_grade'.
     522    *
     523    * @param osmPrimitive
     524    *            The OSM entity to check.
     525    */
     526    public static String getWhitewaterSectionGradeValue(
     527            OsmPrimitive osmPrimitive) {
     528        return osmPrimitive != null ? osmPrimitive
     529                .get(WHITEWATER_SECTION_GRADE_TAG) : null;
     530    }
     531
     532    /**
     533    * Check if OSM primitive has a tag 'denomination'.
     534    *
     535    * @param osmPrimitive
     536    *            The OSM entity to check.
     537    */
     538    public static boolean hasDenominationTag(OsmPrimitive osmPrimitive) {
     539        return osmPrimitive != null ? osmPrimitive.hasKey(DENOMINATION_TAG)
     540                : false;
     541    }
     542
     543    /**
     544    * Gets the value of tag 'denomination'.
     545    *
     546    * @param osmPrimitive
     547    *            The OSM entity to check.
     548    */
     549    public static String getDenominationValue(OsmPrimitive osmPrimitive) {
     550        return osmPrimitive != null ? osmPrimitive.get(DENOMINATION_TAG) : null;
     551    }
     552
     553    /**
     554    * Check if OSM primitive has a tag 'addr:postcode'.
     555    *
     556    * @param osmPrimitive
     557    *            The OSM entity to check.
     558    */
     559    public static boolean hasAddrPostcodeTag(OsmPrimitive osmPrimitive) {
     560        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_POSTCODE_TAG)
     561                : false;
     562    }
     563
     564    /**
     565    * Gets the value of tag 'addr:postcode'.
     566    *
     567    * @param osmPrimitive
     568    *            The OSM entity to check.
     569    */
     570    public static String getAddrPostcodeValue(OsmPrimitive osmPrimitive) {
     571        return osmPrimitive != null ? osmPrimitive.get(ADDR_POSTCODE_TAG)
     572                : null;
     573    }
     574
     575    /**
     576    * Check if OSM primitive has a tag 'wires'.
     577    *
     578    * @param osmPrimitive
     579    *            The OSM entity to check.
     580    */
     581    public static boolean hasWiresTag(OsmPrimitive osmPrimitive) {
     582        return osmPrimitive != null ? osmPrimitive.hasKey(WIRES_TAG) : false;
     583    }
     584
     585    /**
     586    * Gets the value of tag 'wires'.
     587    *
     588    * @param osmPrimitive
     589    *            The OSM entity to check.
     590    */
     591    public static String getWiresValue(OsmPrimitive osmPrimitive) {
     592        return osmPrimitive != null ? osmPrimitive.get(WIRES_TAG) : null;
     593    }
     594
     595    /**
     596    * Check if OSM primitive has a tag 'loc_ref'.
     597    *
     598    * @param osmPrimitive
     599    *            The OSM entity to check.
     600    */
     601    public static boolean hasLocRefTag(OsmPrimitive osmPrimitive) {
     602        return osmPrimitive != null ? osmPrimitive.hasKey(LOC_REF_TAG) : false;
     603    }
     604
     605    /**
     606    * Gets the value of tag 'loc_ref'.
     607    *
     608    * @param osmPrimitive
     609    *            The OSM entity to check.
     610    */
     611    public static String getLocRefValue(OsmPrimitive osmPrimitive) {
     612        return osmPrimitive != null ? osmPrimitive.get(LOC_REF_TAG) : null;
     613    }
     614
     615    /**
     616    * Check if OSM primitive has a tag 'width'.
     617    *
     618    * @param osmPrimitive
     619    *            The OSM entity to check.
     620    */
     621    public static boolean hasWidthTag(OsmPrimitive osmPrimitive) {
     622        return osmPrimitive != null ? osmPrimitive.hasKey(WIDTH_TAG) : false;
     623    }
     624
     625    /**
     626    * Gets the value of tag 'width'.
     627    *
     628    * @param osmPrimitive
     629    *            The OSM entity to check.
     630    */
     631    public static String getWidthValue(OsmPrimitive osmPrimitive) {
     632        return osmPrimitive != null ? osmPrimitive.get(WIDTH_TAG) : null;
     633    }
     634
     635    /**
     636    * Check if OSM primitive has a tag 'tourism'.
     637    *
     638    * @param osmPrimitive
     639    *            The OSM entity to check.
     640    */
     641    public static boolean hasTourismTag(OsmPrimitive osmPrimitive) {
     642        return osmPrimitive != null ? osmPrimitive.hasKey(TOURISM_TAG) : false;
     643    }
     644
     645    /**
     646    * Gets the value of tag 'tourism'.
     647    *
     648    * @param osmPrimitive
     649    *            The OSM entity to check.
     650    */
     651    public static String getTourismValue(OsmPrimitive osmPrimitive) {
     652        return osmPrimitive != null ? osmPrimitive.get(TOURISM_TAG) : null;
     653    }
     654
     655    /**
     656    * Check if OSM primitive has a tag 'leisure'.
     657    *
     658    * @param osmPrimitive
     659    *            The OSM entity to check.
     660    */
     661    public static boolean hasLeisureTag(OsmPrimitive osmPrimitive) {
     662        return osmPrimitive != null ? osmPrimitive.hasKey(LEISURE_TAG) : false;
     663    }
     664
     665    /**
     666    * Gets the value of tag 'leisure'.
     667    *
     668    * @param osmPrimitive
     669    *            The OSM entity to check.
     670    */
     671    public static String getLeisureValue(OsmPrimitive osmPrimitive) {
     672        return osmPrimitive != null ? osmPrimitive.get(LEISURE_TAG) : null;
     673    }
     674
     675    /**
     676    * Check if OSM primitive has a tag 'electrified'.
     677    *
     678    * @param osmPrimitive
     679    *            The OSM entity to check.
     680    */
     681    public static boolean hasElectrifiedTag(OsmPrimitive osmPrimitive) {
     682        return osmPrimitive != null ? osmPrimitive.hasKey(ELECTRIFIED_TAG)
     683                : false;
     684    }
     685
     686    /**
     687    * Gets the value of tag 'electrified'.
     688    *
     689    * @param osmPrimitive
     690    *            The OSM entity to check.
     691    */
     692    public static String getElectrifiedValue(OsmPrimitive osmPrimitive) {
     693        return osmPrimitive != null ? osmPrimitive.get(ELECTRIFIED_TAG) : null;
     694    }
     695
     696    /**
     697    * Check if OSM primitive has a tag 'junction'.
     698    *
     699    * @param osmPrimitive
     700    *            The OSM entity to check.
     701    */
     702    public static boolean hasJunctionTag(OsmPrimitive osmPrimitive) {
     703        return osmPrimitive != null ? osmPrimitive.hasKey(JUNCTION_TAG) : false;
     704    }
     705
     706    /**
     707    * Gets the value of tag 'junction'.
     708    *
     709    * @param osmPrimitive
     710    *            The OSM entity to check.
     711    */
     712    public static String getJunctionValue(OsmPrimitive osmPrimitive) {
     713        return osmPrimitive != null ? osmPrimitive.get(JUNCTION_TAG) : null;
     714    }
     715
     716    /**
     717    * Check if OSM primitive has a tag 'railway'.
     718    *
     719    * @param osmPrimitive
     720    *            The OSM entity to check.
     721    */
     722    public static boolean hasRailwayTag(OsmPrimitive osmPrimitive) {
     723        return osmPrimitive != null ? osmPrimitive.hasKey(RAILWAY_TAG) : false;
     724    }
     725
     726    /**
     727    * Gets the value of tag 'railway'.
     728    *
     729    * @param osmPrimitive
     730    *            The OSM entity to check.
     731    */
     732    public static String getRailwayValue(OsmPrimitive osmPrimitive) {
     733        return osmPrimitive != null ? osmPrimitive.get(RAILWAY_TAG) : null;
     734    }
     735
     736    /**
     737    * Check if OSM primitive has a tag 'voltage'.
     738    *
     739    * @param osmPrimitive
     740    *            The OSM entity to check.
     741    */
     742    public static boolean hasVoltageTag(OsmPrimitive osmPrimitive) {
     743        return osmPrimitive != null ? osmPrimitive.hasKey(VOLTAGE_TAG) : false;
     744    }
     745
     746    /**
     747    * Gets the value of tag 'voltage'.
     748    *
     749    * @param osmPrimitive
     750    *            The OSM entity to check.
     751    */
     752    public static String getVoltageValue(OsmPrimitive osmPrimitive) {
     753        return osmPrimitive != null ? osmPrimitive.get(VOLTAGE_TAG) : null;
     754    }
     755
     756    /**
     757    * Check if OSM primitive has a tag 'bridge'.
     758    *
     759    * @param osmPrimitive
     760    *            The OSM entity to check.
     761    */
     762    public static boolean hasBridgeTag(OsmPrimitive osmPrimitive) {
     763        return osmPrimitive != null ? osmPrimitive.hasKey(BRIDGE_TAG) : false;
     764    }
     765
     766    /**
     767    * Gets the value of tag 'bridge'.
     768    *
     769    * @param osmPrimitive
     770    *            The OSM entity to check.
     771    */
     772    public static String getBridgeValue(OsmPrimitive osmPrimitive) {
     773        return osmPrimitive != null ? osmPrimitive.get(BRIDGE_TAG) : null;
     774    }
     775
     776    /**
     777    * Check if OSM primitive has a tag 'motor_vehicle'.
     778    *
     779    * @param osmPrimitive
     780    *            The OSM entity to check.
     781    */
     782    public static boolean hasMotorVehicleTag(OsmPrimitive osmPrimitive) {
     783        return osmPrimitive != null ? osmPrimitive.hasKey(MOTOR_VEHICLE_TAG)
     784                : false;
     785    }
     786
     787    /**
     788    * Gets the value of tag 'motor_vehicle'.
     789    *
     790    * @param osmPrimitive
     791    *            The OSM entity to check.
     792    */
     793    public static String getMotorVehicleValue(OsmPrimitive osmPrimitive) {
     794        return osmPrimitive != null ? osmPrimitive.get(MOTOR_VEHICLE_TAG)
     795                : null;
     796    }
     797
     798    /**
     799    * Check if OSM primitive has a tag 'comment'.
     800    *
     801    * @param osmPrimitive
     802    *            The OSM entity to check.
     803    */
     804    public static boolean hasCommentTag(OsmPrimitive osmPrimitive) {
     805        return osmPrimitive != null ? osmPrimitive.hasKey(COMMENT_TAG) : false;
     806    }
     807
     808    /**
     809    * Gets the value of tag 'comment'.
     810    *
     811    * @param osmPrimitive
     812    *            The OSM entity to check.
     813    */
     814    public static String getCommentValue(OsmPrimitive osmPrimitive) {
     815        return osmPrimitive != null ? osmPrimitive.get(COMMENT_TAG) : null;
     816    }
     817
     818    /**
     819    * Check if OSM primitive has a tag 'maxspeed'.
     820    *
     821    * @param osmPrimitive
     822    *            The OSM entity to check.
     823    */
     824    public static boolean hasMaxspeedTag(OsmPrimitive osmPrimitive) {
     825        return osmPrimitive != null ? osmPrimitive.hasKey(MAXSPEED_TAG) : false;
     826    }
     827
     828    /**
     829    * Gets the value of tag 'maxspeed'.
     830    *
     831    * @param osmPrimitive
     832    *            The OSM entity to check.
     833    */
     834    public static String getMaxspeedValue(OsmPrimitive osmPrimitive) {
     835        return osmPrimitive != null ? osmPrimitive.get(MAXSPEED_TAG) : null;
     836    }
     837
     838    /**
     839    * Check if OSM primitive has a tag 'natural'.
     840    *
     841    * @param osmPrimitive
     842    *            The OSM entity to check.
     843    */
     844    public static boolean hasNaturalTag(OsmPrimitive osmPrimitive) {
     845        return osmPrimitive != null ? osmPrimitive.hasKey(NATURAL_TAG) : false;
     846    }
     847
     848    /**
     849    * Gets the value of tag 'natural'.
     850    *
     851    * @param osmPrimitive
     852    *            The OSM entity to check.
     853    */
     854    public static String getNaturalValue(OsmPrimitive osmPrimitive) {
     855        return osmPrimitive != null ? osmPrimitive.get(NATURAL_TAG) : null;
     856    }
     857
     858    /**
     859    * Check if OSM primitive has a tag 'sac_scale'.
     860    *
     861    * @param osmPrimitive
     862    *            The OSM entity to check.
     863    */
     864    public static boolean hasSacScaleTag(OsmPrimitive osmPrimitive) {
     865        return osmPrimitive != null ? osmPrimitive.hasKey(SAC_SCALE_TAG)
     866                : false;
     867    }
     868
     869    /**
     870    * Gets the value of tag 'sac_scale'.
     871    *
     872    * @param osmPrimitive
     873    *            The OSM entity to check.
     874    */
     875    public static String getSacScaleValue(OsmPrimitive osmPrimitive) {
     876        return osmPrimitive != null ? osmPrimitive.get(SAC_SCALE_TAG) : null;
     877    }
     878
     879    /**
     880    * Check if OSM primitive has a tag 'tunnel'.
     881    *
     882    * @param osmPrimitive
     883    *            The OSM entity to check.
     884    */
     885    public static boolean hasTunnelTag(OsmPrimitive osmPrimitive) {
     886        return osmPrimitive != null ? osmPrimitive.hasKey(TUNNEL_TAG) : false;
     887    }
     888
     889    /**
     890    * Gets the value of tag 'tunnel'.
     891    *
     892    * @param osmPrimitive
     893    *            The OSM entity to check.
     894    */
     895    public static String getTunnelValue(OsmPrimitive osmPrimitive) {
     896        return osmPrimitive != null ? osmPrimitive.get(TUNNEL_TAG) : null;
     897    }
     898
     899    /**
     900    * Check if OSM primitive has a tag 'waterway'.
     901    *
     902    * @param osmPrimitive
     903    *            The OSM entity to check.
     904    */
     905    public static boolean hasWaterwayTag(OsmPrimitive osmPrimitive) {
     906        return osmPrimitive != null ? osmPrimitive.hasKey(WATERWAY_TAG) : false;
     907    }
     908
     909    /**
     910    * Gets the value of tag 'waterway'.
     911    *
     912    * @param osmPrimitive
     913    *            The OSM entity to check.
     914    */
     915    public static String getWaterwayValue(OsmPrimitive osmPrimitive) {
     916        return osmPrimitive != null ? osmPrimitive.get(WATERWAY_TAG) : null;
     917    }
     918
     919    /**
     920    * Check if OSM primitive has a tag 'trail_visibility'.
     921    *
     922    * @param osmPrimitive
     923    *            The OSM entity to check.
     924    */
     925    public static boolean hasTrailVisibilityTag(OsmPrimitive osmPrimitive) {
     926        return osmPrimitive != null ? osmPrimitive.hasKey(TRAIL_VISIBILITY_TAG)
     927                : false;
     928    }
     929
     930    /**
     931    * Gets the value of tag 'trail_visibility'.
     932    *
     933    * @param osmPrimitive
     934    *            The OSM entity to check.
     935    */
     936    public static String getTrailVisibilityValue(OsmPrimitive osmPrimitive) {
     937        return osmPrimitive != null ? osmPrimitive.get(TRAIL_VISIBILITY_TAG)
     938                : null;
     939    }
     940
     941    /**
     942    * Check if OSM primitive has a tag 'highway'.
     943    *
     944    * @param osmPrimitive
     945    *            The OSM entity to check.
     946    */
     947    public static boolean hasHighwayTag(OsmPrimitive osmPrimitive) {
     948        return osmPrimitive != null ? osmPrimitive.hasKey(HIGHWAY_TAG) : false;
     949    }
     950
     951    /**
     952    * Gets the value of tag 'highway'.
     953    *
     954    * @param osmPrimitive
     955    *            The OSM entity to check.
     956    */
     957    public static String getHighwayValue(OsmPrimitive osmPrimitive) {
     958        return osmPrimitive != null ? osmPrimitive.get(HIGHWAY_TAG) : null;
     959    }
     960
     961    /**
     962    * Check if OSM primitive has a tag 'vehicle'.
     963    *
     964    * @param osmPrimitive
     965    *            The OSM entity to check.
     966    */
     967    public static boolean hasVehicleTag(OsmPrimitive osmPrimitive) {
     968        return osmPrimitive != null ? osmPrimitive.hasKey(VEHICLE_TAG) : false;
     969    }
     970
     971    /**
     972    * Gets the value of tag 'vehicle'.
     973    *
     974    * @param osmPrimitive
     975    *            The OSM entity to check.
     976    */
     977    public static String getVehicleValue(OsmPrimitive osmPrimitive) {
     978        return osmPrimitive != null ? osmPrimitive.get(VEHICLE_TAG) : null;
     979    }
     980
     981    /**
     982    * Check if OSM primitive has a tag 'horse'.
     983    *
     984    * @param osmPrimitive
     985    *            The OSM entity to check.
     986    */
     987    public static boolean hasHorseTag(OsmPrimitive osmPrimitive) {
     988        return osmPrimitive != null ? osmPrimitive.hasKey(HORSE_TAG) : false;
     989    }
     990
     991    /**
     992    * Gets the value of tag 'horse'.
     993    *
     994    * @param osmPrimitive
     995    *            The OSM entity to check.
     996    */
     997    public static String getHorseValue(OsmPrimitive osmPrimitive) {
     998        return osmPrimitive != null ? osmPrimitive.get(HORSE_TAG) : null;
     999    }
     1000
     1001    /**
     1002    * Check if OSM primitive has a tag 'goods'.
     1003    *
     1004    * @param osmPrimitive
     1005    *            The OSM entity to check.
     1006    */
     1007    public static boolean hasGoodsTag(OsmPrimitive osmPrimitive) {
     1008        return osmPrimitive != null ? osmPrimitive.hasKey(GOODS_TAG) : false;
     1009    }
     1010
     1011    /**
     1012    * Gets the value of tag 'goods'.
     1013    *
     1014    * @param osmPrimitive
     1015    *            The OSM entity to check.
     1016    */
     1017    public static String getGoodsValue(OsmPrimitive osmPrimitive) {
     1018        return osmPrimitive != null ? osmPrimitive.get(GOODS_TAG) : null;
     1019    }
     1020
     1021    /**
     1022    * Check if OSM primitive has a tag 'frequency'.
     1023    *
     1024    * @param osmPrimitive
     1025    *            The OSM entity to check.
     1026    */
     1027    public static boolean hasFrequencyTag(OsmPrimitive osmPrimitive) {
     1028        return osmPrimitive != null ? osmPrimitive.hasKey(FREQUENCY_TAG)
     1029                : false;
     1030    }
     1031
     1032    /**
     1033    * Gets the value of tag 'frequency'.
     1034    *
     1035    * @param osmPrimitive
     1036    *            The OSM entity to check.
     1037    */
     1038    public static String getFrequencyValue(OsmPrimitive osmPrimitive) {
     1039        return osmPrimitive != null ? osmPrimitive.get(FREQUENCY_TAG) : null;
     1040    }
     1041
     1042    /**
     1043    * Check if OSM primitive has a tag 'man_made'.
     1044    *
     1045    * @param osmPrimitive
     1046    *            The OSM entity to check.
     1047    */
     1048    public static boolean hasManMadeTag(OsmPrimitive osmPrimitive) {
     1049        return osmPrimitive != null ? osmPrimitive.hasKey(MAN_MADE_TAG) : false;
     1050    }
     1051
     1052    /**
     1053    * Gets the value of tag 'man_made'.
     1054    *
     1055    * @param osmPrimitive
     1056    *            The OSM entity to check.
     1057    */
     1058    public static String getManMadeValue(OsmPrimitive osmPrimitive) {
     1059        return osmPrimitive != null ? osmPrimitive.get(MAN_MADE_TAG) : null;
     1060    }
     1061
     1062    /**
     1063    * Check if OSM primitive has a tag 'addr:housenumber'.
     1064    *
     1065    * @param osmPrimitive
     1066    *            The OSM entity to check.
     1067    */
     1068    public static boolean hasAddrHousenumberTag(OsmPrimitive osmPrimitive) {
     1069        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENUMBER_TAG)
     1070                : false;
     1071    }
     1072
     1073    /**
     1074    * Gets the value of tag 'addr:housenumber'.
     1075    *
     1076    * @param osmPrimitive
     1077    *            The OSM entity to check.
     1078    */
     1079    public static String getAddrHousenumberValue(OsmPrimitive osmPrimitive) {
     1080        return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENUMBER_TAG)
     1081                : null;
     1082    }
     1083
     1084    /**
     1085    * Check if OSM primitive has a tag 'addr:housename'.
     1086    *
     1087    * @param osmPrimitive
     1088    *            The OSM entity to check.
     1089    */
     1090    public static boolean hasAddrHousenameTag(OsmPrimitive osmPrimitive) {
     1091        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_HOUSENAME_TAG)
     1092                : false;
     1093    }
     1094
     1095    /**
     1096    * Gets the value of tag 'addr:housename'.
     1097    *
     1098    * @param osmPrimitive
     1099    *            The OSM entity to check.
     1100    */
     1101    public static String getAddrHousenameValue(OsmPrimitive osmPrimitive) {
     1102        return osmPrimitive != null ? osmPrimitive.get(ADDR_HOUSENAME_TAG)
     1103                : null;
     1104    }
     1105
     1106    /**
     1107    * Check if OSM primitive has a tag 'area'.
     1108    *
     1109    * @param osmPrimitive
     1110    *            The OSM entity to check.
     1111    */
     1112    public static boolean hasAreaTag(OsmPrimitive osmPrimitive) {
     1113        return osmPrimitive != null ? osmPrimitive.hasKey(AREA_TAG) : false;
     1114    }
     1115
     1116    /**
     1117    * Gets the value of tag 'area'.
     1118    *
     1119    * @param osmPrimitive
     1120    *            The OSM entity to check.
     1121    */
     1122    public static String getAreaValue(OsmPrimitive osmPrimitive) {
     1123        return osmPrimitive != null ? osmPrimitive.get(AREA_TAG) : null;
     1124    }
     1125
     1126    /**
     1127    * Check if OSM primitive has a tag 'building:levels'.
     1128    *
     1129    * @param osmPrimitive
     1130    *            The OSM entity to check.
     1131    */
     1132    public static boolean hasBuildingLevelsTag(OsmPrimitive osmPrimitive) {
     1133        return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_LEVELS_TAG)
     1134                : false;
     1135    }
     1136
     1137    /**
     1138    * Gets the value of tag 'building:levels'.
     1139    *
     1140    * @param osmPrimitive
     1141    *            The OSM entity to check.
     1142    */
     1143    public static String getBuildingLevelsValue(OsmPrimitive osmPrimitive) {
     1144        return osmPrimitive != null ? osmPrimitive.get(BUILDING_LEVELS_TAG)
     1145                : null;
     1146    }
     1147
     1148    /**
     1149    * Check if OSM primitive has a tag 'wheelchair'.
     1150    *
     1151    * @param osmPrimitive
     1152    *            The OSM entity to check.
     1153    */
     1154    public static boolean hasWheelchairTag(OsmPrimitive osmPrimitive) {
     1155        return osmPrimitive != null ? osmPrimitive.hasKey(WHEELCHAIR_TAG)
     1156                : false;
     1157    }
     1158
     1159    /**
     1160    * Gets the value of tag 'wheelchair'.
     1161    *
     1162    * @param osmPrimitive
     1163    *            The OSM entity to check.
     1164    */
     1165    public static String getWheelchairValue(OsmPrimitive osmPrimitive) {
     1166        return osmPrimitive != null ? osmPrimitive.get(WHEELCHAIR_TAG) : null;
     1167    }
     1168
     1169    /**
     1170    * Check if OSM primitive has a tag 'name'.
     1171    *
     1172    * @param osmPrimitive
     1173    *            The OSM entity to check.
     1174    */
     1175    public static boolean hasNameTag(OsmPrimitive osmPrimitive) {
     1176        return osmPrimitive != null ? osmPrimitive.hasKey(NAME_TAG) : false;
     1177    }
     1178
     1179    /**
     1180    * Gets the value of tag 'name'.
     1181    *
     1182    * @param osmPrimitive
     1183    *            The OSM entity to check.
     1184    */
     1185    public static String getNameValue(OsmPrimitive osmPrimitive) {
     1186        return osmPrimitive != null ? osmPrimitive.get(NAME_TAG) : null;
     1187    }
     1188
     1189    /**
     1190    * Check if OSM primitive has a tag 'oneway'.
     1191    *
     1192    * @param osmPrimitive
     1193    *            The OSM entity to check.
     1194    */
     1195    public static boolean hasOnewayTag(OsmPrimitive osmPrimitive) {
     1196        return osmPrimitive != null ? osmPrimitive.hasKey(ONEWAY_TAG) : false;
     1197    }
     1198
     1199    /**
     1200    * Gets the value of tag 'oneway'.
     1201    *
     1202    * @param osmPrimitive
     1203    *            The OSM entity to check.
     1204    */
     1205    public static String getOnewayValue(OsmPrimitive osmPrimitive) {
     1206        return osmPrimitive != null ? osmPrimitive.get(ONEWAY_TAG) : null;
     1207    }
     1208
     1209    /**
     1210    * Check if OSM primitive has a tag 'FIXME'.
     1211    *
     1212    * @param osmPrimitive
     1213    *            The OSM entity to check.
     1214    */
     1215    public static boolean hasFIXMETag(OsmPrimitive osmPrimitive) {
     1216        return osmPrimitive != null ? osmPrimitive.hasKey(FIXME_TAG) : false;
     1217    }
     1218
     1219    /**
     1220    * Gets the value of tag 'FIXME'.
     1221    *
     1222    * @param osmPrimitive
     1223    *            The OSM entity to check.
     1224    */
     1225    public static String getFIXMEValue(OsmPrimitive osmPrimitive) {
     1226        return osmPrimitive != null ? osmPrimitive.get(FIXME_TAG) : null;
     1227    }
     1228
     1229    /**
     1230    * Check if OSM primitive has a tag 'capacity'.
     1231    *
     1232    * @param osmPrimitive
     1233    *            The OSM entity to check.
     1234    */
     1235    public static boolean hasCapacityTag(OsmPrimitive osmPrimitive) {
     1236        return osmPrimitive != null ? osmPrimitive.hasKey(CAPACITY_TAG) : false;
     1237    }
     1238
     1239    /**
     1240    * Gets the value of tag 'capacity'.
     1241    *
     1242    * @param osmPrimitive
     1243    *            The OSM entity to check.
     1244    */
     1245    public static String getCapacityValue(OsmPrimitive osmPrimitive) {
     1246        return osmPrimitive != null ? osmPrimitive.get(CAPACITY_TAG) : null;
     1247    }
     1248
     1249    /**
     1250    * Check if OSM primitive has a tag 'motorcycle'.
     1251    *
     1252    * @param osmPrimitive
     1253    *            The OSM entity to check.
     1254    */
     1255    public static boolean hasMotorcycleTag(OsmPrimitive osmPrimitive) {
     1256        return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCYCLE_TAG)
     1257                : false;
     1258    }
     1259
     1260    /**
     1261    * Gets the value of tag 'motorcycle'.
     1262    *
     1263    * @param osmPrimitive
     1264    *            The OSM entity to check.
     1265    */
     1266    public static String getMotorcycleValue(OsmPrimitive osmPrimitive) {
     1267        return osmPrimitive != null ? osmPrimitive.get(MOTORCYCLE_TAG) : null;
     1268    }
     1269
     1270    /**
     1271    * Check if OSM primitive has a tag 'hgv'.
     1272    *
     1273    * @param osmPrimitive
     1274    *            The OSM entity to check.
     1275    */
     1276    public static boolean hasHgvTag(OsmPrimitive osmPrimitive) {
     1277        return osmPrimitive != null ? osmPrimitive.hasKey(HGV_TAG) : false;
     1278    }
     1279
     1280    /**
     1281    * Gets the value of tag 'hgv'.
     1282    *
     1283    * @param osmPrimitive
     1284    *            The OSM entity to check.
     1285    */
     1286    public static String getHgvValue(OsmPrimitive osmPrimitive) {
     1287        return osmPrimitive != null ? osmPrimitive.get(HGV_TAG) : null;
     1288    }
     1289
     1290    /**
     1291    * Check if OSM primitive has a tag 'construction'.
     1292    *
     1293    * @param osmPrimitive
     1294    *            The OSM entity to check.
     1295    */
     1296    public static boolean hasConstructionTag(OsmPrimitive osmPrimitive) {
     1297        return osmPrimitive != null ? osmPrimitive.hasKey(CONSTRUCTION_TAG)
     1298                : false;
     1299    }
     1300
     1301    /**
     1302    * Gets the value of tag 'construction'.
     1303    *
     1304    * @param osmPrimitive
     1305    *            The OSM entity to check.
     1306    */
     1307    public static String getConstructionValue(OsmPrimitive osmPrimitive) {
     1308        return osmPrimitive != null ? osmPrimitive.get(CONSTRUCTION_TAG) : null;
     1309    }
     1310
     1311    /**
     1312    * Check if OSM primitive has a tag 'addr:state'.
     1313    *
     1314    * @param osmPrimitive
     1315    *            The OSM entity to check.
     1316    */
     1317    public static boolean hasAddrStateTag(OsmPrimitive osmPrimitive) {
     1318        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_STATE_TAG)
     1319                : false;
     1320    }
     1321
     1322    /**
     1323    * Gets the value of tag 'addr:state'.
     1324    *
     1325    * @param osmPrimitive
     1326    *            The OSM entity to check.
     1327    */
     1328    public static String getAddrStateValue(OsmPrimitive osmPrimitive) {
     1329        return osmPrimitive != null ? osmPrimitive.get(ADDR_STATE_TAG) : null;
     1330    }
     1331
     1332    /**
     1333    * Check if OSM primitive has a tag 'lanes'.
     1334    *
     1335    * @param osmPrimitive
     1336    *            The OSM entity to check.
     1337    */
     1338    public static boolean hasLanesTag(OsmPrimitive osmPrimitive) {
     1339        return osmPrimitive != null ? osmPrimitive.hasKey(LANES_TAG) : false;
     1340    }
     1341
     1342    /**
     1343    * Gets the value of tag 'lanes'.
     1344    *
     1345    * @param osmPrimitive
     1346    *            The OSM entity to check.
     1347    */
     1348    public static String getLanesValue(OsmPrimitive osmPrimitive) {
     1349        return osmPrimitive != null ? osmPrimitive.get(LANES_TAG) : null;
     1350    }
     1351
     1352    /**
     1353    * Check if OSM primitive has a tag 'note'.
     1354    *
     1355    * @param osmPrimitive
     1356    *            The OSM entity to check.
     1357    */
     1358    public static boolean hasNoteTag(OsmPrimitive osmPrimitive) {
     1359        return osmPrimitive != null ? osmPrimitive.hasKey(NOTE_TAG) : false;
     1360    }
     1361
     1362    /**
     1363    * Gets the value of tag 'note'.
     1364    *
     1365    * @param osmPrimitive
     1366    *            The OSM entity to check.
     1367    */
     1368    public static String getNoteValue(OsmPrimitive osmPrimitive) {
     1369        return osmPrimitive != null ? osmPrimitive.get(NOTE_TAG) : null;
     1370    }
     1371
     1372    /**
     1373    * Check if OSM primitive has a tag 'lit'.
     1374    *
     1375    * @param osmPrimitive
     1376    *            The OSM entity to check.
     1377    */
     1378    public static boolean hasLitTag(OsmPrimitive osmPrimitive) {
     1379        return osmPrimitive != null ? osmPrimitive.hasKey(LIT_TAG) : false;
     1380    }
     1381
     1382    /**
     1383    * Gets the value of tag 'lit'.
     1384    *
     1385    * @param osmPrimitive
     1386    *            The OSM entity to check.
     1387    */
     1388    public static String getLitValue(OsmPrimitive osmPrimitive) {
     1389        return osmPrimitive != null ? osmPrimitive.get(LIT_TAG) : null;
     1390    }
     1391
     1392    /**
     1393    * Check if OSM primitive has a tag 'building'.
     1394    *
     1395    * @param osmPrimitive
     1396    *            The OSM entity to check.
     1397    */
     1398    public static boolean hasBuildingTag(OsmPrimitive osmPrimitive) {
     1399        return osmPrimitive != null ? osmPrimitive.hasKey(BUILDING_TAG) : false;
     1400    }
     1401
     1402    /**
     1403    * Gets the value of tag 'building'.
     1404    *
     1405    * @param osmPrimitive
     1406    *            The OSM entity to check.
     1407    */
     1408    public static String getBuildingValue(OsmPrimitive osmPrimitive) {
     1409        return osmPrimitive != null ? osmPrimitive.get(BUILDING_TAG) : null;
     1410    }
     1411
     1412    /**
     1413    * Check if OSM primitive has a tag 'segregated'.
     1414    *
     1415    * @param osmPrimitive
     1416    *            The OSM entity to check.
     1417    */
     1418    public static boolean hasSegregatedTag(OsmPrimitive osmPrimitive) {
     1419        return osmPrimitive != null ? osmPrimitive.hasKey(SEGREGATED_TAG)
     1420                : false;
     1421    }
     1422
     1423    /**
     1424    * Gets the value of tag 'segregated'.
     1425    *
     1426    * @param osmPrimitive
     1427    *            The OSM entity to check.
     1428    */
     1429    public static String getSegregatedValue(OsmPrimitive osmPrimitive) {
     1430        return osmPrimitive != null ? osmPrimitive.get(SEGREGATED_TAG) : null;
     1431    }
     1432
     1433    /**
     1434    * Check if OSM primitive has a tag 'addr:inclusion'.
     1435    *
     1436    * @param osmPrimitive
     1437    *            The OSM entity to check.
     1438    */
     1439    public static boolean hasAddrInclusionTag(OsmPrimitive osmPrimitive) {
     1440        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_INCLUSION_TAG)
     1441                : false;
     1442    }
     1443
     1444    /**
     1445    * Gets the value of tag 'addr:inclusion'.
     1446    *
     1447    * @param osmPrimitive
     1448    *            The OSM entity to check.
     1449    */
     1450    public static String getAddrInclusionValue(OsmPrimitive osmPrimitive) {
     1451        return osmPrimitive != null ? osmPrimitive.get(ADDR_INCLUSION_TAG)
     1452                : null;
     1453    }
     1454
     1455    /**
     1456    * Check if OSM primitive has a tag 'layer'.
     1457    *
     1458    * @param osmPrimitive
     1459    *            The OSM entity to check.
     1460    */
     1461    public static boolean hasLayerTag(OsmPrimitive osmPrimitive) {
     1462        return osmPrimitive != null ? osmPrimitive.hasKey(LAYER_TAG) : false;
     1463    }
     1464
     1465    /**
     1466    * Gets the value of tag 'layer'.
     1467    *
     1468    * @param osmPrimitive
     1469    *            The OSM entity to check.
     1470    */
     1471    public static String getLayerValue(OsmPrimitive osmPrimitive) {
     1472        return osmPrimitive != null ? osmPrimitive.get(LAYER_TAG) : null;
     1473    }
     1474
     1475    /**
     1476    * Check if OSM primitive has a tag 'sport'.
     1477    *
     1478    * @param osmPrimitive
     1479    *            The OSM entity to check.
     1480    */
     1481    public static boolean hasSportTag(OsmPrimitive osmPrimitive) {
     1482        return osmPrimitive != null ? osmPrimitive.hasKey(SPORT_TAG) : false;
     1483    }
     1484
     1485    /**
     1486    * Gets the value of tag 'sport'.
     1487    *
     1488    * @param osmPrimitive
     1489    *            The OSM entity to check.
     1490    */
     1491    public static String getSportValue(OsmPrimitive osmPrimitive) {
     1492        return osmPrimitive != null ? osmPrimitive.get(SPORT_TAG) : null;
     1493    }
     1494
     1495    /**
     1496    * Check if OSM primitive has a tag 'addr:interpolation'.
     1497    *
     1498    * @param osmPrimitive
     1499    *            The OSM entity to check.
     1500    */
     1501    public static boolean hasAddrInterpolationTag(OsmPrimitive osmPrimitive) {
     1502        return osmPrimitive != null ? osmPrimitive
     1503                .hasKey(ADDR_INTERPOLATION_TAG) : false;
     1504    }
     1505
     1506    /**
     1507    * Gets the value of tag 'addr:interpolation'.
     1508    *
     1509    * @param osmPrimitive
     1510    *            The OSM entity to check.
     1511    */
     1512    public static String getAddrInterpolationValue(OsmPrimitive osmPrimitive) {
     1513        return osmPrimitive != null ? osmPrimitive.get(ADDR_INTERPOLATION_TAG)
     1514                : null;
     1515    }
     1516
     1517    /**
     1518    * Check if OSM primitive has a tag 'cutting'.
     1519    *
     1520    * @param osmPrimitive
     1521    *            The OSM entity to check.
     1522    */
     1523    public static boolean hasCuttingTag(OsmPrimitive osmPrimitive) {
     1524        return osmPrimitive != null ? osmPrimitive.hasKey(CUTTING_TAG) : false;
     1525    }
     1526
     1527    /**
     1528    * Gets the value of tag 'cutting'.
     1529    *
     1530    * @param osmPrimitive
     1531    *            The OSM entity to check.
     1532    */
     1533    public static String getCuttingValue(OsmPrimitive osmPrimitive) {
     1534        return osmPrimitive != null ? osmPrimitive.get(CUTTING_TAG) : null;
     1535    }
     1536
     1537    /**
     1538    * Check if OSM primitive has a tag 'amenity'.
     1539    *
     1540    * @param osmPrimitive
     1541    *            The OSM entity to check.
     1542    */
     1543    public static boolean hasAmenityTag(OsmPrimitive osmPrimitive) {
     1544        return osmPrimitive != null ? osmPrimitive.hasKey(AMENITY_TAG) : false;
     1545    }
     1546
     1547    /**
     1548    * Gets the value of tag 'amenity'.
     1549    *
     1550    * @param osmPrimitive
     1551    *            The OSM entity to check.
     1552    */
     1553    public static String getAmenityValue(OsmPrimitive osmPrimitive) {
     1554        return osmPrimitive != null ? osmPrimitive.get(AMENITY_TAG) : null;
     1555    }
     1556
     1557    /**
     1558    * Check if OSM primitive has a tag 'access'.
     1559    *
     1560    * @param osmPrimitive
     1561    *            The OSM entity to check.
     1562    */
     1563    public static boolean hasAccessTag(OsmPrimitive osmPrimitive) {
     1564        return osmPrimitive != null ? osmPrimitive.hasKey(ACCESS_TAG) : false;
     1565    }
     1566
     1567    /**
     1568    * Gets the value of tag 'access'.
     1569    *
     1570    * @param osmPrimitive
     1571    *            The OSM entity to check.
     1572    */
     1573    public static String getAccessValue(OsmPrimitive osmPrimitive) {
     1574        return osmPrimitive != null ? osmPrimitive.get(ACCESS_TAG) : null;
     1575    }
     1576
     1577    /**
     1578    * Check if OSM primitive has a tag 'agricultural'.
     1579    *
     1580    * @param osmPrimitive
     1581    *            The OSM entity to check.
     1582    */
     1583    public static boolean hasAgriculturalTag(OsmPrimitive osmPrimitive) {
     1584        return osmPrimitive != null ? osmPrimitive.hasKey(AGRICULTURAL_TAG)
     1585                : false;
     1586    }
     1587
     1588    /**
     1589    * Gets the value of tag 'agricultural'.
     1590    *
     1591    * @param osmPrimitive
     1592    *            The OSM entity to check.
     1593    */
     1594    public static String getAgriculturalValue(OsmPrimitive osmPrimitive) {
     1595        return osmPrimitive != null ? osmPrimitive.get(AGRICULTURAL_TAG) : null;
     1596    }
     1597
     1598    /**
     1599    * Check if OSM primitive has a tag 'capacity:disabled'.
     1600    *
     1601    * @param osmPrimitive
     1602    *            The OSM entity to check.
     1603    */
     1604    public static boolean hasCapacityDisabledTag(OsmPrimitive osmPrimitive) {
     1605        return osmPrimitive != null ? osmPrimitive
     1606                .hasKey(CAPACITY_DISABLED_TAG) : false;
     1607    }
     1608
     1609    /**
     1610    * Gets the value of tag 'capacity:disabled'.
     1611    *
     1612    * @param osmPrimitive
     1613    *            The OSM entity to check.
     1614    */
     1615    public static String getCapacityDisabledValue(OsmPrimitive osmPrimitive) {
     1616        return osmPrimitive != null ? osmPrimitive.get(CAPACITY_DISABLED_TAG)
     1617                : null;
     1618    }
     1619
     1620    /**
     1621    * Check if OSM primitive has a tag 'operator'.
     1622    *
     1623    * @param osmPrimitive
     1624    *            The OSM entity to check.
     1625    */
     1626    public static boolean hasOperatorTag(OsmPrimitive osmPrimitive) {
     1627        return osmPrimitive != null ? osmPrimitive.hasKey(OPERATOR_TAG) : false;
     1628    }
     1629
     1630    /**
     1631    * Gets the value of tag 'operator'.
     1632    *
     1633    * @param osmPrimitive
     1634    *            The OSM entity to check.
     1635    */
     1636    public static String getOperatorValue(OsmPrimitive osmPrimitive) {
     1637        return osmPrimitive != null ? osmPrimitive.get(OPERATOR_TAG) : null;
     1638    }
     1639
     1640    /**
     1641    * Check if OSM primitive has a tag 'ref'.
     1642    *
     1643    * @param osmPrimitive
     1644    *            The OSM entity to check.
     1645    */
     1646    public static boolean hasRefTag(OsmPrimitive osmPrimitive) {
     1647        return osmPrimitive != null ? osmPrimitive.hasKey(REF_TAG) : false;
     1648    }
     1649
     1650    /**
     1651    * Gets the value of tag 'ref'.
     1652    *
     1653    * @param osmPrimitive
     1654    *            The OSM entity to check.
     1655    */
     1656    public static String getRefValue(OsmPrimitive osmPrimitive) {
     1657        return osmPrimitive != null ? osmPrimitive.get(REF_TAG) : null;
     1658    }
     1659
     1660    /**
     1661    * Check if OSM primitive has a tag 'noexit'.
     1662    *
     1663    * @param osmPrimitive
     1664    *            The OSM entity to check.
     1665    */
     1666    public static boolean hasNoexitTag(OsmPrimitive osmPrimitive) {
     1667        return osmPrimitive != null ? osmPrimitive.hasKey(NOEXIT_TAG) : false;
     1668    }
     1669
     1670    /**
     1671    * Gets the value of tag 'noexit'.
     1672    *
     1673    * @param osmPrimitive
     1674    *            The OSM entity to check.
     1675    */
     1676    public static String getNoexitValue(OsmPrimitive osmPrimitive) {
     1677        return osmPrimitive != null ? osmPrimitive.get(NOEXIT_TAG) : null;
     1678    }
     1679
     1680    /**
     1681    * Check if OSM primitive has a tag 'admin_level'.
     1682    *
     1683    * @param osmPrimitive
     1684    *            The OSM entity to check.
     1685    */
     1686    public static boolean hasAdminLevelTag(OsmPrimitive osmPrimitive) {
     1687        return osmPrimitive != null ? osmPrimitive.hasKey(ADMIN_LEVEL_TAG)
     1688                : false;
     1689    }
     1690
     1691    /**
     1692    * Gets the value of tag 'admin_level'.
     1693    *
     1694    * @param osmPrimitive
     1695    *            The OSM entity to check.
     1696    */
     1697    public static String getAdminLevelValue(OsmPrimitive osmPrimitive) {
     1698        return osmPrimitive != null ? osmPrimitive.get(ADMIN_LEVEL_TAG) : null;
     1699    }
     1700
     1701    /**
     1702    * Check if OSM primitive has a tag 'source'.
     1703    *
     1704    * @param osmPrimitive
     1705    *            The OSM entity to check.
     1706    */
     1707    public static boolean hasSourceTag(OsmPrimitive osmPrimitive) {
     1708        return osmPrimitive != null ? osmPrimitive.hasKey(SOURCE_TAG) : false;
     1709    }
     1710
     1711    /**
     1712    * Gets the value of tag 'source'.
     1713    *
     1714    * @param osmPrimitive
     1715    *            The OSM entity to check.
     1716    */
     1717    public static String getSourceValue(OsmPrimitive osmPrimitive) {
     1718        return osmPrimitive != null ? osmPrimitive.get(SOURCE_TAG) : null;
     1719    }
     1720
     1721    /**
     1722    * Check if OSM primitive has a tag 'tracktype'.
     1723    *
     1724    * @param osmPrimitive
     1725    *            The OSM entity to check.
     1726    */
     1727    public static boolean hasTracktypeTag(OsmPrimitive osmPrimitive) {
     1728        return osmPrimitive != null ? osmPrimitive.hasKey(TRACKTYPE_TAG)
     1729                : false;
     1730    }
     1731
     1732    /**
     1733    * Gets the value of tag 'tracktype'.
     1734    *
     1735    * @param osmPrimitive
     1736    *            The OSM entity to check.
     1737    */
     1738    public static String getTracktypeValue(OsmPrimitive osmPrimitive) {
     1739        return osmPrimitive != null ? osmPrimitive.get(TRACKTYPE_TAG) : null;
     1740    }
     1741
     1742    /**
     1743    * Check if OSM primitive has a tag 'addr:country'.
     1744    *
     1745    * @param osmPrimitive
     1746    *            The OSM entity to check.
     1747    */
     1748    public static boolean hasAddrCountryTag(OsmPrimitive osmPrimitive) {
     1749        return osmPrimitive != null ? osmPrimitive.hasKey(ADDR_COUNTRY_TAG)
     1750                : false;
     1751    }
     1752
     1753    /**
     1754    * Gets the value of tag 'addr:country'.
     1755    *
     1756    * @param osmPrimitive
     1757    *            The OSM entity to check.
     1758    */
     1759    public static String getAddrCountryValue(OsmPrimitive osmPrimitive) {
     1760        return osmPrimitive != null ? osmPrimitive.get(ADDR_COUNTRY_TAG) : null;
     1761    }
     1762
     1763    /**
     1764    * Check if OSM primitive has a tag 'route'.
     1765    *
     1766    * @param osmPrimitive
     1767    *            The OSM entity to check.
     1768    */
     1769    public static boolean hasRouteTag(OsmPrimitive osmPrimitive) {
     1770        return osmPrimitive != null ? osmPrimitive.hasKey(ROUTE_TAG) : false;
     1771    }
     1772
     1773    /**
     1774    * Gets the value of tag 'route'.
     1775    *
     1776    * @param osmPrimitive
     1777    *            The OSM entity to check.
     1778    */
     1779    public static String getRouteValue(OsmPrimitive osmPrimitive) {
     1780        return osmPrimitive != null ? osmPrimitive.get(ROUTE_TAG) : null;
     1781    }
     1782
     1783    /**
     1784    * Check if OSM primitive has a tag 'cables'.
     1785    *
     1786    * @param osmPrimitive
     1787    *            The OSM entity to check.
     1788    */
     1789    public static boolean hasCablesTag(OsmPrimitive osmPrimitive) {
     1790        return osmPrimitive != null ? osmPrimitive.hasKey(CABLES_TAG) : false;
     1791    }
     1792
     1793    /**
     1794    * Gets the value of tag 'cables'.
     1795    *
     1796    * @param osmPrimitive
     1797    *            The OSM entity to check.
     1798    */
     1799    public static String getCablesValue(OsmPrimitive osmPrimitive) {
     1800        return osmPrimitive != null ? osmPrimitive.get(CABLES_TAG) : null;
     1801    }
     1802
     1803    /**
     1804    * Check if OSM primitive has a tag 'service'.
     1805    *
     1806    * @param osmPrimitive
     1807    *            The OSM entity to check.
     1808    */
     1809    public static boolean hasServiceTag(OsmPrimitive osmPrimitive) {
     1810        return osmPrimitive != null ? osmPrimitive.hasKey(SERVICE_TAG) : false;
     1811    }
     1812
     1813    /**
     1814    * Gets the value of tag 'service'.
     1815    *
     1816    * @param osmPrimitive
     1817    *            The OSM entity to check.
     1818    */
     1819    public static String getServiceValue(OsmPrimitive osmPrimitive) {
     1820        return osmPrimitive != null ? osmPrimitive.get(SERVICE_TAG) : null;
     1821    }
     1822
     1823    /**
     1824    * Check if OSM primitive has a tag 'motorcar'.
     1825    *
     1826    * @param osmPrimitive
     1827    *            The OSM entity to check.
     1828    */
     1829    public static boolean hasMotorcarTag(OsmPrimitive osmPrimitive) {
     1830        return osmPrimitive != null ? osmPrimitive.hasKey(MOTORCAR_TAG) : false;
     1831    }
     1832
     1833    /**
     1834    * Gets the value of tag 'motorcar'.
     1835    *
     1836    * @param osmPrimitive
     1837    *            The OSM entity to check.
     1838    */
     1839    public static String getMotorcarValue(OsmPrimitive osmPrimitive) {
     1840        return osmPrimitive != null ? osmPrimitive.get(MOTORCAR_TAG) : null;
     1841    }
     1842
     1843    /**
     1844    * Check if OSM primitive has a tag 'whitewater'.
     1845    *
     1846    * @param osmPrimitive
     1847    *            The OSM entity to check.
     1848    */
     1849    public static boolean hasWhitewaterTag(OsmPrimitive osmPrimitive) {
     1850        return osmPrimitive != null ? osmPrimitive.hasKey(WHITEWATER_TAG)
     1851                : false;
     1852    }
     1853
     1854    /**
     1855    * Gets the value of tag 'whitewater'.
     1856    *
     1857    * @param osmPrimitive
     1858    *            The OSM entity to check.
     1859    */
     1860    public static String getWhitewaterValue(OsmPrimitive osmPrimitive) {
     1861        return osmPrimitive != null ? osmPrimitive.get(WHITEWATER_TAG) : null;
     1862    }
     1863
     1864    /**
     1865    * Check if OSM primitive has a tag 'embankment'.
     1866    *
     1867    * @param osmPrimitive
     1868    *            The OSM entity to check.
     1869    */
     1870    public static boolean hasEmbankmentTag(OsmPrimitive osmPrimitive) {
     1871        return osmPrimitive != null ? osmPrimitive.hasKey(EMBANKMENT_TAG)
     1872                : false;
     1873    }
     1874
     1875    /**
     1876    * Gets the value of tag 'embankment'.
     1877    *
     1878    * @param osmPrimitive
     1879    *            The OSM entity to check.
     1880    */
     1881    public static String getEmbankmentValue(OsmPrimitive osmPrimitive) {
     1882        return osmPrimitive != null ? osmPrimitive.get(EMBANKMENT_TAG) : null;
     1883    }
     1884
     1885    /**
     1886    * Checks if the given street supporting housenumbers. Usually motor ways and primary roads have
     1887    * no addresses, also no paths or tracks.
     1888    *
     1889    * @param w the w
     1890    * @return true, if is street supporting housenumbers
     1891    */
     1892    public static boolean isStreetSupportingHousenumbers(Way w) {
     1893        if (w == null) return false;
     1894        if (!hasHighwayTag(w)) {
     1895            return false;
     1896        }
     1897
     1898        // TODO: Should be configurable
     1899
     1900        /* Allow everything until this can be configured */
     1901        return true;
     1902        /*
     1903        String hwType = getHighwayValue(w);
     1904        return  !(TagUtils.HIGHWAY_MOTORWAY_LINK_VALUE.equals(hwType) ||
     1905                TagUtils.HIGHWAY_MOTORWAY_VALUE.equals(hwType) ||
     1906                TagUtils.HIGHWAY_FOOTWAY_VALUE.equals(hwType) ||
     1907                TagUtils.HIGHWAY_TRACK_VALUE.equals(hwType)
     1908                );*/
     1909    }
     1910
     1911    // Relation support
     1912
     1913    /**
     1914    * Check if OSM relation is a 'associatedStreet' relation.
     1915    *
     1916    * @param osmPrimitive
     1917    *            The OSM entity to check.
     1918    */
     1919    public static boolean isAssociatedStreetRelation(Relation rel) {
     1920        return rel != null &&
     1921            rel.hasKey(RELATION_TYPE) &&
     1922            ASSOCIATEDSTREET_RELATION_TYPE.equals(rel.get(RELATION_TYPE));
     1923    }
     1924
     1925    /**
     1926    * Checks if given relation member has role "street".
     1927    *
     1928    * @param relMember the relation member
     1929    * @return true, if is street member
     1930    */
     1931    public static boolean isStreetMember(RelationMember relMember) {
     1932        return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole());
     1933    }
     1934
     1935    /**
     1936    * Checks if given relation member has role "house".
     1937    *
     1938    * @param relMember the relation member
     1939    * @return true, if is street member
     1940    */
     1941    public static boolean isHouseMember(RelationMember relMember) {
     1942        return relMember != null && STREET_RELATION_ROLE.equals(relMember.getRole());
     1943    }
     1944
     1945    /**
     1946    * Checks if "addr:state" tag is required.
     1947    *
     1948    * @return true, if is state required
     1949    */
     1950    public static boolean isStateRequired() {
     1951        String loc = OsmUtils.getLocale();
     1952
     1953        for (int i = 0; i < COUNTRIES_REQUIRE_STATE.length; i++) {
     1954            if (COUNTRIES_REQUIRE_STATE[i].equals(loc)) {
     1955                return true;
     1956            }
     1957        }
     1958
     1959        return false;
     1960    }
     1961
     1962    public static final String PARKING_TAG = "parking";
     1963    public static final String SHOP_TAG = "shop";
     1964    public static final String CRAFT_TAG = "craft";
     1965    public static final String SURFACE_TAG = "surface";
     1966    public static final String CUISINE_TAG = "cuisine";
     1967    public static final String WOOD_TAG = "wood";
     1968    public static final String FOOT_TAG = "foot";
     1969    public static final String NAME_DE_TAG = "name:de";
     1970    public static final String NAT_REF_TAG = "nat_ref";
     1971    public static final String NOTE_DE_TAG = "note:de";
     1972    public static final String ADDR_STREET_TAG = "addr:street";
     1973    public static final String TYPE_TAG = "type";
     1974    public static final String ADDR_CITY_TAG = "addr:city";
     1975    public static final String BOUNDARY_TAG = "boundary";
     1976    public static final String SMOOTHNESS_TAG = "smoothness";
     1977    public static final String OPENING_HOURS_TAG = "opening_hours";
     1978    public static final String BICYCLE_TAG = "bicycle";
     1979    public static final String RELIGION_TAG = "religion";
     1980    public static final String BARRIER_TAG = "barrier";
     1981    public static final String POWER_TAG = "power";
     1982    public static final String LANDUSE_TAG = "landuse";
     1983    public static final String FIREPLACE_TAG = "fireplace";
     1984    public static final String INT_REF_TAG = "int_ref";
     1985    public static final String WHITEWATER_SECTION_GRADE_TAG = "whitewater:section_grade";
     1986    public static final String DENOMINATION_TAG = "denomination";
     1987    public static final String ADDR_POSTCODE_TAG = "addr:postcode";
     1988    public static final String WIRES_TAG = "wires";
     1989    public static final String LOC_REF_TAG = "loc_ref";
     1990    public static final String WIDTH_TAG = "width";
     1991    public static final String TOURISM_TAG = "tourism";
     1992    public static final String LEISURE_TAG = "leisure";
     1993    public static final String ELECTRIFIED_TAG = "electrified";
     1994    public static final String JUNCTION_TAG = "junction";
     1995    public static final String RAILWAY_TAG = "railway";
     1996    public static final String VOLTAGE_TAG = "voltage";
     1997    public static final String BRIDGE_TAG = "bridge";
     1998    public static final String MOTOR_VEHICLE_TAG = "motor_vehicle";
     1999    public static final String COMMENT_TAG = "comment";
     2000    public static final String MAXSPEED_TAG = "maxspeed";
     2001    public static final String NATURAL_TAG = "natural";
     2002    public static final String BUILDING_HEIGHT_TAG = "building:height";
     2003    public static final String SAC_SCALE_TAG = "sac_scale";
     2004    public static final String TUNNEL_TAG = "tunnel";
     2005    public static final String WATERWAY_TAG = "waterway";
     2006    public static final String TRAIL_VISIBILITY_TAG = "trail_visibility";
     2007    public static final String HIGHWAY_TAG = "highway";
     2008    public static final String VEHICLE_TAG = "vehicle";
     2009    public static final String HORSE_TAG = "horse";
     2010    public static final String GOODS_TAG = "goods";
     2011    public static final String FREQUENCY_TAG = "frequency";
     2012    public static final String MAN_MADE_TAG = "man_made";
     2013    public static final String ADDR_HOUSENUMBER_TAG = "addr:housenumber";
     2014    public static final String AREA_TAG = "area";
     2015    public static final String BUILDING_LEVELS_TAG = "building:levels";
     2016    public static final String WHEELCHAIR_TAG = "wheelchair";
     2017    public static final String NAME_TAG = "name";
     2018    public static final String ONEWAY_TAG = "oneway";
     2019    public static final String FIXME_TAG = "FIXME";
     2020    public static final String CAPACITY_TAG = "capacity";
     2021    public static final String MOTORCYCLE_TAG = "motorcycle";
     2022    public static final String HGV_TAG = "hgv";
     2023    public static final String CONSTRUCTION_TAG = "construction";
     2024    public static final String ADDR_STATE_TAG = "addr:state";
     2025    public static final String LANES_TAG = "lanes";
     2026    public static final String NOTE_TAG = "note";
     2027    public static final String LIT_TAG = "lit";
     2028    public static final String BUILDING_TAG = "building";
     2029    public static final String SEGREGATED_TAG = "segregated";
     2030    public static final String ADDR_INCLUSION_TAG = "addr:inclusion";
     2031    public static final String LAYER_TAG = "layer";
     2032    public static final String SPORT_TAG = "sport";
     2033    public static final String ADDR_INTERPOLATION_TAG = "addr:interpolation";
     2034    public static final String CUTTING_TAG = "cutting";
     2035    public static final String AMENITY_TAG = "amenity";
     2036    public static final String ACCESS_TAG = "access";
     2037    public static final String AGRICULTURAL_TAG = "agricultural";
     2038    public static final String CAPACITY_DISABLED_TAG = "capacity:disabled";
     2039    public static final String OPERATOR_TAG = "operator";
     2040    public static final String REF_TAG = "ref";
     2041    public static final String NOEXIT_TAG = "noexit";
     2042    public static final String ADMIN_LEVEL_TAG = "admin_level";
     2043    public static final String SOURCE_TAG = "source";
     2044    public static final String TRACKTYPE_TAG = "tracktype";
     2045    public static final String ADDR_COUNTRY_TAG = "addr:country";
     2046    public static final String ROUTE_TAG = "route";
     2047    public static final String CABLES_TAG = "cables";
     2048    public static final String SERVICE_TAG = "service";
     2049    public static final String MOTORCAR_TAG = "motorcar";
     2050    public static final String WHITEWATER_TAG = "whitewater";
     2051    public static final String EMBANKMENT_TAG = "embankment";
     2052    public static final String ADDR_HOUSENAME_TAG = "addr:housename";
     2053
     2054    /* Highway types */
     2055    public static final String HIGHWAY_CYCLEWAY_VALUE = "cycleway";
     2056    public static final String HIGHWAY_FOOTWAY_VALUE = "footway";
     2057    public static final String HIGHWAY_MOTORWAY_LINK_VALUE = "motorway_link";
     2058    public static final String HIGHWAY_MOTORWAY_VALUE = "motorway";
     2059    public static final String HIGHWAY_PATH_VALUE = "path";
     2060    public static final String HIGHWAY_RESIDENTIAL_VALUE = "residential";
     2061    public static final String HIGHWAY_LIVING_STREET_VALUE = "living_street";
     2062    public static final String HIGHWAY_ROAD_VALUE = "road";
     2063    public static final String HIGHWAY_SECONDARY_VALUE = "secondary";
     2064    public static final String HIGHWAY_SERVICE_VALUE = "service";
     2065    public static final String HIGHWAY_STEPS_VALUE = "steps";
     2066    public static final String HIGHWAY_TERTIARY_VALUE = "tertiary";
     2067    public static final String HIGHWAY_TRACK_VALUE = "track";
     2068    public static final String HIGHWAY_TRUNK_LINK_VALUE = "trunk_link";
     2069    public static final String HIGHWAY_TRUNK_VALUE = "trunk";
     2070    public static final String HIGHWAY_UNCLASSIFIED_VALUE = "unclassified";
     2071
     2072    /* Relation keys */
     2073
     2074    // Associated street: See http://wiki.openstreetmap.org/wiki/Proposed_features/De:Hausnummern
     2075    public static final String RELATION_TYPE = "type";
     2076    public static final String ASSOCIATEDSTREET_RELATION_TYPE = "associatedStreet";
     2077    public static final String STREET_RELATION_ROLE = "street";
     2078    public static final String HOUSE_RELATION_ROLE = "house";
    20912079}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java

    r27322 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    6250@SuppressWarnings("serial")
    6351public class AddressEditDialog extends JDialog implements ActionListener, ListSelectionListener, IAddressEditContainerListener {
    64         private static final String UNRESOLVED_ADDRESS = tr("Unresolved Addresses");
    65         private static final String STREETS = tr("Streets");
    66         private static final String UNRESOLVED_HEADER_FMT = "%s (%d)";
    67         private static final String STREET_HEADER_FMT = "%s (%d)";
    68         private static final String OK_COMMAND = tr("Close");
    69         private static final String SELECT_AND_CLOSE = tr("Select and close");
    70 
    71         private AddressEditContainer editContainer;
    72         private JTable unresolvedTable;
    73         private JTable streetTable;
    74 
    75         private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] {
    76                 AddressActions.getResolveAction(),
    77                 AddressActions.getGuessAddressAction(),
    78                 AddressActions.getApplyGuessesAction(),
    79                 AddressActions.getSelectAction(),
    80                 AddressActions.getRemoveTagsAction(),
    81                 AddressActions.getConvertToRelationAction(),
    82                 AddressActions.getConvertAllToRelationAction()
    83         };
    84        
    85         private JLabel streetLabel;
    86         private JLabel unresolvedAddressesLabel;
    87         private JMapViewer mapViewer;
    88 
    89 
    90         /**
    91         * @param arg0
    92         * @throws HeadlessException
    93         */
    94         public AddressEditDialog(AddressEditContainer addressEditContainer) throws HeadlessException  {
    95                 super(JOptionPane.getFrameForComponent(Main.parent), tr("Fix unresolved addresses"), false);
    96 
    97                 this.editContainer = addressEditContainer;
    98                 this.editContainer.addChangedListener(this);
    99                 setLayout(new BorderLayout());
    100                 setSize(1024,600);
    101                 setLocationRelativeTo(null);
    102 
    103                 if (addressEditContainer != null) {
    104                         /* Panel for street table */
    105                         JPanel streetPanel = new JPanel(new BorderLayout());
    106                         streetTable = new JTable(new StreetTableModel(editContainer));
    107                         streetTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    108                         streetTable.getSelectionModel().addListSelectionListener(this);
    109                         streetTable.addKeyListener(new JumpToEntryListener(1));
    110 
    111                         JScrollPane scroll1 = new JScrollPane(streetTable);
    112                         streetPanel.add(scroll1, BorderLayout.CENTER);
    113 
    114                         streetLabel = createHeaderLabel(STREET_HEADER_FMT,
    115                                         tr(STREETS),
    116                                         editContainer.getNumberOfStreets());
    117 
    118                         JPanel headerPanel = new JPanel(new GridLayout(1, 4));
    119                         headerPanel.setMinimumSize(new Dimension(100, 30));
    120                         headerPanel.add(streetLabel);
    121 
    122                         /*
    123                         JPanel streetButtonPanel = new JPanel(new GridLayout(1, 3));
    124                         SideButton convertToRel = new SideButton(convertToRelationAction);
    125                         streetButtonPanel.add(convertToRel);
    126                         // SideButton convertAllToRel = new SideButton(convertAllToRelationAction);
    127                         // streetButtonPanel.add(convertAllToRel);
    128                         // add filler
    129                         streetButtonPanel.add(new JPanel());
    130                         streetButtonPanel.add(new JPanel());
    131 
    132 
    133                         streetPanel.add(streetButtonPanel, BorderLayout.SOUTH);
    134                         */
    135                         streetPanel.add(headerPanel, BorderLayout.NORTH);
    136                         streetPanel.setMinimumSize(new Dimension(500, 200));
    137 
    138                         /* Panel for unresolved addresses table */
    139                         JPanel unresolvedPanel = new JPanel(new BorderLayout());
    140                         UnresolvedAddressesTableModel uaModel = new UnresolvedAddressesTableModel(editContainer);
    141                         unresolvedTable = new JTable(uaModel);
    142                         unresolvedTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    143                         unresolvedTable.getSelectionModel().addListSelectionListener(this);
    144                         unresolvedTable.getSelectionModel().addListSelectionListener(new IncompleteAddressListener());
    145                         unresolvedTable.addMouseListener(AddressActions.getApplyGuessesAction());
    146 
    147                         JTableHeader header = unresolvedTable.getTableHeader();
    148                         header.addMouseListener(uaModel.new ColumnListener(unresolvedTable));
    149 
    150                         JScrollPane scroll2 = new JScrollPane(unresolvedTable);
    151                         unresolvedPanel.add(scroll2, BorderLayout.CENTER);
    152                         unresolvedAddressesLabel = createHeaderLabel(
    153                                         UNRESOLVED_HEADER_FMT,
    154                                         tr(UNRESOLVED_ADDRESS),
    155                                         editContainer.getNumberOfUnresolvedAddresses());
    156 
    157                         JPanel headerPanel2 = new JPanel(new GridLayout(1, 4));
    158                         headerPanel2.setMinimumSize(new Dimension(100, 30));
    159                         headerPanel2.add(unresolvedAddressesLabel);
    160                         unresolvedPanel.add(headerPanel2 , BorderLayout.NORTH);
    161                         unresolvedPanel.setMinimumSize(new Dimension(500, 200));
    162 
    163 
    164                         try {
    165                                 JPanel unresolvedButtons = new JPanel(new GridLayout(2,5, 5, 5));
    166                                 SideButton assign = new SideButton(AddressActions.getResolveAction());
    167                                 unresolvedButtons.add(assign);
    168 
    169                                 SideButton guess = new SideButton(AddressActions.getGuessAddressAction());
    170                                 unresolvedButtons.add(guess);
    171                                 SideButton applyAllGuesses = new SideButton(AddressActions.getApplyGuessesAction());
    172                                 unresolvedButtons.add(applyAllGuesses);
    173 
    174                                 SideButton removeAddressTags = new SideButton(AddressActions.getRemoveTagsAction());
    175                                 unresolvedButtons.add(removeAddressTags);
    176 
    177                                 unresolvedButtons.add(new JPanel());
    178 
    179                                 SideButton selectInMap = new SideButton(AddressActions.getSelectAction());
    180                                 unresolvedButtons.add(selectInMap);
    181                                 headerPanel2.setMinimumSize(new Dimension(100, 70));
    182 
    183                                 unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH);
    184                         } catch (Exception e) {
    185                                 e.printStackTrace();
    186                         }
    187 
    188                         /* Map Panel */
    189                         JPanel mapPanel = new JPanel(new BorderLayout());
    190                         mapViewer = new JMapViewer();
    191                         mapPanel.add(mapViewer, BorderLayout.CENTER);
    192                         mapPanel.setMinimumSize(new Dimension(200, 200));
    193                         mapViewer.setVisible(false);
    194 
    195                         JPanel mapControl = new JPanel(new GridLayout(1, 4));
    196                         JLabel mapL1 = new JLabel(tr("Complete Addresses"));
    197                         mapL1.setForeground(Color.BLUE);
    198                         mapControl.add(mapL1);
    199 
    200                         JLabel mapL2 = new JLabel(tr("Incomplete Addresses"));
    201                         mapL2.setForeground(Color.RED);
    202                         mapControl.add(mapL2);
    203 
    204                         JLabel mapL3 = new JLabel(tr("Selected Addresses"));
    205                         mapL3.setForeground(Color.ORANGE);
    206                         mapControl.add(mapL3);
    207 
    208                         JLabel mapL4 = new JLabel(tr("Selected Street"));
    209                         mapL4.setForeground(Color.GREEN);
    210                         mapControl.add(mapL4);
    211 
    212                         mapPanel.add(mapControl, BorderLayout.SOUTH);
    213 
    214                         /* Combine panels */
    215                         JSplitPane unresSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, streetPanel, unresolvedPanel);
    216                         JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresSplitPane, mapPanel);
    217 
    218                         this.getContentPane().add(pane, BorderLayout.CENTER);
    219                         //this.getContentPane().add(mapPanel, BorderLayout.SOUTH);
    220                 } else {
    221                         this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER);
    222                 }
    223 
    224                 for (int i = 0; i < actions.length; i++) {
    225                         actions[i].setContainer(addressEditContainer);
    226                 }
    227 
    228                 JPanel buttonPanel = new JPanel(new GridLayout(1,10));
    229                 JButton ok = new JButton(OK_COMMAND, ImageProvider.getIfAvailable(null, "ok"));
    230                 ok.addActionListener(this);
    231                 JButton selectAndClose = new JButton(SELECT_AND_CLOSE);
    232                 selectAndClose.addActionListener(this);
    233 
    234                 // Murks
    235                 for (int i = 0; i < 8; i++) {
    236                         buttonPanel.add(new JSeparator());
    237                 }
    238 
    239                 buttonPanel.add(ok);
    240 
    241 
    242                 this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    243         }
    244 
    245         /**
    246         * Creates a header label in the form "title (number)" with bold font.
    247         * @param fmtString The format string having a string and a numeric placeholder.
    248         * @param title The title of the header.
    249         * @param n The number to show in the header.
    250         * @return
    251         */
    252         private JLabel createHeaderLabel(String fmtString, String title, int n) {
    253                 JLabel label = new JLabel(String.format(fmtString, title, n));
    254                 label.setFont(label.getFont().deriveFont(Font.BOLD, label.getFont().getSize() + 2));
    255                 label.setBorder(new EmptyBorder(5,2,4,5));
    256                 return label;
    257         }
    258 
    259         /**
    260         * Updates the list headings.
    261         */
    262         private void updateHeaders() {
    263                 if (editContainer != null) {
    264                         streetLabel.setText(String.format(
    265                                         STREET_HEADER_FMT,
    266                                         STREETS,
    267                                         editContainer.getNumberOfStreets()));
    268                         unresolvedAddressesLabel.setText(
    269                                         String.format(UNRESOLVED_HEADER_FMT,
    270                                                         UNRESOLVED_ADDRESS,
    271                                                         editContainer.getNumberOfUnresolvedAddresses()));
    272                 } else {
    273                         streetLabel.setText(String.format(STREET_HEADER_FMT, 0));
    274                         unresolvedAddressesLabel.setText(String.format(UNRESOLVED_HEADER_FMT, 0));
    275                 }
    276         }
    277 
    278         @Override
    279         public void actionPerformed(ActionEvent e) {
    280                 if (OK_COMMAND.equals(e.getActionCommand())) {
    281                         this.setVisible(false);
    282                 }
    283         }
    284 
    285         @Override
    286         public void valueChanged(ListSelectionEvent e) {
    287 
    288                 AddressEditSelectionEvent ev = new AddressEditSelectionEvent(e.getSource(),
    289                                 streetTable, unresolvedTable, null, editContainer);
    290 
    291                 for (AbstractAddressEditAction action : actions) {
    292                         action.setEvent(ev);
    293                 }
    294 
    295                 clearMapViewer();
    296                 OSMStreet sNode = ev.getSelectedStreet();
    297                 if (sNode != null) {
    298 
    299                         //mapViewer.addMapRectangle(new BBoxMapRectangle(bb));
    300                         for (IOSMEntity seg : sNode.getChildren()) {
    301                                 Way way = (Way) seg.getOsmObject();
    302                                 //BBox bb = way.getBBox();
    303 
    304                                 for (Node node : way.getNodes()) {
    305                                         mapViewer.addMapMarker(new MapMarkerDot(Color.GREEN, node.getCoor().lat(), node.getCoor().lon()));
    306                                 }
    307                         }
    308 
    309                         // show addresses as blue marker
    310                         if (sNode.hasAddresses()) {
    311                                 for (OSMAddress aNode : sNode.getAddresses()) {
    312                                         Color markerCol = Color.BLUE;
    313                                         if (!aNode.isComplete()) {
    314                                                 markerCol = Color.RED;
    315                                         }
    316                                         mapViewer.addMapMarker(new MapMarkerDot(markerCol, aNode.getCoor().lat(), aNode.getCoor().lon()));
    317                                 }
    318                         }
    319                 }
    320 
    321                 List<OSMAddress> unrAddresses = ev.getSelectedUnresolvedAddresses();
    322                 if (unrAddresses != null) {
    323                         for (OSMAddress aNode : unrAddresses) {
    324                                 mapViewer.addMapMarker(new MapMarkerDot(Color.ORANGE, aNode.getCoor().lat(), aNode.getCoor().lon()));
    325                         }
    326                 }
    327                 mapViewer.setDisplayToFitMapMarkers();
    328                 mapViewer.setVisible(true);
    329         }
    330 
    331         /**
    332         * Removes all markers and rectangles from the map viewer.
    333         */
    334         private void clearMapViewer() {
    335                 mapViewer.setVisible(false);
    336                 // remove markers and rectangles from map viewer
    337                 mapViewer.getMapMarkerList().clear();
    338                 mapViewer.getMapRectangleList().clear();
    339         }
    340 
    341         @Override
    342         public void containerChanged(AddressEditContainer container) {
    343                 updateHeaders();
    344 
    345                 for (int i = 0; i < actions.length; i++) {
    346                         actions[i].setEvent(null);
    347                         actions[i].setContainer(container);
    348                 }
    349         }
    350 
    351         @Override
    352         public void entityChanged(IOSMEntity entity) {
    353                 updateHeaders();
    354         }
    355 
    356         /**
    357         * Special listener to react on selection changes in the incomplete address list.
    358         * It searches the street table for the streets which matches best matching to the
    359         * street name given in the address.
    360         *
    361         * @author Oliver Wieland <oliver.wieland@online.de>
    362         */
    363         class IncompleteAddressListener implements ListSelectionListener {
    364 
    365                 @Override
    366                 public void valueChanged(ListSelectionEvent e) {
    367                         if (unresolvedTable.getSelectedRowCount() == 1) {
    368                                 String streetOfAddr = (String) unresolvedTable.
    369                                                                                         getModel().getValueAt(unresolvedTable.getSelectedRow(), 0);
    370 
    371                                 int maxScore = 0, score = 0, row = -1;
    372                                 for (int i = 0; i < streetTable.getRowCount(); i++) {
    373                                         String streetName = (String) streetTable.getModel().getValueAt(i, 1);
    374 
    375                                         score = StringUtils.lcsLength(streetOfAddr, streetName);
    376                                         if (score > maxScore) {
    377                                                 maxScore = score;
    378                                                 row = i;
    379                                         }
    380                                 }
    381 
    382                                 if (row > 0) {
    383                                         streetTable.getSelectionModel().clearSelection();
    384                                         streetTable.getSelectionModel().addSelectionInterval(row, row);
    385                                         streetTable.scrollRectToVisible(streetTable.getCellRect(row, 0, true));
    386                                 }
    387                         }
    388                 }
    389 
    390         }
    391 
    392         /**
    393         * The listener interface for receiving key events of a table.
    394         * The class that is interested in processing a jumpToEntry
    395         * event implements this interface, and the object created
    396         * with that class is registered with a component using the
    397         * component's <code>addJumpToEntryListener<code> method. When
    398         * the jumpToEntry event occurs, that object's appropriate
    399         * method is invoked.
    400         *
    401         * @see JumpToEntryEvent
    402         */
    403         class JumpToEntryListener implements KeyListener {
    404                 private int column;
    405 
    406                 /**
    407                 * Instantiates a new jump-to-entry listener.
    408                 * @param column the column of the table to use for the comparison
    409                 */
    410                 public JumpToEntryListener(int column) {
    411                         super();
    412                         this.column = column;
    413                 }
    414 
    415                 @Override
    416                 public void keyPressed(KeyEvent arg0) {
    417                         // TODO Auto-generated method stub
    418 
    419                 }
    420 
    421                 @Override
    422                 public void keyReleased(KeyEvent arg0) {
    423                         // TODO Auto-generated method stub
    424 
    425                 }
    426 
    427                 @Override
    428                 public void keyTyped(KeyEvent arg0) {
    429                         JTable table  = (JTable) arg0.getSource();
    430 
    431                         if (table == null) return;
    432 
    433                         TableModel model = table.getModel();
    434 
    435                         if (model == null || model.getColumnCount() == 0) {
    436                                 return;
    437                         }
    438                         // clip column
    439                         if (column < 0 || column >= model.getColumnCount()) {
    440                                 column = 0; // use the first column
    441                         }
    442 
    443                         char firstChar = Character.toLowerCase(arg0.getKeyChar());
    444 
    445                         // visit every row and find a matching entry
    446                         for (int i = 0; i < model.getRowCount(); i++) {
    447                                 Object obj = model.getValueAt(i, column);
    448                                 if (obj != null) {
    449                                         String s = obj.toString();
    450                                         if (s.length() > 0 && firstChar == Character.toLowerCase(s.charAt(0))) {
    451                                                 // select entry and make it visible in the table
    452                                                 table.getSelectionModel().setSelectionInterval(i, i);
    453                                                 table.scrollRectToVisible(streetTable.getCellRect(i, 0, true));
    454                                                 return;
    455                                         }
    456                                 }
    457                         }
    458                 }
    459         }
     52    private static final String UNRESOLVED_ADDRESS = tr("Unresolved Addresses");
     53    private static final String STREETS = tr("Streets");
     54    private static final String UNRESOLVED_HEADER_FMT = "%s (%d)";
     55    private static final String STREET_HEADER_FMT = "%s (%d)";
     56    private static final String OK_COMMAND = tr("Close");
     57    private static final String SELECT_AND_CLOSE = tr("Select and close");
     58
     59    private AddressEditContainer editContainer;
     60    private JTable unresolvedTable;
     61    private JTable streetTable;
     62
     63    private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] {
     64        AddressActions.getResolveAction(),
     65        AddressActions.getGuessAddressAction(),
     66        AddressActions.getApplyGuessesAction(),
     67        AddressActions.getSelectAction(),
     68        AddressActions.getRemoveTagsAction(),
     69        AddressActions.getConvertToRelationAction(),
     70        AddressActions.getConvertAllToRelationAction()
     71    };
     72   
     73    private JLabel streetLabel;
     74    private JLabel unresolvedAddressesLabel;
     75    private JMapViewer mapViewer;
     76
     77
     78    /**
     79    * @param arg0
     80    * @throws HeadlessException
     81    */
     82    public AddressEditDialog(AddressEditContainer addressEditContainer) throws HeadlessException  {
     83        super(JOptionPane.getFrameForComponent(Main.parent), tr("Fix unresolved addresses"), false);
     84
     85        this.editContainer = addressEditContainer;
     86        this.editContainer.addChangedListener(this);
     87        setLayout(new BorderLayout());
     88        setSize(1024,600);
     89        setLocationRelativeTo(null);
     90
     91        if (addressEditContainer != null) {
     92            /* Panel for street table */
     93            JPanel streetPanel = new JPanel(new BorderLayout());
     94            streetTable = new JTable(new StreetTableModel(editContainer));
     95            streetTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     96            streetTable.getSelectionModel().addListSelectionListener(this);
     97            streetTable.addKeyListener(new JumpToEntryListener(1));
     98
     99            JScrollPane scroll1 = new JScrollPane(streetTable);
     100            streetPanel.add(scroll1, BorderLayout.CENTER);
     101
     102            streetLabel = createHeaderLabel(STREET_HEADER_FMT,
     103                    tr(STREETS),
     104                    editContainer.getNumberOfStreets());
     105
     106            JPanel headerPanel = new JPanel(new GridLayout(1, 4));
     107            headerPanel.setMinimumSize(new Dimension(100, 30));
     108            headerPanel.add(streetLabel);
     109
     110            /*
     111            JPanel streetButtonPanel = new JPanel(new GridLayout(1, 3));
     112            SideButton convertToRel = new SideButton(convertToRelationAction);
     113            streetButtonPanel.add(convertToRel);
     114            // SideButton convertAllToRel = new SideButton(convertAllToRelationAction);
     115            // streetButtonPanel.add(convertAllToRel);
     116            // add filler
     117            streetButtonPanel.add(new JPanel());
     118            streetButtonPanel.add(new JPanel());
     119
     120
     121            streetPanel.add(streetButtonPanel, BorderLayout.SOUTH);
     122            */
     123            streetPanel.add(headerPanel, BorderLayout.NORTH);
     124            streetPanel.setMinimumSize(new Dimension(500, 200));
     125
     126            /* Panel for unresolved addresses table */
     127            JPanel unresolvedPanel = new JPanel(new BorderLayout());
     128            UnresolvedAddressesTableModel uaModel = new UnresolvedAddressesTableModel(editContainer);
     129            unresolvedTable = new JTable(uaModel);
     130            unresolvedTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     131            unresolvedTable.getSelectionModel().addListSelectionListener(this);
     132            unresolvedTable.getSelectionModel().addListSelectionListener(new IncompleteAddressListener());
     133            unresolvedTable.addMouseListener(AddressActions.getApplyGuessesAction());
     134
     135            JTableHeader header = unresolvedTable.getTableHeader();
     136            header.addMouseListener(uaModel.new ColumnListener(unresolvedTable));
     137
     138            JScrollPane scroll2 = new JScrollPane(unresolvedTable);
     139            unresolvedPanel.add(scroll2, BorderLayout.CENTER);
     140            unresolvedAddressesLabel = createHeaderLabel(
     141                    UNRESOLVED_HEADER_FMT,
     142                    tr(UNRESOLVED_ADDRESS),
     143                    editContainer.getNumberOfUnresolvedAddresses());
     144
     145            JPanel headerPanel2 = new JPanel(new GridLayout(1, 4));
     146            headerPanel2.setMinimumSize(new Dimension(100, 30));
     147            headerPanel2.add(unresolvedAddressesLabel);
     148            unresolvedPanel.add(headerPanel2 , BorderLayout.NORTH);
     149            unresolvedPanel.setMinimumSize(new Dimension(500, 200));
     150
     151
     152            try {
     153                JPanel unresolvedButtons = new JPanel(new GridLayout(2,5, 5, 5));
     154                SideButton assign = new SideButton(AddressActions.getResolveAction());
     155                unresolvedButtons.add(assign);
     156
     157                SideButton guess = new SideButton(AddressActions.getGuessAddressAction());
     158                unresolvedButtons.add(guess);
     159                SideButton applyAllGuesses = new SideButton(AddressActions.getApplyGuessesAction());
     160                unresolvedButtons.add(applyAllGuesses);
     161
     162                SideButton removeAddressTags = new SideButton(AddressActions.getRemoveTagsAction());
     163                unresolvedButtons.add(removeAddressTags);
     164
     165                unresolvedButtons.add(new JPanel());
     166
     167                SideButton selectInMap = new SideButton(AddressActions.getSelectAction());
     168                unresolvedButtons.add(selectInMap);
     169                headerPanel2.setMinimumSize(new Dimension(100, 70));
     170
     171                unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH);
     172            } catch (Exception e) {
     173                e.printStackTrace();
     174            }
     175
     176            /* Map Panel */
     177            JPanel mapPanel = new JPanel(new BorderLayout());
     178            mapViewer = new JMapViewer();
     179            mapPanel.add(mapViewer, BorderLayout.CENTER);
     180            mapPanel.setMinimumSize(new Dimension(200, 200));
     181            mapViewer.setVisible(false);
     182
     183            JPanel mapControl = new JPanel(new GridLayout(1, 4));
     184            JLabel mapL1 = new JLabel(tr("Complete Addresses"));
     185            mapL1.setForeground(Color.BLUE);
     186            mapControl.add(mapL1);
     187
     188            JLabel mapL2 = new JLabel(tr("Incomplete Addresses"));
     189            mapL2.setForeground(Color.RED);
     190            mapControl.add(mapL2);
     191
     192            JLabel mapL3 = new JLabel(tr("Selected Addresses"));
     193            mapL3.setForeground(Color.ORANGE);
     194            mapControl.add(mapL3);
     195
     196            JLabel mapL4 = new JLabel(tr("Selected Street"));
     197            mapL4.setForeground(Color.GREEN);
     198            mapControl.add(mapL4);
     199
     200            mapPanel.add(mapControl, BorderLayout.SOUTH);
     201
     202            /* Combine panels */
     203            JSplitPane unresSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, streetPanel, unresolvedPanel);
     204            JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, unresSplitPane, mapPanel);
     205
     206            this.getContentPane().add(pane, BorderLayout.CENTER);
     207            //this.getContentPane().add(mapPanel, BorderLayout.SOUTH);
     208        } else {
     209            this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER);
     210        }
     211
     212        for (int i = 0; i < actions.length; i++) {
     213            actions[i].setContainer(addressEditContainer);
     214        }
     215
     216        JPanel buttonPanel = new JPanel(new GridLayout(1,10));
     217        JButton ok = new JButton(OK_COMMAND, ImageProvider.getIfAvailable(null, "ok"));
     218        ok.addActionListener(this);
     219        JButton selectAndClose = new JButton(SELECT_AND_CLOSE);
     220        selectAndClose.addActionListener(this);
     221
     222        // Murks
     223        for (int i = 0; i < 8; i++) {
     224            buttonPanel.add(new JSeparator());
     225        }
     226
     227        buttonPanel.add(ok);
     228
     229
     230        this.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
     231    }
     232
     233    /**
     234    * Creates a header label in the form "title (number)" with bold font.
     235    * @param fmtString The format string having a string and a numeric placeholder.
     236    * @param title The title of the header.
     237    * @param n The number to show in the header.
     238    * @return
     239    */
     240    private JLabel createHeaderLabel(String fmtString, String title, int n) {
     241        JLabel label = new JLabel(String.format(fmtString, title, n));
     242        label.setFont(label.getFont().deriveFont(Font.BOLD, label.getFont().getSize() + 2));
     243        label.setBorder(new EmptyBorder(5,2,4,5));
     244        return label;
     245    }
     246
     247    /**
     248    * Updates the list headings.
     249    */
     250    private void updateHeaders() {
     251        if (editContainer != null) {
     252            streetLabel.setText(String.format(
     253                    STREET_HEADER_FMT,
     254                    STREETS,
     255                    editContainer.getNumberOfStreets()));
     256            unresolvedAddressesLabel.setText(
     257                    String.format(UNRESOLVED_HEADER_FMT,
     258                            UNRESOLVED_ADDRESS,
     259                            editContainer.getNumberOfUnresolvedAddresses()));
     260        } else {
     261            streetLabel.setText(String.format(STREET_HEADER_FMT, 0));
     262            unresolvedAddressesLabel.setText(String.format(UNRESOLVED_HEADER_FMT, 0));
     263        }
     264    }
     265
     266    @Override
     267    public void actionPerformed(ActionEvent e) {
     268        if (OK_COMMAND.equals(e.getActionCommand())) {
     269            this.setVisible(false);
     270        }
     271    }
     272
     273    @Override
     274    public void valueChanged(ListSelectionEvent e) {
     275
     276        AddressEditSelectionEvent ev = new AddressEditSelectionEvent(e.getSource(),
     277                streetTable, unresolvedTable, null, editContainer);
     278
     279        for (AbstractAddressEditAction action : actions) {
     280            action.setEvent(ev);
     281        }
     282
     283        clearMapViewer();
     284        OSMStreet sNode = ev.getSelectedStreet();
     285        if (sNode != null) {
     286
     287            //mapViewer.addMapRectangle(new BBoxMapRectangle(bb));
     288            for (IOSMEntity seg : sNode.getChildren()) {
     289                Way way = (Way) seg.getOsmObject();
     290                //BBox bb = way.getBBox();
     291
     292                for (Node node : way.getNodes()) {
     293                    mapViewer.addMapMarker(new MapMarkerDot(Color.GREEN, node.getCoor().lat(), node.getCoor().lon()));
     294                }
     295            }
     296
     297            // show addresses as blue marker
     298            if (sNode.hasAddresses()) {
     299                for (OSMAddress aNode : sNode.getAddresses()) {
     300                    Color markerCol = Color.BLUE;
     301                    if (!aNode.isComplete()) {
     302                        markerCol = Color.RED;
     303                    }
     304                    mapViewer.addMapMarker(new MapMarkerDot(markerCol, aNode.getCoor().lat(), aNode.getCoor().lon()));
     305                }
     306            }
     307        }
     308
     309        List<OSMAddress> unrAddresses = ev.getSelectedUnresolvedAddresses();
     310        if (unrAddresses != null) {
     311            for (OSMAddress aNode : unrAddresses) {
     312                mapViewer.addMapMarker(new MapMarkerDot(Color.ORANGE, aNode.getCoor().lat(), aNode.getCoor().lon()));
     313            }
     314        }
     315        mapViewer.setDisplayToFitMapMarkers();
     316        mapViewer.setVisible(true);
     317    }
     318
     319    /**
     320    * Removes all markers and rectangles from the map viewer.
     321    */
     322    private void clearMapViewer() {
     323        mapViewer.setVisible(false);
     324        // remove markers and rectangles from map viewer
     325        mapViewer.getMapMarkerList().clear();
     326        mapViewer.getMapRectangleList().clear();
     327    }
     328
     329    @Override
     330    public void containerChanged(AddressEditContainer container) {
     331        updateHeaders();
     332
     333        for (int i = 0; i < actions.length; i++) {
     334            actions[i].setEvent(null);
     335            actions[i].setContainer(container);
     336        }
     337    }
     338
     339    @Override
     340    public void entityChanged(IOSMEntity entity) {
     341        updateHeaders();
     342    }
     343
     344    /**
     345    * Special listener to react on selection changes in the incomplete address list.
     346    * It searches the street table for the streets which matches best matching to the
     347    * street name given in the address.
     348    *
     349    * @author Oliver Wieland <oliver.wieland@online.de>
     350    */
     351    class IncompleteAddressListener implements ListSelectionListener {
     352
     353        @Override
     354        public void valueChanged(ListSelectionEvent e) {
     355            if (unresolvedTable.getSelectedRowCount() == 1) {
     356                String streetOfAddr = (String) unresolvedTable.
     357                                            getModel().getValueAt(unresolvedTable.getSelectedRow(), 0);
     358
     359                int maxScore = 0, score = 0, row = -1;
     360                for (int i = 0; i < streetTable.getRowCount(); i++) {
     361                    String streetName = (String) streetTable.getModel().getValueAt(i, 1);
     362
     363                    score = StringUtils.lcsLength(streetOfAddr, streetName);
     364                    if (score > maxScore) {
     365                        maxScore = score;
     366                        row = i;
     367                    }
     368                }
     369
     370                if (row > 0) {
     371                    streetTable.getSelectionModel().clearSelection();
     372                    streetTable.getSelectionModel().addSelectionInterval(row, row);
     373                    streetTable.scrollRectToVisible(streetTable.getCellRect(row, 0, true));
     374                }
     375            }
     376        }
     377
     378    }
     379
     380    /**
     381    * The listener interface for receiving key events of a table.
     382    * The class that is interested in processing a jumpToEntry
     383    * event implements this interface, and the object created
     384    * with that class is registered with a component using the
     385    * component's <code>addJumpToEntryListener<code> method. When
     386    * the jumpToEntry event occurs, that object's appropriate
     387    * method is invoked.
     388    *
     389    * @see JumpToEntryEvent
     390    */
     391    class JumpToEntryListener implements KeyListener {
     392        private int column;
     393
     394        /**
     395        * Instantiates a new jump-to-entry listener.
     396        * @param column the column of the table to use for the comparison
     397        */
     398        public JumpToEntryListener(int column) {
     399            super();
     400            this.column = column;
     401        }
     402
     403        @Override
     404        public void keyPressed(KeyEvent arg0) {
     405            // TODO Auto-generated method stub
     406
     407        }
     408
     409        @Override
     410        public void keyReleased(KeyEvent arg0) {
     411            // TODO Auto-generated method stub
     412
     413        }
     414
     415        @Override
     416        public void keyTyped(KeyEvent arg0) {
     417            JTable table  = (JTable) arg0.getSource();
     418
     419            if (table == null) return;
     420
     421            TableModel model = table.getModel();
     422
     423            if (model == null || model.getColumnCount() == 0) {
     424                return;
     425            }
     426            // clip column
     427            if (column < 0 || column >= model.getColumnCount()) {
     428                column = 0; // use the first column
     429            }
     430
     431            char firstChar = Character.toLowerCase(arg0.getKeyChar());
     432
     433            // visit every row and find a matching entry
     434            for (int i = 0; i < model.getRowCount(); i++) {
     435                Object obj = model.getValueAt(i, column);
     436                if (obj != null) {
     437                    String s = obj.toString();
     438                    if (s.length() > 0 && firstChar == Character.toLowerCase(s.charAt(0))) {
     439                        // select entry and make it visible in the table
     440                        table.getSelectionModel().setSelectionInterval(i, i);
     441                        table.scrollRectToVisible(streetTable.getCellRect(i, 0, true));
     442                        return;
     443                    }
     444                }
     445            }
     446        }
     447    }
    460448}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditModel.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    2715
    2816public class AddressEditModel {
    29         private List<OSMStreet> streets;
    30         private List<OSMAddress> unresolvedAddresses;
    31         private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>();
    32         private DefaultMutableTreeNode streetRoot;
    33         private DefaultMutableTreeNode unresolvedRoot;
    34         private DefaultMutableTreeNode incompleteRoot;
     17    private List<OSMStreet> streets;
     18    private List<OSMAddress> unresolvedAddresses;
     19    private List<OSMAddress> incompleteAddresses = new ArrayList<OSMAddress>();
     20    private DefaultMutableTreeNode streetRoot;
     21    private DefaultMutableTreeNode unresolvedRoot;
     22    private DefaultMutableTreeNode incompleteRoot;
    3523
    36         /**
    37         * @param streets
    38         * @param unresolvedAddresses
    39         */
    40         public AddressEditModel(List<OSMStreet> streets,
    41                         List<OSMAddress> unresolvedAddresses) {
    42                 super();
    43                 this.streets = streets;
    44                 this.unresolvedAddresses = unresolvedAddresses;
    45         }
     24    /**
     25    * @param streets
     26    * @param unresolvedAddresses
     27    */
     28    public AddressEditModel(List<OSMStreet> streets,
     29            List<OSMAddress> unresolvedAddresses) {
     30        super();
     31        this.streets = streets;
     32        this.unresolvedAddresses = unresolvedAddresses;
     33    }
    4634
    47         public TreeNode getStreetsTree() {
    48                 if (streets == null) return new DefaultMutableTreeNode(tr("(No data)"));
     35    public TreeNode getStreetsTree() {
     36        if (streets == null) return new DefaultMutableTreeNode(tr("(No data)"));
    4937
    50                 if (streetRoot == null) {
    51                         streetRoot = new DefaultMutableTreeNode();
    52                         for (OSMStreet sNode : streets) {
    53                                 DefaultMutableTreeNode treeStreetNode = new DefaultMutableTreeNode(sNode);
     38        if (streetRoot == null) {
     39            streetRoot = new DefaultMutableTreeNode();
     40            for (OSMStreet sNode : streets) {
     41                DefaultMutableTreeNode treeStreetNode = new DefaultMutableTreeNode(sNode);
    5442
    55                                 DefaultMutableTreeNode segmentsNode = new DefaultMutableTreeNode(tr("Segments"));
    56                                 treeStreetNode.add(segmentsNode);
     43                DefaultMutableTreeNode segmentsNode = new DefaultMutableTreeNode(tr("Segments"));
     44                treeStreetNode.add(segmentsNode);
    5745
    58                                 // Add street segment(s)
    59                                 for (IOSMEntity child : sNode.getChildren()) {
    60                                         segmentsNode.add(new DefaultMutableTreeNode(child));
    61                                 }
     46                // Add street segment(s)
     47                for (IOSMEntity child : sNode.getChildren()) {
     48                    segmentsNode.add(new DefaultMutableTreeNode(child));
     49                }
    6250
    63                                 if (sNode.hasAddresses()) {
    64                                         // Add address nodes
    65                                         DefaultMutableTreeNode addressNode = new DefaultMutableTreeNode(tr("Addresses"));
    66                                         treeStreetNode.add(addressNode);
     51                if (sNode.hasAddresses()) {
     52                    // Add address nodes
     53                    DefaultMutableTreeNode addressNode = new DefaultMutableTreeNode(tr("Addresses"));
     54                    treeStreetNode.add(addressNode);
    6755
    68                                         for (OSMAddress addr : sNode.getAddresses()) {
    69                                                 addressNode.add(new DefaultMutableTreeNode(addr));
    70                                                 if (!addr.isComplete()) {
    71                                                         incompleteAddresses.add(addr);
    72                                                 }
    73                                         }
    74                                 }
    75                                 streetRoot.add(treeStreetNode);
    76                         }
    77                 }
     56                    for (OSMAddress addr : sNode.getAddresses()) {
     57                        addressNode.add(new DefaultMutableTreeNode(addr));
     58                        if (!addr.isComplete()) {
     59                            incompleteAddresses.add(addr);
     60                        }
     61                    }
     62                }
     63                streetRoot.add(treeStreetNode);
     64            }
     65        }
    7866
    79                 return streetRoot;
    80         }
     67        return streetRoot;
     68    }
    8169
    82         /**
    83         * Gets the tree node containing all unresolved addresses.
    84         * @return
    85         */
    86         public TreeNode getUnresolvedAddressesTree() {
    87                 if (unresolvedAddresses == null) return new DefaultMutableTreeNode(tr("(No data)"));
     70    /**
     71    * Gets the tree node containing all unresolved addresses.
     72    * @return
     73    */
     74    public TreeNode getUnresolvedAddressesTree() {
     75        if (unresolvedAddresses == null) return new DefaultMutableTreeNode(tr("(No data)"));
    8876
    89                 if (unresolvedRoot == null) {
    90                         unresolvedRoot = new DefaultMutableTreeNode();
     77        if (unresolvedRoot == null) {
     78            unresolvedRoot = new DefaultMutableTreeNode();
    9179
    92                         for (OSMAddress addr : unresolvedAddresses) {
    93                                 // Add address nodes
    94                                 unresolvedRoot.add(new DefaultMutableTreeNode(addr));
    95                         }
    96                 }
     80            for (OSMAddress addr : unresolvedAddresses) {
     81                // Add address nodes
     82                unresolvedRoot.add(new DefaultMutableTreeNode(addr));
     83            }
     84        }
    9785
    98                 return unresolvedRoot;
    99         }
     86        return unresolvedRoot;
     87    }
    10088
    101         /**
    102         * Gets the tree node containing all incomplete addresses.
    103         * @return
    104         */
    105         public TreeNode getIncompleteAddressesTree() {
    106                 if (incompleteAddresses == null) return new DefaultMutableTreeNode(tr("(No data)"));
     89    /**
     90    * Gets the tree node containing all incomplete addresses.
     91    * @return
     92    */
     93    public TreeNode getIncompleteAddressesTree() {
     94        if (incompleteAddresses == null) return new DefaultMutableTreeNode(tr("(No data)"));
    10795
    108                 if (incompleteRoot == null) {
    109                         incompleteRoot = new DefaultMutableTreeNode();
     96        if (incompleteRoot == null) {
     97            incompleteRoot = new DefaultMutableTreeNode();
    11098
    111                         for (OSMAddress addr : incompleteAddresses) {
    112                                 // Add address nodes
    113                                 incompleteRoot.add(new DefaultMutableTreeNode(addr));
    114                         }
    115                 }
     99            for (OSMAddress addr : incompleteAddresses) {
     100                // Add address nodes
     101                incompleteRoot.add(new DefaultMutableTreeNode(addr));
     102            }
     103        }
    116104
    117                 return incompleteRoot;
    118         }
     105        return incompleteRoot;
     106    }
    119107}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditSelectionEvent.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    2513
    2614public class AddressEditSelectionEvent extends ActionEvent {
    27         /**
    28         *
    29         */
    30         private static final long serialVersionUID = -93034483427803409L;
    31         private JTable streetTable;
    32         private JTable unresolvedAddressTable;
    33         private JTable incompleteAddressTable;
    34         private AddressEditContainer addressContainer;
     15    /**
     16    *
     17    */
     18    private static final long serialVersionUID = -93034483427803409L;
     19    private JTable streetTable;
     20    private JTable unresolvedAddressTable;
     21    private JTable incompleteAddressTable;
     22    private AddressEditContainer addressContainer;
    3523
    36         private List<OSMAddress> unresolvedCache;
    37         private List<OSMAddress> incompleteCache;
     24    private List<OSMAddress> unresolvedCache;
     25    private List<OSMAddress> incompleteCache;
    3826
    39         /**
    40         * Creates a new 'AddressEditSelectionEvent'.
    41         * @param source The event source.
    42         * @param selStreet The street table component.
    43         * @param unresolvedAddresses The unresolved addresses table component.
    44         * @param incomplete The incomplete addresses table component.
    45         * @param container The address container instance holding the entities for streets and addresses.
    46         */
    47         public AddressEditSelectionEvent(Object source, JTable selStreet, JTable unresolvedAddresses, JTable incompleteAddresses, AddressEditContainer container) {
    48                 super(source, -1, "");
    49                 this.streetTable = selStreet;
    50                 this.unresolvedAddressTable = unresolvedAddresses;
    51                 this.incompleteAddressTable = incompleteAddresses;
    52                 this.addressContainer = container;
    53         }
     27    /**
     28    * Creates a new 'AddressEditSelectionEvent'.
     29    * @param source The event source.
     30    * @param selStreet The street table component.
     31    * @param unresolvedAddresses The unresolved addresses table component.
     32    * @param incomplete The incomplete addresses table component.
     33    * @param container The address container instance holding the entities for streets and addresses.
     34    */
     35    public AddressEditSelectionEvent(Object source, JTable selStreet, JTable unresolvedAddresses, JTable incompleteAddresses, AddressEditContainer container) {
     36        super(source, -1, "");
     37        this.streetTable = selStreet;
     38        this.unresolvedAddressTable = unresolvedAddresses;
     39        this.incompleteAddressTable = incompleteAddresses;
     40        this.addressContainer = container;
     41    }
    5442
    55         /**
    56         * Gets the street table component.
    57         * @return
    58         */
    59         public JTable getStreetTable() {
    60                 return streetTable;
    61         }
     43    /**
     44    * Gets the street table component.
     45    * @return
     46    */
     47    public JTable getStreetTable() {
     48        return streetTable;
     49    }
    6250
    63         /**
    64         * Gets the 'unresolved addresses' table component.
    65         * @return
    66         */
    67         public JTable getUnresolvedAddressTable() {
    68                 return unresolvedAddressTable;
    69         }
     51    /**
     52    * Gets the 'unresolved addresses' table component.
     53    * @return
     54    */
     55    public JTable getUnresolvedAddressTable() {
     56        return unresolvedAddressTable;
     57    }
    7058
    71         /**
    72         * @return the incompleteAddressTable
    73         */
    74         protected JTable getIncompleteAddressTable() {
    75                 return incompleteAddressTable;
    76         }
     59    /**
     60    * @return the incompleteAddressTable
     61    */
     62    protected JTable getIncompleteAddressTable() {
     63        return incompleteAddressTable;
     64    }
    7765
    78         /**
    79         * Gets the address container.
    80         *
    81         * @return the address container
    82         */
    83         public AddressEditContainer getAddressContainer() {
    84                 return addressContainer;
    85         }
     66    /**
     67    * Gets the address container.
     68    *
     69    * @return the address container
     70    */
     71    public AddressEditContainer getAddressContainer() {
     72        return addressContainer;
     73    }
    8674
    87         /**
    88         * Gets the selected street of the street table.
    89         * @return
    90         */
    91         public OSMStreet getSelectedStreet() {
    92                 if (streetTable != null && addressContainer != null && addressContainer.getStreetList() != null) {
    93                         int selRows = streetTable.getSelectedRow();
     75    /**
     76    * Gets the selected street of the street table.
     77    * @return
     78    */
     79    public OSMStreet getSelectedStreet() {
     80        if (streetTable != null && addressContainer != null && addressContainer.getStreetList() != null) {
     81            int selRows = streetTable.getSelectedRow();
    9482
    95                         if (selRows < 0 || selRows >= addressContainer.getNumberOfStreets()) {
    96                                 return null;
    97                         }
     83            if (selRows < 0 || selRows >= addressContainer.getNumberOfStreets()) {
     84                return null;
     85            }
    9886
    99                         return addressContainer.getStreetList().get(selRows);
    100                 }
    101                 return null;
    102         }
     87            return addressContainer.getStreetList().get(selRows);
     88        }
     89        return null;
     90    }
    10391
    104         /**
    105         * Checks for addresses.
    106         *
    107         * @return true, if successful
    108         */
    109         public boolean hasAddresses() {
    110                 return hasIncompleteAddresses() || hasUnresolvedAddresses();
    111         }
     92    /**
     93    * Checks for addresses.
     94    *
     95    * @return true, if successful
     96    */
     97    public boolean hasAddresses() {
     98        return hasIncompleteAddresses() || hasUnresolvedAddresses();
     99    }
    112100
    113         /**
    114         * Checks for incomplete addresses.
    115         *
    116         * @return true, if successful
    117         */
    118         public boolean hasIncompleteAddresses() {
    119                 return getSelectedIncompleteAddresses() != null;
    120         }
     101    /**
     102    * Checks for incomplete addresses.
     103    *
     104    * @return true, if successful
     105    */
     106    public boolean hasIncompleteAddresses() {
     107        return getSelectedIncompleteAddresses() != null;
     108    }
    121109
    122         /**
    123         * Checks for unresolved addresses.
    124         *
    125         * @return true, if successful
    126         */
    127         public boolean hasUnresolvedAddresses() {
    128                 return getSelectedUnresolvedAddresses() != null;
    129         }
     110    /**
     111    * Checks for unresolved addresses.
     112    *
     113    * @return true, if successful
     114    */
     115    public boolean hasUnresolvedAddresses() {
     116        return getSelectedUnresolvedAddresses() != null;
     117    }
    130118
    131         /**
    132         * Checks for addresses with guesses.
    133         *
    134         * @return true, if successful
    135         */
    136         public boolean hasAddressesWithGuesses() {
    137                 if (hasIncompleteAddresses()) {
    138                         for (OSMAddress addr : getSelectedIncompleteAddresses()) {
    139                                 if (addr.hasGuesses()) {
    140                                         return true;
    141                                 }
    142                         }
    143                 }
     119    /**
     120    * Checks for addresses with guesses.
     121    *
     122    * @return true, if successful
     123    */
     124    public boolean hasAddressesWithGuesses() {
     125        if (hasIncompleteAddresses()) {
     126            for (OSMAddress addr : getSelectedIncompleteAddresses()) {
     127                if (addr.hasGuesses()) {
     128                    return true;
     129                }
     130            }
     131        }
    144132
    145                 if (hasUnresolvedAddresses()) {
    146                         for (OSMAddress addr : getSelectedUnresolvedAddresses()) {
    147                                 if (addr.hasGuesses()) {
    148                                         return true;
    149                                 }
    150                         }
    151                 }
     133        if (hasUnresolvedAddresses()) {
     134            for (OSMAddress addr : getSelectedUnresolvedAddresses()) {
     135                if (addr.hasGuesses()) {
     136                    return true;
     137                }
     138            }
     139        }
    152140
    153                 return false;
    154         }
     141        return false;
     142    }
    155143
    156         /**
    157         * Gets the list containing the selected items of the 'unresolved addresses ' table.
    158         * @return
    159         */
    160         public List<OSMAddress> getSelectedUnresolvedAddresses() {
    161                 if (unresolvedAddressTable != null &&
    162                                 addressContainer != null &&
    163                                 unresolvedCache == null) {
     144    /**
     145    * Gets the list containing the selected items of the 'unresolved addresses ' table.
     146    * @return
     147    */
     148    public List<OSMAddress> getSelectedUnresolvedAddresses() {
     149        if (unresolvedAddressTable != null &&
     150                addressContainer != null &&
     151                unresolvedCache == null) {
    164152
    165                         int[] selRows = unresolvedAddressTable.getSelectedRows();
     153            int[] selRows = unresolvedAddressTable.getSelectedRows();
    166154
    167                         unresolvedCache = new ArrayList<OSMAddress>();
    168                         for (int i = 0; i < selRows.length; i++) {
    169                                 if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfUnresolvedAddresses()) {
    170                                         unresolvedCache.add(addressContainer.getUnresolvedAddresses().get(selRows[i]));
    171                                 }
    172                         }
    173                         return unresolvedCache;
    174                 } else {
    175                         return unresolvedCache;
    176                 }
    177         }
     155            unresolvedCache = new ArrayList<OSMAddress>();
     156            for (int i = 0; i < selRows.length; i++) {
     157                if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfUnresolvedAddresses()) {
     158                    unresolvedCache.add(addressContainer.getUnresolvedAddresses().get(selRows[i]));
     159                }
     160            }
     161            return unresolvedCache;
     162        } else {
     163            return unresolvedCache;
     164        }
     165    }
    178166
    179         /**
    180         * Gets the selected incomplete addresses.
    181         *
    182         * @return the selected incomplete addresses
    183         */
    184         public List<OSMAddress> getSelectedIncompleteAddresses() {
    185                 if (incompleteAddressTable != null &&
    186                                 addressContainer != null &&
    187                                 incompleteCache == null) {
     167    /**
     168    * Gets the selected incomplete addresses.
     169    *
     170    * @return the selected incomplete addresses
     171    */
     172    public List<OSMAddress> getSelectedIncompleteAddresses() {
     173        if (incompleteAddressTable != null &&
     174                addressContainer != null &&
     175                incompleteCache == null) {
    188176
    189                         int[] selRows = incompleteAddressTable.getSelectedRows();
     177            int[] selRows = incompleteAddressTable.getSelectedRows();
    190178
    191                         incompleteCache = new ArrayList<OSMAddress>();
    192                         for (int i = 0; i < selRows.length; i++) {
    193                                 if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfIncompleteAddresses()) {
    194                                         incompleteCache.add(addressContainer.getIncompleteAddresses().get(selRows[i]));
    195                                 }
    196                         }
    197                         return incompleteCache;
    198                 } else {
    199                         return incompleteCache; // equals null, if no data is present
    200                 }
    201         }
     179            incompleteCache = new ArrayList<OSMAddress>();
     180            for (int i = 0; i < selRows.length; i++) {
     181                if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfIncompleteAddresses()) {
     182                    incompleteCache.add(addressContainer.getIncompleteAddresses().get(selRows[i]));
     183                }
     184            }
     185            return incompleteCache;
     186        } else {
     187            return incompleteCache; // equals null, if no data is present
     188        }
     189    }
    202190}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditTableModel.java

    r27326 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    3119@SuppressWarnings("serial")
    3220public abstract class AddressEditTableModel extends DefaultTableModel implements
    33                 IAddressEditContainerListener {
     21        IAddressEditContainerListener {
    3422
    35         protected AddressEditContainer addressContainer;
    36         protected int sortCol = 0;
    37         protected boolean isSortAsc = true;
     23    protected AddressEditContainer addressContainer;
     24    protected int sortCol = 0;
     25    protected boolean isSortAsc = true;
    3826
    39         public AddressEditTableModel(AddressEditContainer addressContainer) {
    40                 super();
    41                 this.addressContainer = addressContainer;
    42                 addressContainer.addChangedListener(this);
    43         }
     27    public AddressEditTableModel(AddressEditContainer addressContainer) {
     28        super();
     29        this.addressContainer = addressContainer;
     30        addressContainer.addChangedListener(this);
     31    }
    4432
    45         @Override
    46         public void containerChanged(AddressEditContainer container) {
    47                 if (SwingUtilities.isEventDispatchThread()) {
    48                         fireTableDataChanged(); // update model
    49                 } else {
    50                         SwingUtilities.invokeLater(new Runnable() {
    51                                
    52                                 @Override
    53                                 public void run() {
    54                                         fireTableDataChanged(); // update model                                 
    55                                 }
    56                         });
    57                 }
    58         }
     33    @Override
     34    public void containerChanged(AddressEditContainer container) {
     35        if (SwingUtilities.isEventDispatchThread()) {
     36            fireTableDataChanged(); // update model
     37        } else {
     38            SwingUtilities.invokeLater(new Runnable() {
     39               
     40                @Override
     41                public void run() {
     42                    fireTableDataChanged(); // update model                   
     43                }
     44            });
     45        }
     46    }
    5947
    60         @Override
    61         public void entityChanged(IOSMEntity entity) {
    62                 int row = getRowOfEntity(entity);
    63                 if (row != -1) { // valid row? -> update model
    64                         fireTableRowsUpdated(row, row);
    65                 } // else we don't do anything
    66         }
     48    @Override
     49    public void entityChanged(IOSMEntity entity) {
     50        int row = getRowOfEntity(entity);
     51        if (row != -1) { // valid row? -> update model
     52            fireTableRowsUpdated(row, row);
     53        } // else we don't do anything
     54    }
    6755
    68         /**
    69         * Gets the node entity for the given row or null; if row contains no
    70         * entity.
    71         *
    72         * @param row
    73         *            The row to get the entity object for.
    74         * @return
    75         */
    76         public abstract IOSMEntity getEntityOfRow(int row);
     56    /**
     57    * Gets the node entity for the given row or null; if row contains no
     58    * entity.
     59    *
     60    * @param row
     61    *            The row to get the entity object for.
     62    * @return
     63    */
     64    public abstract IOSMEntity getEntityOfRow(int row);
    7765
    78         /**
    79         * Gets the row for the given node entity or -1; if the model does not
    80         * contain the entity.
    81         *
    82         * @param entity
    83         *            The entity to get the row for.
    84         * @return
    85         */
    86         public abstract int getRowOfEntity(IOSMEntity entity);
     66    /**
     67    * Gets the row for the given node entity or -1; if the model does not
     68    * contain the entity.
     69    *
     70    * @param entity
     71    *            The entity to get the row for.
     72    * @return
     73    */
     74    public abstract int getRowOfEntity(IOSMEntity entity);
    8775
    88         /**
    89         * Sorts the model data by the given column.
    90         *
    91         * @param column
    92         *            the column
    93         * @param ascending
    94         *            the ascending
    95         */
    96         protected abstract void sortByColumn(int column, boolean ascending);
     76    /**
     77    * Sorts the model data by the given column.
     78    *
     79    * @param column
     80    *            the column
     81    * @param ascending
     82    *            the ascending
     83    */
     84    protected abstract void sortByColumn(int column, boolean ascending);
    9785
    9886
    99         /**
    100         * The listener interface for receiving column events.
    101         * The class that is interested in processing a column
    102         * event implements this interface, and the object created
    103         * with that class is registered with a component using the
    104         * component's <code>addColumnListener<code> method. When
    105         * the column event occurs, that object's appropriate
    106         * method is invoked.
    107         *
    108         * @see ColumnEvent
    109         */
    110         class ColumnListener extends MouseAdapter {
    111                 protected JTable table;
     87    /**
     88    * The listener interface for receiving column events.
     89    * The class that is interested in processing a column
     90    * event implements this interface, and the object created
     91    * with that class is registered with a component using the
     92    * component's <code>addColumnListener<code> method. When
     93    * the column event occurs, that object's appropriate
     94    * method is invoked.
     95    *
     96    * @see ColumnEvent
     97    */
     98    class ColumnListener extends MouseAdapter {
     99        protected JTable table;
    112100
    113                 /**
    114                 * Instantiates a new column listener.
    115                 *
    116                 * @param t the t
    117                 */
    118                 public ColumnListener(JTable t) {
    119                         table = t;
    120                 }
     101        /**
     102        * Instantiates a new column listener.
     103        *
     104        * @param t the t
     105        */
     106        public ColumnListener(JTable t) {
     107            table = t;
     108        }
    121109
    122                 /* (non-Javadoc)
    123                  * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
    124                  */
    125                 public void mouseClicked(MouseEvent e) {
    126                         TableColumnModel colModel = table.getColumnModel();
    127                         int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
    128                         int modelIndex = colModel.getColumn(columnModelIndex)
    129                                         .getModelIndex();
     110        public void mouseClicked(MouseEvent e) {
     111            TableColumnModel colModel = table.getColumnModel();
     112            int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
     113            int modelIndex = colModel.getColumn(columnModelIndex)
     114                    .getModelIndex();
    130115
    131                         if (modelIndex < 0) {
    132                                 return;
    133                         }
    134                         // Same column? If yes, flip order
    135                         if (sortCol == modelIndex) {
    136                                 isSortAsc = !isSortAsc;
    137                         } else {
    138                                 sortCol = modelIndex;
    139                         }
     116            if (modelIndex < 0) {
     117                return;
     118            }
     119            // Same column? If yes, flip order
     120            if (sortCol == modelIndex) {
     121                isSortAsc = !isSortAsc;
     122            } else {
     123                sortCol = modelIndex;
     124            }
    140125
    141                         for (int i = 0; i < colModel.getColumnCount(); i++) {
    142                                 TableColumn column = colModel.getColumn(i);
    143                                 column.setHeaderValue(getColumnName(column.getModelIndex()));
    144                         }
    145                         table.getTableHeader().repaint();
     126            for (int i = 0; i < colModel.getColumnCount(); i++) {
     127                TableColumn column = colModel.getColumn(i);
     128                column.setHeaderValue(getColumnName(column.getModelIndex()));
     129            }
     130            table.getTableHeader().repaint();
    146131
    147                         //Collections.sort(addressContainer, new MyComparator(isSortAsc));
     132            //Collections.sort(addressContainer, new MyComparator(isSortAsc));
    148133
    149                         sortByColumn(sortCol, isSortAsc);
    150                         table.tableChanged(new TableModelEvent(AddressEditTableModel.this));
    151                         table.repaint();
    152                 }
    153         }
     134            sortByColumn(sortCol, isSortAsc);
     135            table.tableChanged(new TableModelEvent(AddressEditTableModel.this));
     136            table.repaint();
     137        }
     138    }
    154139
    155         /**
    156         * Internal base class to sort items by different columns.
    157         */
    158         protected abstract class ColumnSorter<E> implements Comparator<E> {
    159                 private int column;
    160                 private boolean ascending;
     140    /**
     141    * Internal base class to sort items by different columns.
     142    */
     143    protected abstract class ColumnSorter<E> implements Comparator<E> {
     144        private int column;
     145        private boolean ascending;
    161146
    162                 /**
    163                 * Instantiates a new address sorter.
    164                 *
    165                 * @param column the column to sort by
    166                 */
    167                 public ColumnSorter(int column, boolean ascending) {
    168                         super();
    169                         this.column = column;
    170                         this.ascending = ascending;
    171                 }
     147        /**
     148        * Instantiates a new address sorter.
     149        *
     150        * @param column the column to sort by
     151        */
     152        public ColumnSorter(int column, boolean ascending) {
     153            super();
     154            this.column = column;
     155            this.ascending = ascending;
     156        }
    172157
    173                 /**
    174                 * Gets the index of the column to sort.
    175                 *
    176                 * @return the column
    177                 */
    178                 protected int getColumn() {
    179                         return column;
    180                 }
     158        /**
     159        * Gets the index of the column to sort.
     160        *
     161        * @return the column
     162        */
     163        protected int getColumn() {
     164            return column;
     165        }
    181166
    182                 /**
    183                 * Checks if sort mode is ascending or not.
    184                 *
    185                 * @return true, if is ascending
    186                 */
    187                 protected boolean isAscending() {
    188                         return ascending;
    189                 }
     167        /**
     168        * Checks if sort mode is ascending or not.
     169        *
     170        * @return true, if is ascending
     171        */
     172        protected boolean isAscending() {
     173            return ascending;
     174        }
    190175
    191                 /* (non-Javadoc)
    192                  * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
    193                  */
    194                 @Override
    195                 public abstract int compare(E arg0, E arg1);
    196         }
     176        @Override
     177        public abstract int compare(E arg0, E arg1);
     178    }
    197179}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/BBoxMapRectangle.java

    r29519 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    2210
    2311public class BBoxMapRectangle extends MapRectangleImpl {
    24         private BBox bbox;
     12    private BBox bbox;
    2513
    26         /**
    27         * @param bbox
    28         */
    29         public BBoxMapRectangle(BBox bbox) {
    30                 super(null, null);
    31                 this.bbox = bbox;
    32         }
     14    /**
     15    * @param bbox
     16    */
     17    public BBoxMapRectangle(BBox bbox) {
     18        super(null, null);
     19        this.bbox = bbox;
     20    }
    3321
    34         @Override
    35         public Coordinate getBottomRight() {
    36                 return new Coordinate(bbox.getBottomRight().lat(), bbox.getBottomRight().lon());
    37         }
     22    @Override
     23    public Coordinate getBottomRight() {
     24        return new Coordinate(bbox.getBottomRight().lat(), bbox.getBottomRight().lon());
     25    }
    3826
    39         @Override
    40         public Coordinate getTopLeft() {
    41                 return new Coordinate(bbox.getTopLeft().lat(), bbox.getTopLeft().lon());
    42         }
     27    @Override
     28    public Coordinate getTopLeft() {
     29        return new Coordinate(bbox.getTopLeft().lat(), bbox.getTopLeft().lon());
     30    }
    4331
    44         @Override
    45         public void paint(Graphics g, Point topLeft, Point bottomRight) {
    46                         // do nothing here
    47         }
     32    @Override
     33    public void paint(Graphics g, Point topLeft, Point bottomRight) {
     34            // do nothing here
     35    }
    4836}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesDialog.java

    r27357 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    8573     }
    8674
    87     /* (non-Javadoc)
    88      * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#hideNotify()
    89      */
    9075    @Override
    9176    public void hideNotify() {
     
    9479    }
    9580
    96     /* (non-Javadoc)
    97      * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#showNotify()
    98      */
    9981    @Override
    10082    public void showNotify() {
     
    10385    }
    10486
    105     /* (non-Javadoc)
    106      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#dataChanged(org.openstreetmap.josm.data.osm.event.DataChangedEvent)
    107      */
    10887    @Override
    10988    public void dataChanged(DataChangedEvent event) {
     
    11190    }
    11291
    113     /* (non-Javadoc)
    114      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#nodeMoved(org.openstreetmap.josm.data.osm.event.NodeMovedEvent)
    115      */
    11692    @Override
    11793    public void nodeMoved(NodeMovedEvent event) {
     
    11995    }
    12096
    121     /* (non-Javadoc)
    122      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#otherDatasetChange(org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent)
    123      */
    12497    @Override
    12598    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    12699        // TODO Auto-generated method stub
    127 
    128100    }
    129101
    130     /* (non-Javadoc)
    131      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesAdded(org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent)
    132      */
    133         @Override
     102    @Override
    134103    public void primitivesAdded(PrimitivesAddedEvent event) {
    135104        container.invalidate();
    136 
    137105    }
    138106
    139     /* (non-Javadoc)
    140      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#primitivesRemoved(org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent)
    141      */
    142         @Override
     107    @Override
    143108    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    144109        container.invalidate();
    145110    }
    146111
    147     /* (non-Javadoc)
    148      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#relationMembersChanged(org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent)
    149      */
    150112    @Override
    151113    public void relationMembersChanged(RelationMembersChangedEvent event) {
     
    153115    }
    154116
    155     /* (non-Javadoc)
    156      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#tagsChanged(org.openstreetmap.josm.data.osm.event.TagsChangedEvent)
    157      */
    158117    @Override
    159118    public void tagsChanged(TagsChangedEvent event) {
    160119        container.invalidate();
    161 
    162120    }
    163121
    164     /* (non-Javadoc)
    165      * @see org.openstreetmap.josm.data.osm.event.DataSetListener#wayNodesChanged(org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent)
    166      */
    167122    @Override
    168123    public void wayNodesChanged(WayNodesChangedEvent event) {
     
    170125    }
    171126
    172     /* (non-Javadoc)
    173      * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
    174      */
    175127    @Override
    176128    public void valueChanged(ListSelectionEvent e) {
     
    184136    }
    185137
    186     /* (non-Javadoc)
    187      * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    188      */
    189138    @Override
    190139    public void containerChanged(AddressEditContainer container) {
     
    198147    }
    199148
    200     /* (non-Javadoc)
    201      * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)
    202      */
    203149    @Override
    204150    public void entityChanged(IOSMEntity node) {
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesTableModel.java

    r28977 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    2412
    2513public class IncompleteAddressesTableModel extends AddressEditTableModel  {
    26         /**
    27         *
    28         */
    29         private static final long serialVersionUID = -5951629033395186324L;
     14    /**
     15    *
     16    */
     17    private static final long serialVersionUID = -5951629033395186324L;
    3018
    31         // TODO: Add "state" column, if required
    32         private static final int NUMBER_OF_COLUMNS = 5;
    33         private static final String[] COLUMN_NAMES = new String[]{tr("Country"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Street"), tr("Number")};
    34         private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{
    35                 String.class, String.class, String.class, String.class, String.class, String.class};
     19    // TODO: Add "state" column, if required
     20    private static final int NUMBER_OF_COLUMNS = 5;
     21    private static final String[] COLUMN_NAMES = new String[]{tr("Country"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Street"), tr("Number")};
     22    private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{
     23        String.class, String.class, String.class, String.class, String.class, String.class};
    3624
    3725
    38         /**
    39         * Instantiates a new incomplete addresses table model.
    40         *
    41         * @param addressContainer the address container used for display
    42         */
    43         public IncompleteAddressesTableModel(AddressEditContainer addressContainer) {
    44                 super(addressContainer);
    45         }
     26    /**
     27    * Instantiates a new incomplete addresses table model.
     28    *
     29    * @param addressContainer the address container used for display
     30    */
     31    public IncompleteAddressesTableModel(AddressEditContainer addressContainer) {
     32        super(addressContainer);
     33    }
    4634
    47         /* (non-Javadoc)
    48          * @see javax.swing.table.DefaultTableModel#getColumnCount()
    49          */
    50         @Override
    51         public int getColumnCount() {
    52                 return NUMBER_OF_COLUMNS;
    53         }
     35    @Override
     36    public int getColumnCount() {
     37        return NUMBER_OF_COLUMNS;
     38    }
    5439
    55         /* (non-Javadoc)
    56          * @see javax.swing.table.DefaultTableModel#getColumnName(int)
    57          */
    58         @Override
    59         public String getColumnName(int column) {
    60                 return COLUMN_NAMES[column];
    61         }
     40    @Override
     41    public String getColumnName(int column) {
     42        return COLUMN_NAMES[column];
     43    }
    6244
    63         /* (non-Javadoc)
    64          * @see javax.swing.table.DefaultTableModel#getRowCount()
    65          */
    66         @Override
    67         public int getRowCount() {
    68                 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
    69                         return 0;
    70                 }
    71                 return addressContainer.getNumberOfIncompleteAddresses();
    72         }
     45    @Override
     46    public int getRowCount() {
     47        if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
     48            return 0;
     49        }
     50        return addressContainer.getNumberOfIncompleteAddresses();
     51    }
    7352
    74         /* (non-Javadoc)
    75          * @see javax.swing.table.DefaultTableModel#getValueAt(int, int)
    76          */
    77         @Override
    78         public Object getValueAt(int row, int column) {
    79                 OSMAddress aNode = (OSMAddress) getEntityOfRow(row);
     53    @Override
     54    public Object getValueAt(int row, int column) {
     55        OSMAddress aNode = (OSMAddress) getEntityOfRow(row);
    8056
    81                 if (aNode == null) {
    82                         return null;
    83                 }
     57        if (aNode == null) {
     58            return null;
     59        }
    8460
    85                 switch (column) {
    86                 case 0:
    87                         return aNode.getCountry();
    88                 case 1:
    89                         return aNode.getCity();
    90                 case 2:
    91                         return aNode.getPostalCode();
    92                 case 3:
    93                         return aNode.getStreetName();
    94                 case 4:
    95                         return aNode.getHouseNumber();
    96                 default:
    97                         throw new RuntimeException("Invalid column index: " + column);
    98                 }
     61        switch (column) {
     62        case 0:
     63            return aNode.getCountry();
     64        case 1:
     65            return aNode.getCity();
     66        case 2:
     67            return aNode.getPostalCode();
     68        case 3:
     69            return aNode.getStreetName();
     70        case 4:
     71            return aNode.getHouseNumber();
     72        default:
     73            throw new RuntimeException("Invalid column index: " + column);
     74        }
    9975
    100         }
     76    }
    10177
    102         /* (non-Javadoc)
    103          * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
    104          */
    105         @Override
    106         public Class<?> getColumnClass(int arg0) {
    107                 return COLUMN_CLASSES[arg0];
    108         }
     78    @Override
     79    public Class<?> getColumnClass(int arg0) {
     80        return COLUMN_CLASSES[arg0];
     81    }
    10982
    110         /* (non-Javadoc)
    111          * @see javax.swing.table.DefaultTableModel#isCellEditable(int, int)
    112          */
    113         @Override
    114         public boolean isCellEditable(int row, int column) {
    115                 return false;
    116         }
     83    @Override
     84    public boolean isCellEditable(int row, int column) {
     85        return false;
     86    }
    11787
    118         /* (non-Javadoc)
    119          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#getEntityOfRow(int)
    120          */
    121         @Override
    122         public IOSMEntity getEntityOfRow(int row) {
    123                 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
    124                         return null;
    125                 }
    126                 if (row < 0 || row >= addressContainer.getNumberOfIncompleteAddresses()) {
    127                         return null;
    128                 }
    129                 return addressContainer.getIncompleteAddresses().get(row);
    130         }
     88    @Override
     89    public IOSMEntity getEntityOfRow(int row) {
     90        if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
     91            return null;
     92        }
     93        if (row < 0 || row >= addressContainer.getNumberOfIncompleteAddresses()) {
     94            return null;
     95        }
     96        return addressContainer.getIncompleteAddresses().get(row);
     97    }
    13198
    132         /* (non-Javadoc)
    133          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#getRowOfEntity(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)
    134          */
    135         @Override
    136         public int getRowOfEntity(IOSMEntity entity) {
    137                 if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
    138                         return -1;
    139                 }
     99    @Override
     100    public int getRowOfEntity(IOSMEntity entity) {
     101        if (addressContainer == null || addressContainer.getIncompleteAddresses() == null) {
     102            return -1;
     103        }
    140104
    141                 return addressContainer.getIncompleteAddresses().indexOf(entity);
    142         }
     105        return addressContainer.getIncompleteAddresses().indexOf(entity);
     106    }
    143107
     108    @Override
     109    protected void sortByColumn(int column, boolean ascending) {
     110        if (addressContainer.getNumberOfIncompleteAddresses() == 0) return;
    144111
    145         /* (non-Javadoc)
    146          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#sortByColumn(int, boolean)
    147          */
    148         @Override
    149         protected void sortByColumn(int column, boolean ascending) {
    150                 if (addressContainer.getNumberOfIncompleteAddresses() == 0) return;
     112        Collections.sort(addressContainer.getIncompleteAddresses(),
     113                new IncompleteAddressModelSorter(column, ascending));
     114    }
    151115
    152                 Collections.sort(addressContainer.getIncompleteAddresses(),
    153                                 new IncompleteAddressModelSorter(column, ascending));
    154         }
     116    /**
     117     * Internal class StreetModelSorter.
     118     */
     119    class IncompleteAddressModelSorter extends ColumnSorter<OSMAddress> {
    155120
    156         /**
    157          * Internal class StreetModelSorter.
    158          */
    159         class IncompleteAddressModelSorter extends ColumnSorter<OSMAddress> {
     121        /**
     122         * Instantiates a new incomplete address model sorter.
     123         *
     124         * @param column the column to sort
     125         * @param asc sort ascending
     126         */
     127        public IncompleteAddressModelSorter(int column, boolean asc) {
     128            super(column, asc);
     129        }
    160130
    161                 /**
    162                  * Instantiates a new incomplete address model sorter.
    163                  *
    164                  * @param column the column to sort
    165                  * @param asc sort ascending
    166                  */
    167                 public IncompleteAddressModelSorter(int column, boolean asc) {
    168                         super(column, asc);
    169                 }
     131        @Override
     132        public int compare(OSMAddress arg0, OSMAddress arg1) {
     133            int cc = 0;
    170134
    171                 /* (non-Javadoc)
    172                  * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel.ColumnSorter#compare(java.lang.Object, java.lang.Object)
    173                  */
    174                 @Override
    175                 public int compare(OSMAddress arg0, OSMAddress arg1) {
    176                         int cc = 0;
     135            switch (getColumn()) {
     136            case 0:
     137                cc=arg0.getCountry().compareTo(arg1.getCountry());
     138                break;
     139            case 1:
     140                cc=arg0.getCity().compareTo(arg1.getCity());
     141                break;
     142            case 2:
     143                cc=arg0.getPostalCode().compareTo(arg1.getPostalCode());
     144                break;
     145            case 3:
     146                cc= arg0.getStreetName().compareTo(arg1.getStreetName());
     147                break;
     148            case 4:
     149                cc=arg0.getHouseNumber().compareTo(arg1.getHouseNumber());
     150                break;
     151            default:
     152                throw new RuntimeException("Invalid column index: " + getColumn());
     153            }
    177154
    178                         switch (getColumn()) {
    179                         case 0:
    180                                 cc=arg0.getCountry().compareTo(arg1.getCountry());
    181                                 break;
    182                         case 1:
    183                                 cc=arg0.getCity().compareTo(arg1.getCity());
    184                                 break;
    185                         case 2:
    186                                 cc=arg0.getPostalCode().compareTo(arg1.getPostalCode());
    187                                 break;
    188                         case 3:
    189                                 cc= arg0.getStreetName().compareTo(arg1.getStreetName());
    190                                 break;
    191                         case 4:
    192                                 cc=arg0.getHouseNumber().compareTo(arg1.getHouseNumber());
    193                                 break;
    194                         default:
    195                                 throw new RuntimeException("Invalid column index: " + getColumn());
    196                         }
     155            if (!isAscending()) {
     156                cc = -cc;
     157            }
    197158
    198                         if (!isAscending()) {
    199                                 cc = -cc;
    200                         }
    201 
    202                         return cc;
    203                 }
    204         }
     159            return cc;
     160        }
     161    }
    205162
    206163
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/StreetTableModel.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui;
    153
     
    2412@SuppressWarnings("serial")
    2513public class StreetTableModel extends AddressEditTableModel {
    26         private static final int NUMBER_OF_COLUMNS = 3;
    27         private static final String[] COLUMN_NAMES = new String[]{tr("Type"), tr("Name"), tr("Addresses")};
    28         private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{String.class, String.class, Integer.class};
    29         /**
    30         * @param addressContainer
    31         */
    32         public StreetTableModel(AddressEditContainer addressContainer) {
    33                 super(addressContainer);
    34         }
     14    private static final int NUMBER_OF_COLUMNS = 3;
     15    private static final String[] COLUMN_NAMES = new String[]{tr("Type"), tr("Name"), tr("Addresses")};
     16    private static final Class<?>[] COLUMN_CLASSES = new Class<?>[]{String.class, String.class, Integer.class};
     17    /**
     18    * @param addressContainer
     19    */
     20    public StreetTableModel(AddressEditContainer addressContainer) {
     21        super(addressContainer);
     22    }
    3523
    36         /* (non-Javadoc)
    37          * @see javax.swing.table.DefaultTableModel#getColumnCount()
    38          */
    39         @Override
    40         public int getColumnCount() {
    41                 // TODO Auto-generated method stub
    42                 return NUMBER_OF_COLUMNS;
    43         }
     24    @Override
     25    public int getColumnCount() {
     26        // TODO Auto-generated method stub
     27        return NUMBER_OF_COLUMNS;
     28    }
    4429
    45         /* (non-Javadoc)
    46          * @see javax.swing.table.DefaultTableModel#getColumnName(int)
    47          */
    48         @Override
    49         public String getColumnName(int column) {
    50                 return COLUMN_NAMES[column];
    51         }
     30    @Override
     31    public String getColumnName(int column) {
     32        return COLUMN_NAMES[column];
     33    }
    5234
    53         /* (non-Javadoc)
    54          * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
    55          */
    56         @Override
    57         public Class<?> getColumnClass(int columnIndex) {
    58                 return COLUMN_CLASSES[columnIndex];
    59         }
     35    @Override
     36    public Class<?> getColumnClass(int columnIndex) {
     37        return COLUMN_CLASSES[columnIndex];
     38    }
    6039
    61         /* (non-Javadoc)
    62          * @see javax.swing.table.DefaultTableModel#getRowCount()
    63          */
    64         @Override
    65         public int getRowCount() {
    66                 if (addressContainer == null || addressContainer.getStreetList() == null) {
    67                         return 0;
    68                 }
    69                 return addressContainer.getNumberOfStreets();
    70         }
     40    @Override
     41    public int getRowCount() {
     42        if (addressContainer == null || addressContainer.getStreetList() == null) {
     43            return 0;
     44        }
     45        return addressContainer.getNumberOfStreets();
     46    }
    7147
    72         /* (non-Javadoc)
    73          * @see javax.swing.table.DefaultTableModel#getValueAt(int, int)
    74          */
    75         @Override
    76         public Object getValueAt(int row, int column) {
    77                 OSMStreet sNode = (OSMStreet) getEntityOfRow(row);
     48    @Override
     49    public Object getValueAt(int row, int column) {
     50        OSMStreet sNode = (OSMStreet) getEntityOfRow(row);
    7851
    79                 if (sNode == null) {
    80                         return null;
    81                 }
     52        if (sNode == null) {
     53            return null;
     54        }
    8255
    83                 switch (column) {
    84                 case 0:
    85                         return sNode.getType();
    86                 case 1:
    87                         return sNode.getName();
    88                 case 2:
    89                         return sNode.getNumberOfSegments();
    90                 case 3:
    91                         return sNode.getNumberOfAddresses();
    92                 case 4:
    93                         return sNode.hasAssociatedStreetRelation();
    94                 default:
    95                         throw new RuntimeException("Invalid column index: " + column);
    96                 }
     56        switch (column) {
     57        case 0:
     58            return sNode.getType();
     59        case 1:
     60            return sNode.getName();
     61        case 2:
     62            return sNode.getNumberOfSegments();
     63        case 3:
     64            return sNode.getNumberOfAddresses();
     65        case 4:
     66            return sNode.hasAssociatedStreetRelation();
     67        default:
     68            throw new RuntimeException("Invalid column index: " + column);
     69        }
    9770
    98         }
     71    }
    9972
    100         @Override
    101         public boolean isCellEditable(int row, int column) {
    102                 // TODO Auto-generated method stub
    103                 return false;
    104         }
     73    @Override
     74    public boolean isCellEditable(int row, int column) {
     75        // TODO Auto-generated method stub
     76        return false;
     77    }
    10578
    106         @Override
    107         public IOSMEntity getEntityOfRow(int row) {
    108                 if (addressContainer == null || addressContainer.getStreetList() == null) {
    109                         return null;
    110                 }
    111                 if (row < 0 || row >= addressContainer.getNumberOfStreets()) {
    112                         return null;
    113                 }
    114                 return addressContainer.getStreetList().get(row);
    115         }
     79    @Override
     80    public IOSMEntity getEntityOfRow(int row) {
     81        if (addressContainer == null || addressContainer.getStreetList() == null) {
     82            return null;
     83        }
     84        if (row < 0 || row >= addressContainer.getNumberOfStreets()) {
     85            return null;
     86        }
     87        return addressContainer.getStreetList().get(row);
     88    }
    11689
    117         @Override
    118         public int getRowOfEntity(IOSMEntity entity) {
    119                 if (addressContainer == null || addressContainer.getStreetList() == null) {
    120                         return -1;
    121                 }
     90    @Override
     91    public int getRowOfEntity(IOSMEntity entity) {
     92        if (addressContainer == null || addressContainer.getStreetList() == null) {
     93            return -1;
     94        }
    12295
    123                 return addressContainer.getStreetList().indexOf(entity);
    124         }
     96        return addressContainer.getStreetList().indexOf(entity);
     97    }
    12598
    126         /* (non-Javadoc)
    127          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel#sortByColumn(int, boolean)
    128          */
    129         @Override
    130         protected void sortByColumn(int column, boolean ascending) {
    131                 Collections.sort(addressContainer.getStreetList(), new StreetModelSorter(column, ascending));
    132         }
     99    @Override
     100    protected void sortByColumn(int column, boolean ascending) {
     101        Collections.sort(addressContainer.getStreetList(), new StreetModelSorter(column, ascending));
     102    }
    133103
    134         /**
    135         * Internal class StreetModelSorter.
    136         */
    137         class StreetModelSorter extends ColumnSorter<OSMStreet> {
     104    /**
     105    * Internal class StreetModelSorter.
     106    */
     107    class StreetModelSorter extends ColumnSorter<OSMStreet> {
    138108
    139                 public StreetModelSorter(int column, boolean asc) {
    140                         super(column, asc);
    141                 }
     109        public StreetModelSorter(int column, boolean asc) {
     110            super(column, asc);
     111        }
    142112
    143                 public int compare(OSMStreet arg0, OSMStreet arg1) {
    144                         if (arg0 == null || arg1 == null) return 0;
     113        public int compare(OSMStreet arg0, OSMStreet arg1) {
     114            if (arg0 == null || arg1 == null) return 0;
    145115
    146                         switch (getColumn()) {
    147                         case 0:
    148                                 if (arg0.getType() != null) {
    149                                         return arg0.getType().compareTo(arg1.getType());
    150                                 } else {
    151                                         return arg1.hasName() ? -1 : 0;
    152                                 }
    153                         case 1:
    154                                 if (arg0.hasName()) {
    155                                         return arg0.getName().compareTo(arg1.getName());
    156                                 } else {
    157                                         return arg1.hasName() ? -1 : 0;
    158                                 }
    159                         case 2:
    160                                 return new Integer(arg0.getNumberOfAddresses()).
    161                                                                 compareTo(new Integer(arg1.getNumberOfAddresses()));
    162                         default:
    163                         }
    164                         return 0;
    165                 }
    166         }
     116            switch (getColumn()) {
     117            case 0:
     118                if (arg0.getType() != null) {
     119                    return arg0.getType().compareTo(arg1.getType());
     120                } else {
     121                    return arg1.hasName() ? -1 : 0;
     122                }
     123            case 1:
     124                if (arg0.hasName()) {
     125                    return arg0.getName().compareTo(arg1.getName());
     126                } else {
     127                    return arg1.hasName() ? -1 : 0;
     128                }
     129            case 2:
     130                return new Integer(arg0.getNumberOfAddresses()).
     131                                compareTo(new Integer(arg1.getNumberOfAddresses()));
     132            default:
     133            }
     134            return 0;
     135        }
     136    }
    167137}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/UnresolvedAddressesTableModel.java

    r28977 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
    14 /**
    15  * This program is free software: you can redistribute it and/or modify it under
    16  * the terms of the GNU General Public License as published by the
    17  * Free Software Foundation, either version 3 of the License, or
    18  * (at your option) any later version.
    19  *
    20  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    21  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    22  * See the GNU General Public License for more details.
    23  *
    24  * You should have received a copy of the GNU General Public License along with this program.
    25  * If not, see <http://www.gnu.org/licenses/>.
    26  */
    27 
    28 /* File created on 25.10.2010 */
     1// License: GPL. For details, see LICENSE file.
    292package org.openstreetmap.josm.plugins.fixAddresses.gui;
    303
     
    4720public class UnresolvedAddressesTableModel extends AddressEditTableModel {
    4821
    49         private static final int NUMBER_OF_COLUMNS = 5;
    50         private static final String[] COLUMN_NAMES = new String[] { tr("Street"),
    51                         tr("Number"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Name") };
     22    private static final int NUMBER_OF_COLUMNS = 5;
     23    private static final String[] COLUMN_NAMES = new String[] { tr("Street"),
     24            tr("Number"), trc("address", "City" /* fix #8140 */), tr("Postcode"), tr("Name") };
    5225
    53         private static final Class<?>[] COLUMN_CLASSES = new Class<?>[] {
    54                         String.class, String.class, String.class, String.class,
    55                         String.class };
     26    private static final Class<?>[] COLUMN_CLASSES = new Class<?>[] {
     27            String.class, String.class, String.class, String.class,
     28            String.class };
    5629
    57         /**
    58         *
    59         */
    60         private static final long serialVersionUID = 424009321818130586L;
     30    /**
     31    *
     32    */
     33    private static final long serialVersionUID = 424009321818130586L;
    6134
    62         /**
    63         * @param addressContainer
    64         */
    65         public UnresolvedAddressesTableModel(AddressEditContainer addressContainer) {
    66                 super(addressContainer);
    67         }
     35    /**
     36    * @param addressContainer
     37    */
     38    public UnresolvedAddressesTableModel(AddressEditContainer addressContainer) {
     39        super(addressContainer);
     40    }
    6841
    69         /*
    70          * (non-Javadoc)
    71          *
    72          * @see javax.swing.table.DefaultTableModel#getColumnCount()
    73          */
    74         @Override
    75         public int getColumnCount() {
    76                 return NUMBER_OF_COLUMNS;
    77         }
     42    @Override
     43    public int getColumnCount() {
     44        return NUMBER_OF_COLUMNS;
     45    }
    7846
    79         /*
    80          * (non-Javadoc)
    81          *
    82          * @see javax.swing.table.DefaultTableModel#getColumnName(int)
    83          */
    84         @Override
    85         public String getColumnName(int column) {
    86                 return COLUMN_NAMES[column];
    87         }
     47    @Override
     48    public String getColumnName(int column) {
     49        return COLUMN_NAMES[column];
     50    }
    8851
    89         /*
    90          * (non-Javadoc)
    91          *
    92          * @see javax.swing.table.DefaultTableModel#getRowCount()
    93          */
    94         @Override
    95         public int getRowCount() {
    96                 if (addressContainer == null
    97                                 || addressContainer.getUnresolvedAddresses() == null) {
    98                         return 0;
    99                 }
    100                 return addressContainer.getNumberOfUnresolvedAddresses();
    101         }
     52    @Override
     53    public int getRowCount() {
     54        if (addressContainer == null
     55                || addressContainer.getUnresolvedAddresses() == null) {
     56            return 0;
     57        }
     58        return addressContainer.getNumberOfUnresolvedAddresses();
     59    }
    10260
    103         /*
    104          * (non-Javadoc)
    105          *
    106          * @see javax.swing.table.DefaultTableModel#getValueAt(int, int)
    107          */
    108         @Override
    109         public Object getValueAt(int row, int column) {
    110                 OSMAddress aNode = (OSMAddress) getEntityOfRow(row);
     61    @Override
     62    public Object getValueAt(int row, int column) {
     63        OSMAddress aNode = (OSMAddress) getEntityOfRow(row);
    11164
    112                 if (aNode == null) {
    113                         return null;
    114                 }
     65        if (aNode == null) {
     66            return null;
     67        }
    11568
    116                 switch (column) {
    117                 case 0:
    118                         return aNode.getStreetName();
    119                 case 1:
    120                         return aNode.getHouseNumber();
    121                 case 2:
    122                         return aNode.getCity();
    123                 case 3:
    124                         return aNode.getPostalCode();
    125                 case 4:
    126                         return aNode.getName();
    127                 default:
    128                         throw new RuntimeException("Invalid column index: " + column);
    129                 }
     69        switch (column) {
     70        case 0:
     71            return aNode.getStreetName();
     72        case 1:
     73            return aNode.getHouseNumber();
     74        case 2:
     75            return aNode.getCity();
     76        case 3:
     77            return aNode.getPostalCode();
     78        case 4:
     79            return aNode.getName();
     80        default:
     81            throw new RuntimeException("Invalid column index: " + column);
     82        }
    13083
    131         }
     84    }
    13285
    133         /*
    134          * (non-Javadoc)
    135          *
    136          * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
    137          */
    138         @Override
    139         public Class<?> getColumnClass(int arg0) {
    140                 return COLUMN_CLASSES[arg0];
    141         }
     86    @Override
     87    public Class<?> getColumnClass(int arg0) {
     88        return COLUMN_CLASSES[arg0];
     89    }
    14290
    143         /*
    144          * (non-Javadoc)
    145          *
    146          * @see javax.swing.table.DefaultTableModel#isCellEditable(int, int)
    147          */
    148         @Override
    149         public boolean isCellEditable(int row, int column) {
    150                 return false;
    151         }
     91    @Override
     92    public boolean isCellEditable(int row, int column) {
     93        return false;
     94    }
    15295
    153         /*
    154          * (non-Javadoc)
    155          *
    156          * @see
    157          * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel
    158          * #getEntityOfRow(int)
    159          */
    160         @Override
    161         public IOSMEntity getEntityOfRow(int row) {
    162                 if (addressContainer == null
    163                                 || addressContainer.getUnresolvedAddresses() == null) {
    164                         return null;
    165                 }
    166                 if (row < 0 || row >= addressContainer.getNumberOfUnresolvedAddresses()) {
    167                         return null;
    168                 }
    169                 return addressContainer.getUnresolvedAddresses().get(row);
    170         }
     96    @Override
     97    public IOSMEntity getEntityOfRow(int row) {
     98        if (addressContainer == null
     99                || addressContainer.getUnresolvedAddresses() == null) {
     100            return null;
     101        }
     102        if (row < 0 || row >= addressContainer.getNumberOfUnresolvedAddresses()) {
     103            return null;
     104        }
     105        return addressContainer.getUnresolvedAddresses().get(row);
     106    }
    171107
    172         @Override
    173         public int getRowOfEntity(IOSMEntity entity) {
    174                 if (addressContainer == null
    175                                 || addressContainer.getUnresolvedAddresses() == null) {
    176                         return -1;
    177                 }
     108    @Override
     109    public int getRowOfEntity(IOSMEntity entity) {
     110        if (addressContainer == null
     111                || addressContainer.getUnresolvedAddresses() == null) {
     112            return -1;
     113        }
    178114
    179                 return addressContainer.getUnresolvedAddresses().indexOf(entity);
    180         }
     115        return addressContainer.getUnresolvedAddresses().indexOf(entity);
     116    }
    181117
    182         /*
    183          * (non-Javadoc)
    184          *
    185          * @see
    186          * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel
    187          * #sortByColumn(int, boolean)
    188          */
    189         @Override
    190         protected void sortByColumn(int column, boolean ascending) {
    191                 if (addressContainer.getNumberOfUnresolvedAddresses() == 0)
    192                         return;
     118    @Override
     119    protected void sortByColumn(int column, boolean ascending) {
     120        if (addressContainer.getNumberOfUnresolvedAddresses() == 0)
     121            return;
    193122
    194                 Collections.sort(addressContainer.getUnresolvedAddresses(),
    195                                 new UnresolvedAddressModelSorter(column, ascending));
    196         }
     123        Collections.sort(addressContainer.getUnresolvedAddresses(),
     124                new UnresolvedAddressModelSorter(column, ascending));
     125    }
    197126
    198         /**
    199         * Internal class StreetModelSorter.
    200         */
    201         class UnresolvedAddressModelSorter extends ColumnSorter<OSMAddress> {
     127    /**
     128    * Internal class StreetModelSorter.
     129    */
     130    class UnresolvedAddressModelSorter extends ColumnSorter<OSMAddress> {
    202131
    203                 public UnresolvedAddressModelSorter(int column, boolean asc) {
    204                         super(column, asc);
    205                 }
     132        public UnresolvedAddressModelSorter(int column, boolean asc) {
     133            super(column, asc);
     134        }
    206135
    207                 /*
    208                  * (non-Javadoc)
    209                  *
    210                  * @see
    211                  * org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditTableModel
    212                  * .ColumnSorter#compare(java.lang.Object, java.lang.Object)
    213                  */
    214                 @Override
    215                 public int compare(OSMAddress arg0, OSMAddress arg1) {
    216                         int cc = 0;
    217                         switch (getColumn()) {
    218                         case 0:
    219                                 cc = arg0.getStreetName().compareTo(arg1.getStreetName());
    220                                 break;
    221                         case 1:
    222                                 cc = arg0.getHouseNumber().compareTo(arg1.getHouseNumber());
    223                                 break;
    224                         case 2:
    225                                 cc = arg0.getCity().compareTo(arg1.getCity());
    226                                 break;
    227                         case 3:
    228                                 cc = arg0.getPostalCode().compareTo(arg1.getPostalCode());
    229                                 break;
    230                         case 4:
    231                                 cc = arg0.getName().compareTo(arg1.getName());
    232                                 break;
    233                         default:
    234                                 throw new RuntimeException("Invalid column index: "
    235                                                 + getColumn());
    236                         }
     136        @Override
     137        public int compare(OSMAddress arg0, OSMAddress arg1) {
     138            int cc = 0;
     139            switch (getColumn()) {
     140            case 0:
     141                cc = arg0.getStreetName().compareTo(arg1.getStreetName());
     142                break;
     143            case 1:
     144                cc = arg0.getHouseNumber().compareTo(arg1.getHouseNumber());
     145                break;
     146            case 2:
     147                cc = arg0.getCity().compareTo(arg1.getCity());
     148                break;
     149            case 3:
     150                cc = arg0.getPostalCode().compareTo(arg1.getPostalCode());
     151                break;
     152            case 4:
     153                cc = arg0.getName().compareTo(arg1.getName());
     154                break;
     155            default:
     156                throw new RuntimeException("Invalid column index: "
     157                        + getColumn());
     158            }
    237159
    238                         if (!isAscending()) {
    239                                 cc = -cc;
    240                         }
     160            if (!isAscending()) {
     161                cc = -cc;
     162            }
    241163
    242                         return cc;
    243                 }
    244         }
     164            return cc;
     165        }
     166    }
    245167}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AbstractAddressEditAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    4331@SuppressWarnings("serial")
    4432public abstract class AbstractAddressEditAction extends JosmAction implements IAddressEditContainerListener, ICommandListener {
    45         private AddressEditSelectionEvent event;
    46         protected AddressEditContainer container;
    47         protected List<Command> commands;
    48         private String txName;
    49 
    50         /**
    51          * @param name
    52          * @param icon
    53          */
    54         public AbstractAddressEditAction(String name, String iconName, String tooltip, String toolbar) {
    55                 super(name, iconName, tooltip, null, true, toolbar, true);
    56 
    57                 setEnabled(false);
    58         }
    59 
    60         /**
    61          * @param name
    62          */
    63         public AbstractAddressEditAction(String name) {
    64                 this(name, null, "", null);
    65         }
    66 
    67         /**
    68          * Gets the current address container.
    69          * @return the container
    70          */
    71         public AddressEditContainer getContainer() {
    72                 return container;
    73         }
    74 
    75         /**
    76          * @param container the container to set
    77          */
    78         public void setContainer(AddressEditContainer container) {
    79                 if (container != null) { // remove old listener first
    80                         container.removeChangedListener(this);
    81                 }
    82                 this.container = container;
    83                 updateEnabledState();
    84                 if (container != null) {
    85                         container.addChangedListener(this);
    86                 }
    87         }
    88 
    89         /**
    90          * @return the event
    91          */
    92         protected AddressEditSelectionEvent getEvent() {
    93                 return event;
    94         }
    95 
    96         /**
    97          * @param event the event to set
    98          */
    99         public void setEvent(AddressEditSelectionEvent event) {
    100                 this.event = event;
    101                 updateEnabledState();
    102         }
    103 
    104         /* (non-Javadoc)
    105          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    106          */
    107         @Override
    108         public void actionPerformed(ActionEvent arg0) {
    109                 if (event != null) { // use the event acquired previously.
    110                         addressEditActionPerformed(event);
    111                         event = null; // consume event
    112                 } else {
    113                         if (container != null) {
    114                                 addressEditActionPerformed(container);
    115                         } else {
    116                                 throw new RuntimeException("AbstractAddressEditAction has no container or event");
    117                         }
    118                 }
    119         }
    120 
    121         /* (non-Javadoc)
    122          * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState()
    123          */
    124         @Override
    125         protected void updateEnabledState() {
    126                 if (this.event != null) {
    127                         updateEnabledState(this.event);
    128                 } else {
    129                         if (container != null) {
    130                                 updateEnabledState(container);
    131                         } else {
    132                                 super.updateEnabledState();
    133                         }
    134                 }
    135         }
    136 
    137         /**
    138          * Updates 'enabled' state depending on the given address container object.
    139          * @param container The address container (maybe null).
    140          * @return
    141          */
    142         protected abstract void updateEnabledState(AddressEditContainer container);
    143 
    144         /**
    145          * Updates 'enabled' state depending on the current selection.
    146          * @param container The selection event.
    147          * @return
    148          */
    149         protected abstract void updateEnabledState(AddressEditSelectionEvent event);
    150 
    151         /**
    152          * Redirected action handler for doing actions on a address selection.
    153          * @param ev
    154          */
    155         public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev);
    156 
    157         /**
    158          * Redirected action handler for doing actions on an address container.
    159          * @param ev
    160          */
    161         public abstract void addressEditActionPerformed(AddressEditContainer container);
    162 
    163 
    164         /* (non-Javadoc)
    165          * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#containerChanged(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    166          */
    167         @Override
    168         public void containerChanged(AddressEditContainer container) {
    169                 updateEnabledState();
    170         }
    171 
    172         /* (non-Javadoc)
    173          * @see org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener#entityChanged(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity)
    174          */
    175         @Override
    176         public void entityChanged(IOSMEntity node) {
    177                 container.removeProblemsOfSource(node); // clear problems of changed node...
    178                 node.visit(container, container);                   // .. and revisit it.
    179                 updateEnabledState();
    180         }
    181 
    182         /**
    183          * Begins the transaction (command sequence). Must be called by every subclass before
    184          * any modification on OSM objects starts.
    185          *
    186          * @param txName the name of the transaction (e. g. "change address tags").
    187          */
    188         public void beginTransaction(String txName) {
    189                 if (commands != null && commands.size() > 0) {
    190                         throw new RuntimeException("TX has not been closed (missing finishTransaction?)");
    191                 }
    192 
    193                 commands = new ArrayList<Command>();
    194                 if (StringUtils.isNullOrEmpty(txName)) {
    195                         throw new RuntimeException("Transaction must have a name");
    196                 }
    197                 this.txName = txName;
    198         }
    199 
    200         /**
    201          * Finishes the transaction and passes the command sequence to the framework.
    202          */
    203         public void finishTransaction() {
    204                 if (commands == null) {
    205                         throw new RuntimeException("No command list available. Did you forget to call beginTransaction?");
    206                 }
    207                 // execute the command
    208                 Main.main.undoRedo.add(new SequenceCommand(txName, commands));
    209                 commands.clear();
    210                 container.invalidate();
    211         }
    212 
    213         /**
    214          * Begins the transaction for a single object.
    215          *
    216          * @param entity the entity
    217          */
    218         public void beginObjectTransaction(IOSMEntity entity) {
    219                 if (entity != null) {
    220                         entity.addCommandListener(this);
    221                 } else {
    222                         throw new RuntimeException("Entity must not be null");
    223                 }
    224         }
    225 
    226         /**
    227          * Finishes the transaction for a single object.
    228          *
    229          * @param entity the entity
    230          */
    231         public void finishObjectTransaction(IOSMEntity entity) {
    232                 if (entity != null) {
    233                         entity.removeCommandListener(this);
    234                 } else {
    235                         throw new RuntimeException("Entity must not be null");
    236                 }
    237         }
    238 
    239         /* (non-Javadoc)
    240          * @see org.openstreetmap.josm.plugins.fixAddresses.ICommandListener#commandIssued(org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity, org.openstreetmap.josm.command.Command)
    241          */
    242         @Override
    243         public void commandIssued(IOSMEntity entity, Command command) {
    244                 if (commands == null) {
    245                         throw new RuntimeException("No command list available. Did you forget to call beginTransaction?");
    246                 }
    247                 commands.add(command);
    248         }
     33    private AddressEditSelectionEvent event;
     34    protected AddressEditContainer container;
     35    protected List<Command> commands;
     36    private String txName;
     37
     38    /**
     39     * @param name
     40     * @param icon
     41     */
     42    public AbstractAddressEditAction(String name, String iconName, String tooltip, String toolbar) {
     43        super(name, iconName, tooltip, null, true, toolbar, true);
     44
     45        setEnabled(false);
     46    }
     47
     48    /**
     49     * @param name
     50     */
     51    public AbstractAddressEditAction(String name) {
     52        this(name, null, "", null);
     53    }
     54
     55    /**
     56     * Gets the current address container.
     57     * @return the container
     58     */
     59    public AddressEditContainer getContainer() {
     60        return container;
     61    }
     62
     63    /**
     64     * @param container the container to set
     65     */
     66    public void setContainer(AddressEditContainer container) {
     67        if (container != null) { // remove old listener first
     68            container.removeChangedListener(this);
     69        }
     70        this.container = container;
     71        updateEnabledState();
     72        if (container != null) {
     73            container.addChangedListener(this);
     74        }
     75    }
     76
     77    /**
     78     * @return the event
     79     */
     80    protected AddressEditSelectionEvent getEvent() {
     81        return event;
     82    }
     83
     84    /**
     85     * @param event the event to set
     86     */
     87    public void setEvent(AddressEditSelectionEvent event) {
     88        this.event = event;
     89        updateEnabledState();
     90    }
     91
     92    @Override
     93    public void actionPerformed(ActionEvent arg0) {
     94        if (event != null) { // use the event acquired previously.
     95            addressEditActionPerformed(event);
     96            event = null; // consume event
     97        } else {
     98            if (container != null) {
     99                addressEditActionPerformed(container);
     100            } else {
     101                throw new RuntimeException("AbstractAddressEditAction has no container or event");
     102            }
     103        }
     104    }
     105
     106    @Override
     107    protected void updateEnabledState() {
     108        if (this.event != null) {
     109            updateEnabledState(this.event);
     110        } else {
     111            if (container != null) {
     112                updateEnabledState(container);
     113            } else {
     114                super.updateEnabledState();
     115            }
     116        }
     117    }
     118
     119    /**
     120     * Updates 'enabled' state depending on the given address container object.
     121     * @param container The address container (maybe null).
     122     * @return
     123     */
     124    protected abstract void updateEnabledState(AddressEditContainer container);
     125
     126    /**
     127     * Updates 'enabled' state depending on the current selection.
     128     * @param container The selection event.
     129     * @return
     130     */
     131    protected abstract void updateEnabledState(AddressEditSelectionEvent event);
     132
     133    /**
     134     * Redirected action handler for doing actions on a address selection.
     135     * @param ev
     136     */
     137    public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev);
     138
     139    /**
     140     * Redirected action handler for doing actions on an address container.
     141     * @param ev
     142     */
     143    public abstract void addressEditActionPerformed(AddressEditContainer container);
     144
     145    @Override
     146    public void containerChanged(AddressEditContainer container) {
     147        updateEnabledState();
     148    }
     149
     150    @Override
     151    public void entityChanged(IOSMEntity node) {
     152        container.removeProblemsOfSource(node); // clear problems of changed node...
     153        node.visit(container, container);                   // .. and revisit it.
     154        updateEnabledState();
     155    }
     156
     157    /**
     158     * Begins the transaction (command sequence). Must be called by every subclass before
     159     * any modification on OSM objects starts.
     160     *
     161     * @param txName the name of the transaction (e. g. "change address tags").
     162     */
     163    public void beginTransaction(String txName) {
     164        if (commands != null && commands.size() > 0) {
     165            throw new RuntimeException("TX has not been closed (missing finishTransaction?)");
     166        }
     167
     168        commands = new ArrayList<Command>();
     169        if (StringUtils.isNullOrEmpty(txName)) {
     170            throw new RuntimeException("Transaction must have a name");
     171        }
     172        this.txName = txName;
     173    }
     174
     175    /**
     176     * Finishes the transaction and passes the command sequence to the framework.
     177     */
     178    public void finishTransaction() {
     179        if (commands == null) {
     180            throw new RuntimeException("No command list available. Did you forget to call beginTransaction?");
     181        }
     182        // execute the command
     183        Main.main.undoRedo.add(new SequenceCommand(txName, commands));
     184        commands.clear();
     185        container.invalidate();
     186    }
     187
     188    /**
     189     * Begins the transaction for a single object.
     190     *
     191     * @param entity the entity
     192     */
     193    public void beginObjectTransaction(IOSMEntity entity) {
     194        if (entity != null) {
     195            entity.addCommandListener(this);
     196        } else {
     197            throw new RuntimeException("Entity must not be null");
     198        }
     199    }
     200
     201    /**
     202     * Finishes the transaction for a single object.
     203     *
     204     * @param entity the entity
     205     */
     206    public void finishObjectTransaction(IOSMEntity entity) {
     207        if (entity != null) {
     208            entity.removeCommandListener(this);
     209        } else {
     210            throw new RuntimeException("Entity must not be null");
     211        }
     212    }
     213
     214    @Override
     215    public void commandIssued(IOSMEntity entity, Command command) {
     216        if (commands == null) {
     217            throw new RuntimeException("No command list available. Did you forget to call beginTransaction?");
     218        }
     219        commands.add(command);
     220    }
    249221}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AddressActions.java

    r27322 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
    14 
     1// License: GPL. For details, see LICENSE file.
    152package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    163
    174public final class AddressActions {
    18         /* Global action objects */
    19         private static SelectAddressesInMapAction selectAction = new SelectAddressesInMapAction();
    20         private static GuessAddressDataAction guessDataAction = new GuessAddressDataAction();
    21         private static ApplyAllGuessesAction applyGuessesAction = new ApplyAllGuessesAction();
    22         private static RemoveAddressTagsAction removeTagsAction = new RemoveAddressTagsAction();
    23         private static AssignAddressToStreetAction resolveAction = new AssignAddressToStreetAction();
    24         private static ConvertToRelationAction convertToRelationAction = new ConvertToRelationAction();
    25         private static ConvertAllToRelationAction convertAllToRelationAction = new ConvertAllToRelationAction();
    26        
    27         public static SelectAddressesInMapAction getSelectAction() {
    28                 return selectAction;
    29         }
    30         public static GuessAddressDataAction getGuessAddressAction() {
    31                 return guessDataAction;
    32         }
    33         public static ApplyAllGuessesAction getApplyGuessesAction() {
    34                 return applyGuessesAction;
    35         }
    36         public static RemoveAddressTagsAction getRemoveTagsAction() {
    37                 return removeTagsAction;
    38         }
    39         public static AssignAddressToStreetAction getResolveAction() {
    40                 return resolveAction;
    41         }
    42         public static ConvertToRelationAction getConvertToRelationAction() {
    43                 return convertToRelationAction;
    44         }
    45         public static ConvertAllToRelationAction getConvertAllToRelationAction() {
    46                 return convertAllToRelationAction;
    47         }
     5    /* Global action objects */
     6    private static SelectAddressesInMapAction selectAction = new SelectAddressesInMapAction();
     7    private static GuessAddressDataAction guessDataAction = new GuessAddressDataAction();
     8    private static ApplyAllGuessesAction applyGuessesAction = new ApplyAllGuessesAction();
     9    private static RemoveAddressTagsAction removeTagsAction = new RemoveAddressTagsAction();
     10    private static AssignAddressToStreetAction resolveAction = new AssignAddressToStreetAction();
     11    private static ConvertToRelationAction convertToRelationAction = new ConvertToRelationAction();
     12    private static ConvertAllToRelationAction convertAllToRelationAction = new ConvertAllToRelationAction();
     13   
     14    public static SelectAddressesInMapAction getSelectAction() {
     15        return selectAction;
     16    }
     17    public static GuessAddressDataAction getGuessAddressAction() {
     18        return guessDataAction;
     19    }
     20    public static ApplyAllGuessesAction getApplyGuessesAction() {
     21        return applyGuessesAction;
     22    }
     23    public static RemoveAddressTagsAction getRemoveTagsAction() {
     24        return removeTagsAction;
     25    }
     26    public static AssignAddressToStreetAction getResolveAction() {
     27        return resolveAction;
     28    }
     29    public static ConvertToRelationAction getConvertToRelationAction() {
     30        return convertToRelationAction;
     31    }
     32    public static ConvertAllToRelationAction getConvertAllToRelationAction() {
     33        return convertAllToRelationAction;
     34    }
    4835}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ApplyAllGuessesAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    3624 *
    3725 */
    38 
    3926@SuppressWarnings("serial")
    4027public class ApplyAllGuessesAction extends AbstractAddressEditAction implements MouseListener{
    41         private String tag;
    42         /**
    43         * Instantiates a new "apply all guesses" action.
    44         */
    45         public ApplyAllGuessesAction(String tag) {
    46                 super(tr("Apply"), "applyguesses_24", tr("Turns all guesses into the corresponding tag values."),
    47                         "fixaddresses/applyallguesses");
    48                 this.tag = tag;
    49         }
     28    private String tag;
     29    /**
     30    * Instantiates a new "apply all guesses" action.
     31    */
     32    public ApplyAllGuessesAction(String tag) {
     33        super(tr("Apply"), "applyguesses_24", tr("Turns all guesses into the corresponding tag values."),
     34            "fixaddresses/applyallguesses");
     35        this.tag = tag;
     36    }
    5037
    51         /**
    52         * Instantiates a new "apply all guesses" action.
    53         */
    54         public ApplyAllGuessesAction() {
    55                 this(null);
    56         }
     38    /**
     39    * Instantiates a new "apply all guesses" action.
     40    */
     41    public ApplyAllGuessesAction() {
     42        this(null);
     43    }
    5744
    58         /* (non-Javadoc)
    59          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent)
    60          */
    61         @Override
    62         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    63                 if (ev == null) return;
     45    @Override
     46    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     47        if (ev == null) return;
    6448
    65                 if (ev.getSelectedUnresolvedAddresses() != null) {
    66                         List<OSMAddress> addrToFix = ev.getSelectedUnresolvedAddresses();
    67                         applyGuesses(addrToFix);
    68                 }
     49        if (ev.getSelectedUnresolvedAddresses() != null) {
     50            List<OSMAddress> addrToFix = ev.getSelectedUnresolvedAddresses();
     51            applyGuesses(addrToFix);
     52        }
    6953
    70                 if (ev.getSelectedIncompleteAddresses() != null) {
    71                         List<OSMAddress> addrToFix = ev.getSelectedIncompleteAddresses();
    72                         applyGuesses(addrToFix);
    73                 }
    74         }
     54        if (ev.getSelectedIncompleteAddresses() != null) {
     55            List<OSMAddress> addrToFix = ev.getSelectedIncompleteAddresses();
     56            applyGuesses(addrToFix);
     57        }
     58    }
    7559
    76         /* (non-Javadoc)
    77          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    78          */
    79         @Override
    80         protected void updateEnabledState(AddressEditContainer container) {
    81                 setEnabled(container != null && container.getNumberOfGuesses() > 0);
    82         }
     60    @Override
     61    protected void updateEnabledState(AddressEditContainer container) {
     62        setEnabled(container != null && container.getNumberOfGuesses() > 0);
     63    }
    8364
    84         /**
    85         * Apply guesses.
    86         *
    87         * @param addrToFix the addr to fix
    88         */
    89         private void applyGuesses(List<OSMAddress> addrToFix) {
    90                 beginTransaction(tr("Applied guessed values"));
    91                 List<OSMAddress> addrToFixShadow = new ArrayList<OSMAddress>(addrToFix);
    92                 for (OSMAddress aNode : addrToFixShadow) {
    93                         beginObjectTransaction(aNode);
     65    /**
     66    * Apply guesses.
     67    *
     68    * @param addrToFix the addr to fix
     69    */
     70    private void applyGuesses(List<OSMAddress> addrToFix) {
     71        beginTransaction(tr("Applied guessed values"));
     72        List<OSMAddress> addrToFixShadow = new ArrayList<OSMAddress>(addrToFix);
     73        for (OSMAddress aNode : addrToFixShadow) {
     74            beginObjectTransaction(aNode);
    9475
    95                         if (StringUtils.isNullOrEmpty(tag)) { // tag given?
    96                                 aNode.applyAllGuesses(); // no -> apply all guesses
    97                         } else { // apply guessed values for single tag only
    98                                 aNode.applyGuessForTag(tag);
    99                         }
    100                         finishObjectTransaction(aNode);
    101                 }
    102                 finishTransaction();
    103         }
     76            if (StringUtils.isNullOrEmpty(tag)) { // tag given?
     77                aNode.applyAllGuesses(); // no -> apply all guesses
     78            } else { // apply guessed values for single tag only
     79                aNode.applyGuessForTag(tag);
     80            }
     81            finishObjectTransaction(aNode);
     82        }
     83        finishTransaction();
     84    }
    10485
    105         /* (non-Javadoc)
    106          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent)
    107          */
    108         @Override
    109         protected void updateEnabledState(AddressEditSelectionEvent event) {
    110                 setEnabled(event.hasAddressesWithGuesses());
    111         }
     86    @Override
     87    protected void updateEnabledState(AddressEditSelectionEvent event) {
     88        setEnabled(event.hasAddressesWithGuesses());
     89    }
    11290
    113         /* (non-Javadoc)
    114          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    115          */
    116         @Override
    117         public void addressEditActionPerformed(AddressEditContainer container) {
    118                 if (container == null || container.getNumberOfIncompleteAddresses() == 0) return;
     91    @Override
     92    public void addressEditActionPerformed(AddressEditContainer container) {
     93        if (container == null || container.getNumberOfIncompleteAddresses() == 0) return;
    11994
    120                 List<OSMAddress> addrToFix = container.getUnresolvedAddresses();
    121                 applyGuesses(addrToFix);
     95        List<OSMAddress> addrToFix = container.getUnresolvedAddresses();
     96        applyGuesses(addrToFix);
    12297
    123                 addrToFix = container.getIncompleteAddresses();
    124                 applyGuesses(addrToFix);
    125         }
     98        addrToFix = container.getIncompleteAddresses();
     99        applyGuesses(addrToFix);
     100    }
    126101
    127         /* (non-Javadoc)
    128          * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
    129          */
    130         @Override
    131         public void mouseClicked(MouseEvent e) {
    132                 JTable table = (JTable)e.getSource();
    133                 Point p = e.getPoint();
    134                 if(e.getClickCount() == 2) {
    135                         AddressEditTableModel model = (AddressEditTableModel) table.getModel();
    136                         if (model != null) {
    137                                 int row = table.rowAtPoint(p);
    138                                 IOSMEntity node = model.getEntityOfRow(row);
    139                                 if (node instanceof OSMAddress) {
    140                                         beginTransaction(tr("Applied guessed values for ") + node.getOsmObject());
    141                                         beginObjectTransaction(node);
    142                                         OSMAddress aNode = (OSMAddress) node;
     102    @Override
     103    public void mouseClicked(MouseEvent e) {
     104        JTable table = (JTable)e.getSource();
     105        Point p = e.getPoint();
     106        if(e.getClickCount() == 2) {
     107            AddressEditTableModel model = (AddressEditTableModel) table.getModel();
     108            if (model != null) {
     109                int row = table.rowAtPoint(p);
     110                IOSMEntity node = model.getEntityOfRow(row);
     111                if (node instanceof OSMAddress) {
     112                    beginTransaction(tr("Applied guessed values for ") + node.getOsmObject());
     113                    beginObjectTransaction(node);
     114                    OSMAddress aNode = (OSMAddress) node;
    143115
    144                                         aNode.applyAllGuesses();
     116                    aNode.applyAllGuesses();
    145117
    146                                         finishObjectTransaction(node);
    147                                         finishTransaction();
    148                                 }
    149                         }
    150                 }
    151         }
     118                    finishObjectTransaction(node);
     119                    finishTransaction();
     120                }
     121            }
     122        }
     123    }
    152124
    153         /* (non-Javadoc)
    154          * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
    155          */
    156         @Override
    157         public void mouseEntered(MouseEvent arg0) {
    158         }
     125    @Override
     126    public void mouseEntered(MouseEvent arg0) {
     127    }
    159128
    160         /* (non-Javadoc)
    161          * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
    162          */
    163         @Override
    164         public void mouseExited(MouseEvent arg0) {
    165         }
     129    @Override
     130    public void mouseExited(MouseEvent arg0) {
     131    }
    166132
    167         /* (non-Javadoc)
    168          * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
    169          */
    170         @Override
    171         public void mousePressed(MouseEvent arg0) {
    172         }
     133    @Override
     134    public void mousePressed(MouseEvent arg0) {
     135    }
    173136
    174         /* (non-Javadoc)
    175          * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
    176          */
    177         @Override
    178         public void mouseReleased(MouseEvent arg0) {
    179         }
     137    @Override
     138    public void mouseReleased(MouseEvent arg0) {
     139    }
    180140}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AssignAddressToStreetAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    2917public class AssignAddressToStreetAction extends AbstractAddressEditAction  {
    3018
    31         /**
    32         * Instantiates a new "assign address to street" action.
    33         */
    34         public AssignAddressToStreetAction() {
    35                 super(tr("Assign address to street"), "assignstreet_24",
    36                         tr("Assign the selected address(es) to the selected street."),
    37                         "fixaddresses/assignaddresstostreet");
    38         }
     19    /**
     20    * Instantiates a new "assign address to street" action.
     21    */
     22    public AssignAddressToStreetAction() {
     23        super(tr("Assign address to street"), "assignstreet_24",
     24            tr("Assign the selected address(es) to the selected street."),
     25            "fixaddresses/assignaddresstostreet");
     26    }
    3927
    40         /**
    41         *
    42         */
    43         private static final long serialVersionUID = -6180491357232121384L;
     28    /**
     29    *
     30    */
     31    private static final long serialVersionUID = -6180491357232121384L;
    4432
    45         /* (non-Javadoc)
    46          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    47          */
    48         @Override
    49         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    50                 OSMStreet streetNode = ev.getSelectedStreet();
     33    @Override
     34    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     35        OSMStreet streetNode = ev.getSelectedStreet();
    5136
    52                 if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) {
    53                         beginTransaction(tr("Set street name") + " '" + streetNode.getName() + "'");
    54                         for (OSMAddress addrNode : ev.getSelectedUnresolvedAddresses()) {
    55                                 beginObjectTransaction(addrNode);
    56                                 addrNode.assignStreet(streetNode);
    57                                 finishObjectTransaction(addrNode);
    58                         }
    59                         finishTransaction();
    60                 }
     37        if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) {
     38            beginTransaction(tr("Set street name") + " '" + streetNode.getName() + "'");
     39            for (OSMAddress addrNode : ev.getSelectedUnresolvedAddresses()) {
     40                beginObjectTransaction(addrNode);
     41                addrNode.assignStreet(streetNode);
     42                finishObjectTransaction(addrNode);
     43            }
     44            finishTransaction();
     45        }
    6146
    62         }
     47    }
    6348
    64         /* (non-Javadoc)
    65          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    66          */
    67         @Override
    68         public void updateEnabledState(AddressEditSelectionEvent ev) {
    69                 setEnabled(ev.getSelectedStreet() != null && ev.hasUnresolvedAddresses());
    70         }
     49    @Override
     50    public void updateEnabledState(AddressEditSelectionEvent ev) {
     51        setEnabled(ev.getSelectedStreet() != null && ev.hasUnresolvedAddresses());
     52    }
    7153
    72         @Override
    73         public void updateEnabledState(AddressEditContainer container) {
    74                 // we only accept a selection here
    75                 setEnabled(false);
    76         }
     54    @Override
     55    public void updateEnabledState(AddressEditContainer container) {
     56        // we only accept a selection here
     57        setEnabled(false);
     58    }
    7759
    78         @Override
    79         public void addressEditActionPerformed(AddressEditContainer container) {
    80                 // we only accept a selection: nothing to do here
    81         }
     60    @Override
     61    public void addressEditActionPerformed(AddressEditContainer container) {
     62        // we only accept a selection: nothing to do here
     63    }
    8264
    8365
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ConvertAllToRelationAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    2210@SuppressWarnings("serial")
    2311public class ConvertAllToRelationAction extends ConvertToRelationAction {
    24         public ConvertAllToRelationAction() {
    25                 super(tr("Convert ALL streets."), "convert2rel_24",
    26                         tr("Create relation between street and related addresses for ALL streets in the current layer."),
    27                         "fixaddresses/convertalltorelation");
    28         }
     12    public ConvertAllToRelationAction() {
     13        super(tr("Convert ALL streets."), "convert2rel_24",
     14            tr("Create relation between street and related addresses for ALL streets in the current layer."),
     15            "fixaddresses/convertalltorelation");
     16    }
    2917
    30         @Override
    31         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    32                 // nothing to do
    33         }
     18    @Override
     19    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     20        // nothing to do
     21    }
    3422
    35         @Override
    36         public void addressEditActionPerformed(AddressEditContainer container) {
    37                 if (container != null) {
    38                         for (OSMStreet street : container.getStreetList()) {
    39                                 createRelationForStreet(street);
    40                         }
    41                 }
    42         }
     23    @Override
     24    public void addressEditActionPerformed(AddressEditContainer container) {
     25        if (container != null) {
     26            for (OSMStreet street : container.getStreetList()) {
     27                createRelationForStreet(street);
     28            }
     29        }
     30    }
    4331
    44         @Override
    45         protected void updateEnabledState(AddressEditContainer container) {
    46                 setEnabled(hasStreetsToConvert());
    47         }
     32    @Override
     33    protected void updateEnabledState(AddressEditContainer container) {
     34        setEnabled(hasStreetsToConvert());
     35    }
    4836
    49         @Override
    50         protected void updateEnabledState(AddressEditSelectionEvent event) {
    51                 setEnabled(hasStreetsToConvert());
    52         }
     37    @Override
     38    protected void updateEnabledState(AddressEditSelectionEvent event) {
     39        setEnabled(hasStreetsToConvert());
     40    }
    5341
    54         /**
    55         * Checks for streets to convert to a relation.
    56         *
    57         * @return true, if successful
    58         */
    59         private boolean hasStreetsToConvert() {
    60                 if (container != null) {
    61                         for (OSMStreet street : container.getStreetList()) {
    62                                 if (street.hasAddresses() && !street.hasAssociatedStreetRelation()) {
    63                                         return true;
    64                                 }
    65                         }
    66                 }
    67                 return false;
    68         }
     42    /**
     43    * Checks for streets to convert to a relation.
     44    *
     45    * @return true, if successful
     46    */
     47    private boolean hasStreetsToConvert() {
     48        if (container != null) {
     49            for (OSMStreet street : container.getStreetList()) {
     50                if (street.hasAddresses() && !street.hasAssociatedStreetRelation()) {
     51                    return true;
     52                }
     53            }
     54        }
     55        return false;
     56    }
    6957
    7058}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/ConvertToRelationAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    2917public class ConvertToRelationAction extends AbstractAddressEditAction {
    3018
    31         public ConvertToRelationAction() {
    32                 super(tr("Convert to relation."), "convert2rel_24",
    33                         tr("Create relation between street and related addresses."),
    34                         "fixaddresses/converttorelation");
    35         }
     19    public ConvertToRelationAction() {
     20        super(tr("Convert to relation."), "convert2rel_24",
     21            tr("Create relation between street and related addresses."),
     22            "fixaddresses/converttorelation");
     23    }
    3624
    37         /**
    38         * Instantiates a new convert to relation action.
    39         *
    40         * @param name the name of the action
    41         * @param iconName the icon name
    42         * @param tooltip the tool tip to show on hover
    43         */
    44         public ConvertToRelationAction(String name, String iconName, String tooltip, String toolbar) {
    45                 super(name, iconName, tooltip, toolbar);
    46         }
     25    /**
     26    * Instantiates a new convert to relation action.
     27    *
     28    * @param name the name of the action
     29    * @param iconName the icon name
     30    * @param tooltip the tool tip to show on hover
     31    */
     32    public ConvertToRelationAction(String name, String iconName, String tooltip, String toolbar) {
     33        super(name, iconName, tooltip, toolbar);
     34    }
    4735
    48         /* (non-Javadoc)
    49          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent)
    50          */
    51         @Override
    52         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    53                 OSMStreet streetNode = ev.getSelectedStreet();
     36    @Override
     37    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     38        OSMStreet streetNode = ev.getSelectedStreet();
    5439
    55                 if (streetNode != null) {
    56                         createRelationForStreet(streetNode);
    57                 }
    58         }
     40        if (streetNode != null) {
     41            createRelationForStreet(streetNode);
     42        }
     43    }
    5944
    60         /**
    61         * Creates the 'associatedStreet' relation for a given street by adding all addresses which
    62         * matches the name of the street.
    63         *
    64         * @param streetNode the street node
    65         */
    66         protected void createRelationForStreet(OSMStreet streetNode) {
    67                 if (streetNode == null || !streetNode.hasAddresses()) return;
     45    /**
     46    * Creates the 'associatedStreet' relation for a given street by adding all addresses which
     47    * matches the name of the street.
     48    *
     49    * @param streetNode the street node
     50    */
     51    protected void createRelationForStreet(OSMStreet streetNode) {
     52        if (streetNode == null || !streetNode.hasAddresses()) return;
    6853
    69                 beginTransaction(tr("Create address relation for ") + " '" + streetNode.getName() + "'");
    70                 // Create the relation
    71                 Relation r = new Relation();
    72                 commands.add(new AddCommand(r));
    73                 commands.add(new ChangePropertyCommand(r, TagUtils.NAME_TAG, streetNode.getName()));
    74                 commands.add(new ChangePropertyCommand(r, TagUtils.RELATION_TYPE, TagUtils.ASSOCIATEDSTREET_RELATION_TYPE));
    75                 // add street with role 'street'
    76                 r.addMember(new RelationMember(TagUtils.STREET_RELATION_ROLE, streetNode.getOsmObject()));
     54        beginTransaction(tr("Create address relation for ") + " '" + streetNode.getName() + "'");
     55        // Create the relation
     56        Relation r = new Relation();
     57        commands.add(new AddCommand(r));
     58        commands.add(new ChangePropertyCommand(r, TagUtils.NAME_TAG, streetNode.getName()));
     59        commands.add(new ChangePropertyCommand(r, TagUtils.RELATION_TYPE, TagUtils.ASSOCIATEDSTREET_RELATION_TYPE));
     60        // add street with role 'street'
     61        r.addMember(new RelationMember(TagUtils.STREET_RELATION_ROLE, streetNode.getOsmObject()));
    7762
    78                 // add address members
    79                 for (OSMAddress addrNode : streetNode.getAddresses()) {
    80                         beginObjectTransaction(addrNode);
    81                         r.addMember(new RelationMember(TagUtils.HOUSE_RELATION_ROLE, addrNode.getOsmObject()));
    82                         addrNode.setStreetName(null); // remove street name
    83                         finishObjectTransaction(addrNode);
    84                 }
    85                 finishTransaction();
    86         }
     63        // add address members
     64        for (OSMAddress addrNode : streetNode.getAddresses()) {
     65            beginObjectTransaction(addrNode);
     66            r.addMember(new RelationMember(TagUtils.HOUSE_RELATION_ROLE, addrNode.getOsmObject()));
     67            addrNode.setStreetName(null); // remove street name
     68            finishObjectTransaction(addrNode);
     69        }
     70        finishTransaction();
     71    }
    8772
    88         /* (non-Javadoc)
    89          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    90          */
    91         @Override
    92         public void addressEditActionPerformed(AddressEditContainer container) {
    93                 // Nothing to do (yet).
    94         }
     73    @Override
     74    public void addressEditActionPerformed(AddressEditContainer container) {
     75        // Nothing to do (yet).
     76    }
    9577
    96         /* (non-Javadoc)
    97          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    98          */
    99         @Override
    100         protected void updateEnabledState(AddressEditContainer container) {
    101                 setEnabled(false);
    102         }
     78    @Override
     79    protected void updateEnabledState(AddressEditContainer container) {
     80        setEnabled(false);
     81    }
    10382
    104         /* (non-Javadoc)
    105          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent)
    106          */
    107         @Override
    108         protected void updateEnabledState(AddressEditSelectionEvent event) {
    109                 if (event == null) return;
     83    @Override
     84    protected void updateEnabledState(AddressEditSelectionEvent event) {
     85        if (event == null) return;
    11086
    111                 OSMStreet street = event.getSelectedStreet();
    112                 setEnabled(street != null && street.hasAddresses() && !street.hasAssociatedStreetRelation());
    113         }
    114 
     87        OSMStreet street = event.getSelectedStreet();
     88        setEnabled(street != null && street.hasAddresses() && !street.hasAssociatedStreetRelation());
     89    }
    11590}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/GuessAddressDataAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    3119 * @author Oliver Wieland <oliver.wieland@online.de>
    3220 */
    33 
    3421@SuppressWarnings("serial")
    3522public class GuessAddressDataAction extends AbstractAddressEditAction implements IProgressMonitorFinishedListener {
    3623
    37         /**
    38         * Instantiates a new "guess address data" action.
    39         */
    40         public GuessAddressDataAction() {
    41                 super(tr("Guess"), "guessstreets_24", tr("Tries to guess address data by picking the name of the closest object with according tag."),
    42                         "fixaddresses/guessaddressdata");
    43         }
     24    /**
     25    * Instantiates a new "guess address data" action.
     26    */
     27    public GuessAddressDataAction() {
     28        super(tr("Guess"), "guessstreets_24", tr("Tries to guess address data by picking the name of the closest object with according tag."),
     29            "fixaddresses/guessaddressdata");
     30    }
    4431
    45         /* (non-Javadoc)
    46          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    47          */
    48         @Override
    49         public void updateEnabledState(AddressEditSelectionEvent ev) {
    50                 setEnabled(ev != null && ev.hasAddresses());
    51         }
     32    @Override
     33    public void updateEnabledState(AddressEditSelectionEvent ev) {
     34        setEnabled(ev != null && ev.hasAddresses());
     35    }
    5236
    53         /* (non-Javadoc)
    54          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    55          */
    56         @Override
    57         protected void updateEnabledState(AddressEditContainer container) {
    58                 setEnabled(container != null && container.getNumberOfInvalidAddresses() > 0);
    59         }
     37    @Override
     38    protected void updateEnabledState(AddressEditContainer container) {
     39        setEnabled(container != null && container.getNumberOfInvalidAddresses() > 0);
     40    }
    6041
    61         /* (non-Javadoc)
    62          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer)
    63          */
    64         @Override
    65         public void addressEditActionPerformed(AddressEditContainer container) {
    66                 if (container == null || container.getNumberOfInvalidAddresses() == 0) return;
     42    @Override
     43    public void addressEditActionPerformed(AddressEditContainer container) {
     44        if (container == null || container.getNumberOfInvalidAddresses() == 0) return;
    6745
    68                 internalGuessAddresses(container.getAllAddressesToFix());
    69         }
     46        internalGuessAddresses(container.getAllAddressesToFix());
     47    }
    7048
    71         /* (non-Javadoc)
    72          * @see org.openstreetmap.josm.plugins.fixAddresses.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.fixAddresses.gui.AddressEditSelectionEvent)
    73          */
    74         @Override
    75         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    76                 if (ev == null || !ev.hasAddresses()) return;
     49    @Override
     50    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     51        if (ev == null || !ev.hasAddresses()) return;
    7752
    78                 // guess tags for selected addresses only
    79                 internalGuessAddresses(ev.getSelectedIncompleteAddresses());
    80                 internalGuessAddresses(ev.getSelectedUnresolvedAddresses());
    81         }
     53        // guess tags for selected addresses only
     54        internalGuessAddresses(ev.getSelectedIncompleteAddresses());
     55        internalGuessAddresses(ev.getSelectedUnresolvedAddresses());
     56    }
    8257
    83         /**
    84         * Internal method to start several threads guessing tag values for the given list of addresses.
    85         * @param addrNodes
    86         */
    87         private void internalGuessAddresses(List<OSMAddress> nodes) {
    88                 if (nodes == null) return;
     58    /**
     59    * Internal method to start several threads guessing tag values for the given list of addresses.
     60    * @param addrNodes
     61    */
     62    private void internalGuessAddresses(List<OSMAddress> nodes) {
     63        if (nodes == null) return;
    8964
    90                 // Launch address guessing thread
    91                 GuessAddressRunnable aft = new GuessAddressRunnable(nodes, tr("Guessing address values"));
    92                 aft.addFinishListener(this);
    93                 Main.worker.submit(aft);
    94         }
     65        // Launch address guessing thread
     66        GuessAddressRunnable aft = new GuessAddressRunnable(nodes, tr("Guessing address values"));
     67        aft.addFinishListener(this);
     68        Main.worker.submit(aft);
     69    }
    9570
    96         @Override
    97         public void finished() {
    98                 if (container != null) {
    99                         container.invalidate();
    100                 }
    101         }
     71    @Override
     72    public void finished() {
     73        if (container != null) {
     74            container.invalidate();
     75        }
     76    }
    10277}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/RemoveAddressTagsAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    2311public class RemoveAddressTagsAction extends AbstractAddressEditAction {
    2412
    25         public RemoveAddressTagsAction() {
    26                 super(tr("Remove"), "removeaddrtags_24", tr("Removes address related tags from the object."),
    27                         "fixaddresses/removeaddresstags");
    28         }
     13    public RemoveAddressTagsAction() {
     14        super(tr("Remove"), "removeaddrtags_24", tr("Removes address related tags from the object."),
     15            "fixaddresses/removeaddresstags");
     16    }
    2917
    30         @Override
    31         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    32                 beginTransaction(tr("Remove address tags"));
    33                 if (ev.hasUnresolvedAddresses()) {
    34                         for (OSMAddress aNode : ev.getSelectedUnresolvedAddresses()) {
    35                                 beginObjectTransaction(aNode);
    36                                 aNode.removeAllAddressTags();
    37                                 finishObjectTransaction(aNode);
    38                         }
    39                 }
     18    @Override
     19    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     20        beginTransaction(tr("Remove address tags"));
     21        if (ev.hasUnresolvedAddresses()) {
     22            for (OSMAddress aNode : ev.getSelectedUnresolvedAddresses()) {
     23                beginObjectTransaction(aNode);
     24                aNode.removeAllAddressTags();
     25                finishObjectTransaction(aNode);
     26            }
     27        }
    4028
    41                 if (ev.hasIncompleteAddresses()) {
    42                         for (OSMAddress aNode : ev.getSelectedIncompleteAddresses()) {
    43                                 beginObjectTransaction(aNode);
    44                                 aNode.removeAllAddressTags();
    45                                 finishObjectTransaction(aNode);
    46                         }
    47                 }
    48                 finishTransaction();
    49         }
     29        if (ev.hasIncompleteAddresses()) {
     30            for (OSMAddress aNode : ev.getSelectedIncompleteAddresses()) {
     31                beginObjectTransaction(aNode);
     32                aNode.removeAllAddressTags();
     33                finishObjectTransaction(aNode);
     34            }
     35        }
     36        finishTransaction();
     37    }
    5038
    51         @Override
    52         public void addressEditActionPerformed(AddressEditContainer container) {
    53                 // do nothing
    54         }
     39    @Override
     40    public void addressEditActionPerformed(AddressEditContainer container) {
     41        // do nothing
     42    }
    5543
    56         @Override
    57         protected void updateEnabledState(AddressEditContainer container) {
    58                 setEnabled(false);
    59         }
     44    @Override
     45    protected void updateEnabledState(AddressEditContainer container) {
     46        setEnabled(false);
     47    }
    6048
    61         @Override
    62         protected void updateEnabledState(AddressEditSelectionEvent event) {
    63                 if (event == null) {
    64                         setEnabled(false);
    65                 }
     49    @Override
     50    protected void updateEnabledState(AddressEditSelectionEvent event) {
     51        if (event == null) {
     52            setEnabled(false);
     53        }
    6654
    67                 setEnabled(event.hasAddresses());
    68         }
     55        setEnabled(event.hasAddresses());
     56    }
    6957
    7058}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/SelectAddressesInMapAction.java

    r27907 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
    14 /**
    15  * This program is free software: you can redistribute it and/or modify it under
    16  * the terms of the GNU General Public License as published by the
    17  * Free Software Foundation, either version 3 of the License, or
    18  * (at your option) any later version.
    19  *
    20  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    21  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    22  * See the GNU General Public License for more details.
    23  *
    24  * You should have received a copy of the GNU General Public License along with this program.
    25  * If not, see <http://www.gnu.org/licenses/>.
    26  */
    27 
    28 /* File created on 30.10.2010 */
     1// License: GPL. For details, see LICENSE file.
    292package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    303
     
    4518 *
    4619 */
    47 
    4820@SuppressWarnings("serial")
    4921public class SelectAddressesInMapAction extends AbstractAddressEditAction {
    5022
    51         /**
    52         * Instantiates a new "select addresses in map" action.
    53         */
    54         public SelectAddressesInMapAction() {
    55                 super(tr("Select"), "selectall", tr("Marks selected addresses in the map"),
    56                         "fixaddresses/selectaddressesinmap");
    57         }
     23    /**
     24    * Instantiates a new "select addresses in map" action.
     25    */
     26    public SelectAddressesInMapAction() {
     27        super(tr("Select"), "selectall", tr("Marks selected addresses in the map"),
     28            "fixaddresses/selectaddressesinmap");
     29    }
    5830
    59         /* (non-Javadoc)
    60          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#addressEditActionPerformed(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    61          */
    62         @Override
    63         public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
    64                 if (ev == null) return;
     31    @Override
     32    public void addressEditActionPerformed(AddressEditSelectionEvent ev) {
     33        if (ev == null) return;
    6534
    66                 if (ev.hasUnresolvedAddresses()) {
    67                         internalSelectAddresses(ev.getSelectedUnresolvedAddresses());
    68                 } else if (ev.hasIncompleteAddresses()) {
    69                         internalSelectAddresses(ev.getSelectedIncompleteAddresses());
    70                 }
    71         }
     35        if (ev.hasUnresolvedAddresses()) {
     36            internalSelectAddresses(ev.getSelectedUnresolvedAddresses());
     37        } else if (ev.hasIncompleteAddresses()) {
     38            internalSelectAddresses(ev.getSelectedIncompleteAddresses());
     39        }
     40    }
    7241
    73         @Override
    74         public void addressEditActionPerformed(AddressEditContainer container) {
    75                 // do nothing
    76         }
     42    @Override
     43    public void addressEditActionPerformed(AddressEditContainer container) {
     44        // do nothing
     45    }
    7746
    78         /* (non-Javadoc)
    79          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer)
    80          */
    81         @Override
    82         protected void updateEnabledState(AddressEditContainer container) {
    83                 setEnabled(false);
    84         }
     47    @Override
     48    protected void updateEnabledState(AddressEditContainer container) {
     49        setEnabled(false);
     50    }
    8551
    86         /* (non-Javadoc)
    87          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    88          */
    89         @Override
    90         protected void updateEnabledState(AddressEditSelectionEvent event) {
    91                 setEnabled(event != null && event.hasAddresses());
    92         }
     52    @Override
     53    protected void updateEnabledState(AddressEditSelectionEvent event) {
     54        setEnabled(event != null && event.hasAddresses());
     55    }
    9356
    94         /**
    95         * Internal helper to select the given addresses in the map.
    96         * @param addrToSel
    97         */
    98         private void internalSelectAddresses(List<OSMAddress> addrToSel) {
    99                 if (addrToSel == null) return;
     57    /**
     58    * Internal helper to select the given addresses in the map.
     59    * @param addrToSel
     60    */
     61    private void internalSelectAddresses(List<OSMAddress> addrToSel) {
     62        if (addrToSel == null) return;
    10063
    101                 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>();
     64        List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>();
    10265
    103                 getCurrentDataSet().clearSelection();
    104                 for (OSMAddress aNode : addrToSel) {
    105                         sel.add(aNode.getOsmObject());
     66        getCurrentDataSet().clearSelection();
     67        for (OSMAddress aNode : addrToSel) {
     68            sel.add(aNode.getOsmObject());
    10669
    107                         // Select also guessed objects, if wished
    108                         if (FixAddressesPlugin.getPreferences().isSelectGuessedObjects()) {
    109                                 for (OsmPrimitive osmPrimitive : aNode.getGuessedObjects()) {
    110                                         sel.add(osmPrimitive);
    111                                 }
    112                         }
    113                 }
     70            // Select also guessed objects, if wished
     71            if (FixAddressesPlugin.getPreferences().isSelectGuessedObjects()) {
     72                for (OsmPrimitive osmPrimitive : aNode.getGuessedObjects()) {
     73                    sel.add(osmPrimitive);
     74                }
     75            }
     76        }
    11477
    115                 getCurrentDataSet().setSelected(sel);
    116         }
     78        getCurrentDataSet().setSelected(sel);
     79    }
    11780
    11881}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/SelectIncompleteAddressesAction.java

    r25373 r30348  
    1 /*
    2  * This program is free software: you can redistribute it and/or modify it under
    3  * the terms of the GNU General Public License as published by the
    4  * Free Software Foundation, either version 3 of the License, or
    5  * (at your option) any later version.
    6  *
    7  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    8  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    9  * See the GNU General Public License for more details.
    10  *
    11  * You should have received a copy of the GNU General Public License along with this program.
    12  * If not, see <http://www.gnu.org/licenses/>.
    13  */
     1// License: GPL. For details, see LICENSE file.
    142package org.openstreetmap.josm.plugins.fixAddresses.gui.actions;
    153
     
    2917
    3018
    31         private AddressEditContainer addressEditContainer;
     19    private AddressEditContainer addressEditContainer;
    3220
    33         public SelectIncompleteAddressesAction() {
    34                 super(tr("Select incomplete addresses"), "select_invaddr_24",
    35                                 tr("Selects all addresses with incomplete data."), null, false);
    36         }
     21    public SelectIncompleteAddressesAction() {
     22        super(tr("Select incomplete addresses"), "select_invaddr_24",
     23                tr("Selects all addresses with incomplete data."), null, false);
     24    }
    3725
    38         @Override
    39         public void actionPerformed(ActionEvent arg0) {
    40                 addressEditContainer = new AddressEditContainer();
    41                 addressEditContainer.invalidate();
     26    @Override
     27    public void actionPerformed(ActionEvent arg0) {
     28        addressEditContainer = new AddressEditContainer();
     29        addressEditContainer.invalidate();
    4230
    43                 if (addressEditContainer.getIncompleteAddresses() != null) {
    44                         List<OsmPrimitive> osms = new ArrayList<OsmPrimitive>();
     31        if (addressEditContainer.getIncompleteAddresses() != null) {
     32            List<OsmPrimitive> osms = new ArrayList<OsmPrimitive>();
    4533
    46                         for (OSMAddress aNode : addressEditContainer.getIncompleteAddresses()) {
    47                                 osms.add(aNode.getOsmObject());
    48                         }
    49                         getCurrentDataSet().setSelected(osms);
    50                 }
    51         }
     34            for (OSMAddress aNode : addressEditContainer.getIncompleteAddresses()) {
     35                osms.add(aNode.getOsmObject());
     36            }
     37            getCurrentDataSet().setSelected(osms);
     38        }
     39    }
    5240
    53         /* (non-Javadoc)
    54          * @see org.openstreetmap.josm.actions.JosmAction#updateEnabledState()
    55          */
    56         @Override
    57         protected void updateEnabledState() {
    58                 setEnabled(getCurrentDataSet() != null);
    59         }
     41    @Override
     42    protected void updateEnabledState() {
     43        setEnabled(getCurrentDataSet() != null);
     44    }
    6045}
Note: See TracChangeset for help on using the changeset viewer.