Ticket #8517: sortValidatorDialog.patch

File sortValidatorDialog.patch, 10.3 KB (added by windu.2b, 10 years ago)

sort validator dialog

  • src/org/openstreetmap/josm/data/osm/WaySegment.java

     
    44/**
    55 * A segment consisting of 2 consecutive nodes out of a way.
    66 */
    7 public final class WaySegment {
     7public final class WaySegment implements Comparable<WaySegment> {
    88    /**
    99     * The way.
    1010     */
     
    4949    @Override public int hashCode() {
    5050        return way.hashCode() ^ lowerIndex;
    5151    }
     52
     53    @Override
     54    public int compareTo(WaySegment o) {
     55        return this.toWay().compareTo(o.toWay());
     56    }
    5257}
  • src/org/openstreetmap/josm/data/validation/TestError.java

     
    1313import org.openstreetmap.josm.data.osm.Relation;
    1414import org.openstreetmap.josm.data.osm.Way;
    1515import org.openstreetmap.josm.data.osm.WaySegment;
     16import org.openstreetmap.josm.data.validation.util.MultipleNameVisitor;
    1617
    1718/**
    1819 * Validation error
    1920 * @author frsantos
    2021 */
    21 public class TestError {
     22public class TestError implements Comparable<TestError> {
    2223    /** is this error on the ignore list */
    2324    private Boolean ignored = false;
    2425    /** Severity */
     
    276277    public Collection<?> getHighlighted() {
    277278        return highlighted;
    278279    }
     280
     281    @Override
     282    public int compareTo(TestError o) {
     283        MultipleNameVisitor v1 = new MultipleNameVisitor();
     284        MultipleNameVisitor v2 = new MultipleNameVisitor();
     285
     286        v1.visit(getPrimitives());
     287        v2.visit(o.getPrimitives());
     288        return v1.toString().compareToIgnoreCase(v2.toString());
     289    }
     290
    279291}
  • src/org/openstreetmap/josm/data/validation/tests/DuplicateRelation.java

     
    66import java.util.ArrayList;
    77import java.util.Collection;
    88import java.util.HashSet;
    9 import java.util.LinkedHashSet;
    109import java.util.LinkedList;
    1110import java.util.List;
    1211import java.util.Map;
     12import java.util.TreeSet;
    1313
    1414import org.openstreetmap.josm.command.ChangeCommand;
    1515import org.openstreetmap.josm.command.Command;
     
    191191    @Override
    192192    public void endTest() {
    193193        super.endTest();
    194         for(LinkedHashSet<OsmPrimitive> duplicated : relations.values()) {
     194        for(TreeSet<OsmPrimitive> duplicated : relations.values()) {
    195195            if (duplicated.size() > 1) {
    196196                TestError testError = new TestError(this, Severity.ERROR, tr("Duplicated relations"), DUPLICATE_RELATION, duplicated);
    197197                errors.add( testError );
    198198            }
    199199        }
    200200        relations = null;
    201         for(LinkedHashSet<OsmPrimitive> duplicated : relations_nokeys.values()) {
     201        for(TreeSet<OsmPrimitive> duplicated : relations_nokeys.values()) {
    202202            if (duplicated.size() > 1) {
    203203                TestError testError = new TestError(this, Severity.WARNING, tr("Relations with same members"), SAME_RELATION, duplicated);
    204204                errors.add( testError );
     
    213213            return;
    214214        List<RelationMember> rMembers = r.getMembers();
    215215        Map<String, String> rkeys = r.getKeys();
    216         for (String key : ignoreKeys)
     216        for (String key : ignoreKeys) {
    217217            rkeys.remove(key);
     218        }
    218219        RelationPair rKey = new RelationPair(rMembers, rkeys);
    219220        relations.put(rKey, r);
    220221        relations_nokeys.put(rMembers, r);
     
    289290    @Override
    290291    public boolean isFixable(TestError testError) {
    291292        if (!(testError.getTester() instanceof DuplicateRelation)
    292             || testError.getCode() == SAME_RELATION) return false;
     293                || testError.getCode() == SAME_RELATION) return false;
    293294
    294295        // We fix it only if there is no more than one relation that is relation member.
    295296        Collection<? extends OsmPrimitive> sel = testError.getPrimitives();
  • src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java

     
    66import java.util.ArrayList;
    77import java.util.Collection;
    88import java.util.HashMap;
    9 import java.util.LinkedHashSet;
    109import java.util.List;
    1110import java.util.Map;
     11import java.util.TreeSet;
    1212
    1313import org.openstreetmap.josm.data.osm.Node;
    1414import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5555
    5656    @Override
    5757    public void endTest() {
    58         Map<List<Way>, LinkedHashSet<WaySegment>> ways_seen = new HashMap<List<Way>, LinkedHashSet<WaySegment>>(500);
     58        Map<List<Way>, TreeSet<WaySegment>> ways_seen = new HashMap<List<Way>, TreeSet<WaySegment>>(500);
    5959
    60         for (LinkedHashSet<WaySegment> duplicated : nodePairs.values()) {
     60        for (TreeSet<WaySegment> duplicated : nodePairs.values()) {
    6161            int ways = duplicated.size();
    6262
    6363            if (ways > 1) {
  • src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

     
    88import java.util.Enumeration;
    99import java.util.HashMap;
    1010import java.util.HashSet;
    11 import java.util.LinkedHashSet;
    1211import java.util.List;
    1312import java.util.Map;
    1413import java.util.Map.Entry;
    1514import java.util.Set;
     15import java.util.TreeSet;
    1616
    1717import javax.swing.JTree;
    1818import javax.swing.ToolTipManager;
     
    205206                expandedPaths.add(new TreePath(new Object[] { rootNode, severityNode }));
    206207            }
    207208
    208             for (Entry<String, LinkedHashSet<TestError>> msgErrors : severityErrors.entrySet()) {
     209            for (Entry<String, TreeSet<TestError>> msgErrors : severityErrors.entrySet()) {
    209210                // Message node
    210211                Set<TestError> errs = msgErrors.getValue();
    211212                String msg = msgErrors.getKey() + " (" + errs.size() + ")";
     
    235236                    }
    236237                }
    237238
    238                 for (Entry<String, LinkedHashSet<TestError>> msgErrors : errorlist.entrySet()) {
     239                for (Entry<String, TreeSet<TestError>> msgErrors : errorlist.entrySet()) {
    239240                    // Message node
    240241                    Set<TestError> errs = msgErrors.getValue();
    241242                    String msg;
  • src/org/openstreetmap/josm/tools/MultiMap.java

     
    44import java.util.ArrayList;
    55import java.util.Collection;
    66import java.util.HashMap;
    7 import java.util.LinkedHashSet;
    87import java.util.List;
    98import java.util.Map;
    109import java.util.Map.Entry;
    1110import java.util.Set;
     11import java.util.TreeSet;
    1212
    1313/**
    1414 * MultiMap - maps keys to multiple values
     
    1919 */
    2020public class MultiMap<A, B> {
    2121
    22     private final Map<A, LinkedHashSet<B>> map;
     22    private final Map<A, TreeSet<B>> map;
    2323
    2424    public MultiMap() {
    25         map = new HashMap<A, LinkedHashSet<B>>();
     25        map = new HashMap<A, TreeSet<B>>();
    2626    }
    2727
    2828    public MultiMap(int capacity) {
    29         map = new HashMap<A, LinkedHashSet<B>>(capacity);
     29        map = new HashMap<A, TreeSet<B>>(capacity);
    3030    }
    3131
    3232    /**
     
    3535     * Can be called multiple times with the same key, but different value.
    3636     */
    3737    public void put(A key, B value) {
    38         LinkedHashSet<B> vals = map.get(key);
     38        TreeSet<B> vals = map.get(key);
    3939        if (vals == null) {
    40             vals = new LinkedHashSet<B>();
     40            vals = new TreeSet<B>();
    4141            map.put(key, vals);
    4242        }
    4343        vals.add(value);
     
    5252    public void putVoid(A key) {
    5353        if (map.containsKey(key))
    5454            return;
    55         map.put(key, new LinkedHashSet<B>());
     55        map.put(key, new TreeSet<B>());
    5656    }
    5757
    5858    /**
     
    6161     * Adds to the mappings that are already there.
    6262     */
    6363    public void putAll(A key, Collection<B> values) {
    64         LinkedHashSet<B> vals = map.get(key);
     64        TreeSet<B> vals = map.get(key);
    6565        if (vals == null) {
    66             vals = new LinkedHashSet<B>(values);
     66            vals = new TreeSet<B>(values);
    6767            map.put(key, vals);
    6868        }
    6969        vals.addAll(values);
     
    9090    /**
    9191     * Like get, but returns an empty Set if nothing has been mapped to the key.
    9292     */
    93     public LinkedHashSet<B> getValues(A key) {
     93    public TreeSet<B> getValues(A key) {
    9494        if (!map.containsKey(key))
    95             return new LinkedHashSet<B>();
     95            return new TreeSet<B>();
    9696        return map.get(key);
    9797    }
    9898
     
    120120        map.clear();
    121121    }
    122122
    123     public Set<Entry<A, LinkedHashSet<B>>> entrySet() {
     123    public Set<Entry<A, TreeSet<B>>> entrySet() {
    124124        return map.entrySet();
    125125    }
    126126
     
    134134    /**
    135135     * Returns a collection of all value sets.
    136136     */
    137     public Collection<LinkedHashSet<B>> values() {
     137    public Collection<TreeSet<B>> values() {
    138138        return map.values();
    139139    }
    140140
     
    145145     */
    146146    public boolean remove(A key, B value) {
    147147        Set<B> values = get(key);
    148         if (values != null) {
     148        if (values != null)
    149149            return values.remove(value);
    150         }
    151150        return false;
    152151    }
    153152
    154153    /**
    155154     * Removes all mappings for a certain key.
    156155     */
    157     public LinkedHashSet<B> remove(A key) {
     156    public TreeSet<B> remove(A key) {
    158157        return map.remove(key);
    159158    }
    160159
     160    @Override
    161161    public String toString() {
    162162        List<String> entries = new ArrayList<String>(map.size());
    163163        for (A key : map.keySet()) {