Changeset 2411 in josm


Ignore:
Timestamp:
2009-11-08T15:54:40+01:00 (10 years ago)
Author:
jttt
Message:

Reimplement BackreferencedDataset using OsmPrimitive.getReferrers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/BackreferencedDataSet.java

    r2381 r2411  
    44import java.util.Collection;
    55import java.util.Collections;
    6 import java.util.HashMap;
    76import java.util.HashSet;
    8 import java.util.Map;
    97import java.util.Set;
    10 import static org.openstreetmap.josm.tools.I18n.tr;
    118
    129public class BackreferencedDataSet {
     
    8784    }
    8885
    89     private DataSet source;
    90     private Map<OsmPrimitive, Set<OsmPrimitive>> referers;
    91     private boolean built = false;
    92 
    93 
    9486    /**
    9587     * Creates a new backreference data set based on the dataset <code>source</code>.
    9688     *
    97      * Doesn't create the cache of backreferences yet. Invoke {@see #build()} on the
    98      * created {@see BackreferencedDataSet}.
    99      *
    100      * @param source the source. Must not be null.
    101      * @throws IllegalArgumentException thrown if source is null
     89     * @param source the source. Ignored
    10290     */
    10391    public BackreferencedDataSet(DataSet source) {
    104         if (source == null)
    105             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null."));
    106         this.source = source;
    107         int size = source.getWays().size() + source.getRelations().size();
    108         referers = new HashMap<OsmPrimitive, Set<OsmPrimitive>>(size, 0.75f);
     92
    10993    }
    11094
    11195    /**
    112      * Remembers a reference from a parent primitive to a child primitive
    113      *
    114      * @param parent the parent primitive
    115      * @param child the child primitive
     96     * @deprecated It's not necessary to call this method, OsmPrimitive.getReferres() is used to get list of referrers
    11697     */
    117     protected void remember(OsmPrimitive parent, OsmPrimitive child) {
    118         Set<OsmPrimitive> parents = referers.get(child);
    119         if (parents != null) {
    120             parents.add(parent);
    121             return;
    122         }
    123         parents = new HashSet<OsmPrimitive>();
    124         parents.add(parent);
    125         referers.put(child, parents);
    126     }
     98    @Deprecated
     99    public void build() {
    127100
    128     /**
    129      * Builds the dataset of back references
    130      *
    131      */
    132     public void build() {
    133         for (Way w : source.getWays()) {
    134             for (Node n : w.getNodes()) {
    135                 remember(w, n);
    136             }
    137         }
    138         for (Relation r : source.getRelations()) {
    139             for (RelationMember m : r.getMembers()) {
    140                 remember(r, m.getMember());
    141             }
    142         }
    143         built = true;
    144101    }
    145102
     
    152109     */
    153110    public Set<OsmPrimitive> getParents(OsmPrimitive child) {
    154         Set<OsmPrimitive> parents = referers.get(child);
    155         return parents == null ? new HashSet<OsmPrimitive>() : parents;
     111        return new HashSet<OsmPrimitive>(child.getReferrers());
    156112    }
    157113
     
    159115        if (children == null) return Collections.emptySet();
    160116        children.remove(null);
     117
    161118        Set<OsmPrimitive> parents = new HashSet<OsmPrimitive>();
    162119        for(OsmPrimitive child: children) {
    163             if (referers.get(child) != null) {
    164                 parents.addAll(referers.get(child));
    165             }
     120            parents.addAll(child.getReferrers());
    166121        }
    167122        return parents;
     
    177132    public boolean hasParents(OsmPrimitive child) {
    178133        return ! getParents(child).isEmpty();
    179     }
    180 
    181     /**
    182      * Replies the source dataset for this Backreference DataSet
    183      *
    184      * @return the source dataset
    185      */
    186     public DataSet getSource() {
    187         return source;
    188134    }
    189135
     
    221167        return references;
    222168    }
    223 
    224     public boolean isBuilt() {
    225         return built;
    226     }
    227169}
Note: See TracChangeset for help on using the changeset viewer.