Changeset 5608 in josm


Ignore:
Timestamp:
2012-11-28T23:47:46+01:00 (12 years ago)
Author:
stoecker
Message:

don't hardcode created_by for DuplicateRelation validator test, javadoc fixes

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/upload/DiscardTagsHook.java

    r5497 r5608  
    2121public class DiscardTagsHook implements UploadHook {
    2222
     23    @Override
    2324    public boolean checkUpload(APIDataSet apiDataSet) {
    2425        List<OsmPrimitive> objectsToUpload = apiDataSet.getPrimitives();
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r5589 r5608  
    128128     * If <code>list</code> is null, replies an empty set.
    129129     *
    130      * @param <T>
    131      * @param list  the original collection
     130     * @param <T> type of data (must be one of the {@link OsmPrimitive} types
     131     * @param set  the original collection
    132132     * @param type the type to filter for
    133133     * @return the sub-set of OSM primitives of type <code>type</code>
     
    621621    public static Collection<String> getUninterestingKeys() {
    622622        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);
    627629        }
    628630        return uninteresting;
     
    967969    /*-----------------
    968970     * OTHER METHODS
    969      *----------------/
     971     *----------------*/
    970972
    971973    /**
     
    10751077    /**
    10761078     * Loads (clone) this primitive from provided PrimitiveData
    1077      * @param data
     1079     * @param data The object which should be cloned
    10781080     */
    10791081    public void load(PrimitiveData data) {
     
    10911093    /**
    10921094     * Save parameters of this primitive to the transport object
    1093      * @return
     1095     * @return The saved object data
    10941096     */
    10951097    public abstract PrimitiveData save();
    10961098
     1099    /**
     1100     * Save common parameters of primitives to the transport object
     1101     * @param data The object to save the data into
     1102     */
    10971103    protected void saveCommonAttributes(PrimitiveData data) {
    10981104        data.setId(id);
     
    11081114    }
    11091115
     1116    /**
     1117     * Fetch the bounding box of the primitive
     1118     * @return Bounding box of the object
     1119     */
    11101120    public abstract BBox getBBox();
    11111121
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java

    r4874 r5608  
    2828import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2929import org.openstreetmap.josm.tools.MultiMap;
     30
    3031/**
    3132 * Tests if there are duplicate relations
    3233 */
    33 public class DuplicateRelation extends Test
    34 {
    35 
     34public class DuplicateRelation extends Test {
     35
     36    /**
     37     * Class to store one relation members and information about it
     38     */
    3639    public static class RelMember {
     40        /** Role of the relation member */
    3741        private String role;
     42
     43        /** Type of the relation member */
    3844        private OsmPrimitiveType type;
     45
     46        /** Tags of the relation member */
    3947        private Map<String, String> tags;
     48
     49        /** Coordinates of the relation member */
    4050        private List<LatLon> coor;
     51
     52        /** ID of the relation member in case it is a {@link Relation} */
    4153        private long rel_id;
    4254
     
    5365        }
    5466
     67        /** Extract and store relation information based on the relation member
     68         * @param src The relation member to store information about
     69         */
    5570        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>();
    6075
    6176            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);
    6580                coor.add(r.getCoor());
    6681            }
    6782            if (src.isWay()) {
    68                 Way r=src.getWay();
    69                 tags=r.getKeys();
     83                Way r = src.getWay();
     84                tags = r.getKeys();
    7085                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++) {
    7388                    coor.add(wNodes.get(i).getCoor());
    7489                }
    7590            }
    7691            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     */
    85103    private class RelationMembers {
     104        /** List of member objects of the relation */
    86105        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
    93117        @Override
    94118        public int hashCode() {
    95119            return members.hashCode();
    96120        }
     121
    97122        @Override
    98123        public boolean equals(Object obj) {
     
    103128    }
    104129
     130    /**
     131     * Class to store relation data (keys are usually cleanup and may not be equal to original relation)
     132     */
    105133    private class RelationPair {
     134        /** Member objects of the relation */
    106135        public RelationMembers members;
     136        /** Tags of the relation */
    107137        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
    112148        @Override
    113149        public int hashCode() {
    114150            return members.hashCode()+keys.hashCode();
    115151        }
     152
    116153        @Override
    117154        public boolean equals(Object obj) {
     
    122159    }
    123160
     161    /** Code number of completely duplicated relation error */
    124162    protected static final int DUPLICATE_RELATION = 1901;
     163
     164    /** Code number of relation with same members error */
    125165    protected static final int SAME_RELATION = 1902;
    126166
     
    131171    MultiMap<List<RelationMember>, OsmPrimitive> relations_nokeys;
    132172
    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() {
    138180        super(tr("Duplicated relations"),
    139181                tr("This test checks that there are no relations with same tags and same members with same roles."));
    140182    }
    141183
    142 
    143     @Override
    144     public void startTest(ProgressMonitor monitor)
    145     {
     184    @Override
     185    public void startTest(ProgressMonitor monitor) {
    146186        super.startTest(monitor);
    147187        relations = new MultiMap<RelationPair, OsmPrimitive>(1000);
     
    150190
    151191    @Override
    152     public void endTest()
    153     {
     192    public void endTest() {
    154193        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) {
    159196                TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated relations"), DUPLICATE_RELATION, duplicated);
    160197                errors.add( testError );
     
    162199        }
    163200        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) {
    168203                TestError testError = new TestError(this, Severity.WARNING, tr("Relations with same members"), SAME_RELATION, duplicated);
    169204                errors.add( testError );
     
    174209
    175210    @Override
    176     public void visit(Relation r)
    177     {
     211    public void visit(Relation r) {
    178212        if (!r.isUsable() || r.hasIncompleteMembers())
    179213            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);
    184219        relations.put(rKey, r);
    185220        relations_nokeys.put(rMembers, r);
     
    188223    /**
    189224     * Fix the error by removing all but one instance of duplicate relations
    190      */
    191     @Override
    192     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) {
    194229        if (testError.getCode() == SAME_RELATION) return null;
    195230        Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
     
    253288
    254289    @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;
    261293
    262294        // 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.