- Timestamp:
- 2009-11-08T15:54:40+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/BackreferencedDataSet.java
r2381 r2411 4 4 import java.util.Collection; 5 5 import java.util.Collections; 6 import java.util.HashMap;7 6 import java.util.HashSet; 8 import java.util.Map;9 7 import java.util.Set; 10 import static org.openstreetmap.josm.tools.I18n.tr;11 8 12 9 public class BackreferencedDataSet { … … 87 84 } 88 85 89 private DataSet source;90 private Map<OsmPrimitive, Set<OsmPrimitive>> referers;91 private boolean built = false;92 93 94 86 /** 95 87 * Creates a new backreference data set based on the dataset <code>source</code>. 96 88 * 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 102 90 */ 103 91 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 109 93 } 110 94 111 95 /** 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 116 97 */ 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() { 127 100 128 /**129 * Builds the dataset of back references130 *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;144 101 } 145 102 … … 152 109 */ 153 110 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()); 156 112 } 157 113 … … 159 115 if (children == null) return Collections.emptySet(); 160 116 children.remove(null); 117 161 118 Set<OsmPrimitive> parents = new HashSet<OsmPrimitive>(); 162 119 for(OsmPrimitive child: children) { 163 if (referers.get(child) != null) { 164 parents.addAll(referers.get(child)); 165 } 120 parents.addAll(child.getReferrers()); 166 121 } 167 122 return parents; … … 177 132 public boolean hasParents(OsmPrimitive child) { 178 133 return ! getParents(child).isEmpty(); 179 }180 181 /**182 * Replies the source dataset for this Backreference DataSet183 *184 * @return the source dataset185 */186 public DataSet getSource() {187 return source;188 134 } 189 135 … … 221 167 return references; 222 168 } 223 224 public boolean isBuilt() {225 return built;226 }227 169 }
Note:
See TracChangeset
for help on using the changeset viewer.