- Timestamp:
- 2012-11-28T23:47:46+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/upload/DiscardTagsHook.java
r5497 r5608 21 21 public class DiscardTagsHook implements UploadHook { 22 22 23 @Override 23 24 public boolean checkUpload(APIDataSet apiDataSet) { 24 25 List<OsmPrimitive> objectsToUpload = apiDataSet.getPrimitives(); -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r5589 r5608 128 128 * If <code>list</code> is null, replies an empty set. 129 129 * 130 * @param <T> 131 * @param list the original collection130 * @param <T> type of data (must be one of the {@link OsmPrimitive} types 131 * @param set the original collection 132 132 * @param type the type to filter for 133 133 * @return the sub-set of OSM primitives of type <code>type</code> … … 621 621 public static Collection<String> getUninterestingKeys() { 622 622 if (uninteresting == null) { 623 uninteresting = Main.pref.getCollection("tags.uninteresting", 624 Arrays.asList("source", "source_ref", "source:", "note", "comment", 625 "converted_by", "created_by", "watch", "watch:", "fixme", "FIXME", 626 "description", "attribution")); 623 LinkedList<String> l = new LinkedList<String>(Arrays.asList( 624 "source", "source_ref", "source:", "note", "comment", 625 "converted_by", "watch", "watch:", "fixme", "FIXME", 626 "description", "attribution")); 627 l.addAll(getDiscardableKeys()); 628 uninteresting = Main.pref.getCollection("tags.uninteresting", l); 627 629 } 628 630 return uninteresting; … … 967 969 /*----------------- 968 970 * OTHER METHODS 969 *---------------- /971 *----------------*/ 970 972 971 973 /** … … 1075 1077 /** 1076 1078 * Loads (clone) this primitive from provided PrimitiveData 1077 * @param data 1079 * @param data The object which should be cloned 1078 1080 */ 1079 1081 public void load(PrimitiveData data) { … … 1091 1093 /** 1092 1094 * Save parameters of this primitive to the transport object 1093 * @return 1095 * @return The saved object data 1094 1096 */ 1095 1097 public abstract PrimitiveData save(); 1096 1098 1099 /** 1100 * Save common parameters of primitives to the transport object 1101 * @param data The object to save the data into 1102 */ 1097 1103 protected void saveCommonAttributes(PrimitiveData data) { 1098 1104 data.setId(id); … … 1108 1114 } 1109 1115 1116 /** 1117 * Fetch the bounding box of the primitive 1118 * @return Bounding box of the object 1119 */ 1110 1120 public abstract BBox getBBox(); 1111 1121 -
trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java
r4874 r5608 28 28 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 29 29 import org.openstreetmap.josm.tools.MultiMap; 30 30 31 /** 31 32 * Tests if there are duplicate relations 32 33 */ 33 public class DuplicateRelation extends Test 34 { 35 34 public class DuplicateRelation extends Test { 35 36 /** 37 * Class to store one relation members and information about it 38 */ 36 39 public static class RelMember { 40 /** Role of the relation member */ 37 41 private String role; 42 43 /** Type of the relation member */ 38 44 private OsmPrimitiveType type; 45 46 /** Tags of the relation member */ 39 47 private Map<String, String> tags; 48 49 /** Coordinates of the relation member */ 40 50 private List<LatLon> coor; 51 52 /** ID of the relation member in case it is a {@link Relation} */ 41 53 private long rel_id; 42 54 … … 53 65 } 54 66 67 /** Extract and store relation information based on the relation member 68 * @param src The relation member to store information about 69 */ 55 70 public RelMember(RelationMember src) { 56 role =src.getRole();57 type =src.getType();58 rel_id =0;59 coor =new ArrayList<LatLon>();71 role = src.getRole(); 72 type = src.getType(); 73 rel_id = 0; 74 coor = new ArrayList<LatLon>(); 60 75 61 76 if (src.isNode()) { 62 Node r =src.getNode();63 tags =r.getKeys();64 coor =new ArrayList<LatLon>(1);77 Node r = src.getNode(); 78 tags = r.getKeys(); 79 coor = new ArrayList<LatLon>(1); 65 80 coor.add(r.getCoor()); 66 81 } 67 82 if (src.isWay()) { 68 Way r =src.getWay();69 tags =r.getKeys();83 Way r = src.getWay(); 84 tags = r.getKeys(); 70 85 List<Node> wNodes = r.getNodes(); 71 coor =new ArrayList<LatLon>(wNodes.size());72 for (int i =0;i<wNodes.size();i++) {86 coor = new ArrayList<LatLon>(wNodes.size()); 87 for (int i = 0; i < wNodes.size(); i++) { 73 88 coor.add(wNodes.get(i).getCoor()); 74 89 } 75 90 } 76 91 if (src.isRelation()) { 77 Relation r=src.getRelation(); 78 tags=r.getKeys(); 79 rel_id=r.getId(); 80 coor=new ArrayList<LatLon>(); 81 } 82 } 83 } 84 92 Relation r = src.getRelation(); 93 tags = r.getKeys(); 94 rel_id = r.getId(); 95 coor = new ArrayList<LatLon>(); 96 } 97 } 98 } 99 100 /** 101 * Class to store relation members 102 */ 85 103 private class RelationMembers { 104 /** List of member objects of the relation */ 86 105 public List<RelMember> members; 87 public RelationMembers(List<RelationMember> _members) { 88 members=new ArrayList<RelMember>(_members.size()); 89 for (int i=0;i<_members.size();i++) { 90 members.add(new RelMember(_members.get(i))); 91 } 92 } 106 107 /** Store relation information 108 * @param members The list of relation members 109 */ 110 public RelationMembers(List<RelationMember> members) { 111 this.members = new ArrayList<RelMember>(members.size()); 112 for (int i = 0; i < members.size(); i++) { 113 this.members.add(new RelMember(members.get(i))); 114 } 115 } 116 93 117 @Override 94 118 public int hashCode() { 95 119 return members.hashCode(); 96 120 } 121 97 122 @Override 98 123 public boolean equals(Object obj) { … … 103 128 } 104 129 130 /** 131 * Class to store relation data (keys are usually cleanup and may not be equal to original relation) 132 */ 105 133 private class RelationPair { 134 /** Member objects of the relation */ 106 135 public RelationMembers members; 136 /** Tags of the relation */ 107 137 public Map<String, String> keys; 108 public RelationPair(List<RelationMember> _members,Map<String, String> _keys) { 109 members=new RelationMembers(_members); 110 keys=_keys; 111 } 138 139 /** Store relation information 140 * @param members The list of relation members 141 * @param keys The set of tags of the relation 142 */ 143 public RelationPair(List<RelationMember> members, Map<String, String> keys) { 144 this.members = new RelationMembers(members); 145 this.keys = keys; 146 } 147 112 148 @Override 113 149 public int hashCode() { 114 150 return members.hashCode()+keys.hashCode(); 115 151 } 152 116 153 @Override 117 154 public boolean equals(Object obj) { … … 122 159 } 123 160 161 /** Code number of completely duplicated relation error */ 124 162 protected static final int DUPLICATE_RELATION = 1901; 163 164 /** Code number of relation with same members error */ 125 165 protected static final int SAME_RELATION = 1902; 126 166 … … 131 171 MultiMap<List<RelationMember>, OsmPrimitive> relations_nokeys; 132 172 133 /** 134 * Constructor 135 */ 136 public DuplicateRelation() 137 { 173 /** List of keys without useful information */ 174 Collection<String> ignoreKeys = new HashSet<String>(OsmPrimitive.getUninterestingKeys()); 175 176 /** 177 * Default constructor 178 */ 179 public DuplicateRelation() { 138 180 super(tr("Duplicated relations"), 139 181 tr("This test checks that there are no relations with same tags and same members with same roles.")); 140 182 } 141 183 142 143 @Override 144 public void startTest(ProgressMonitor monitor) 145 { 184 @Override 185 public void startTest(ProgressMonitor monitor) { 146 186 super.startTest(monitor); 147 187 relations = new MultiMap<RelationPair, OsmPrimitive>(1000); … … 150 190 151 191 @Override 152 public void endTest() 153 { 192 public void endTest() { 154 193 super.endTest(); 155 for(LinkedHashSet<OsmPrimitive> duplicated : relations.values() ) 156 { 157 if( duplicated.size() > 1) 158 { 194 for(LinkedHashSet<OsmPrimitive> duplicated : relations.values()) { 195 if (duplicated.size() > 1) { 159 196 TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated relations"), DUPLICATE_RELATION, duplicated); 160 197 errors.add( testError ); … … 162 199 } 163 200 relations = null; 164 for(LinkedHashSet<OsmPrimitive> duplicated : relations_nokeys.values() ) 165 { 166 if( duplicated.size() > 1) 167 { 201 for(LinkedHashSet<OsmPrimitive> duplicated : relations_nokeys.values()) { 202 if (duplicated.size() > 1) { 168 203 TestError testError = new TestError(this, Severity.WARNING, tr("Relations with same members"), SAME_RELATION, duplicated); 169 204 errors.add( testError ); … … 174 209 175 210 @Override 176 public void visit(Relation r) 177 { 211 public void visit(Relation r) { 178 212 if (!r.isUsable() || r.hasIncompleteMembers()) 179 213 return; 180 List<RelationMember> rMembers=r.getMembers(); 181 Map<String, String> rkeys=r.getKeys(); 182 rkeys.remove("created_by"); 183 RelationPair rKey=new RelationPair(rMembers,rkeys); 214 List<RelationMember> rMembers = r.getMembers(); 215 Map<String, String> rkeys = r.getKeys(); 216 for (String key : ignoreKeys) 217 rkeys.remove(ignoreKeys); 218 RelationPair rKey = new RelationPair(rMembers, rkeys); 184 219 relations.put(rKey, r); 185 220 relations_nokeys.put(rMembers, r); … … 188 223 /** 189 224 * Fix the error by removing all but one instance of duplicate relations 190 * /191 @Override192 public Command fixError(TestError testError)193 {225 * @param testError The error to fix, must be of type {@link #DUPLICATE_RELATION} 226 */ 227 @Override 228 public Command fixError(TestError testError) { 194 229 if (testError.getCode() == SAME_RELATION) return null; 195 230 Collection<? extends OsmPrimitive> sel = testError.getPrimitives(); … … 253 288 254 289 @Override 255 public boolean isFixable(TestError testError) 256 { 257 if (!(testError.getTester() instanceof DuplicateRelation)) 258 return false; 259 260 if (testError.getCode() == SAME_RELATION) return false; 290 public boolean isFixable(TestError testError) { 291 if (!(testError.getTester() instanceof DuplicateRelation) 292 || testError.getCode() == SAME_RELATION) return false; 261 293 262 294 // We fix it only if there is no more than one relation that is relation member.
Note:
See TracChangeset
for help on using the changeset viewer.