Changeset 3654 in josm for trunk/src


Ignore:
Timestamp:
2010-11-14T18:09:06+01:00 (13 years ago)
Author:
bastiK
Message:

applied #5631 (patch by bilbo) - Faster selection with many objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r3469 r3654  
    676676         */
    677677        public void sort() {
    678             Collections.sort(this.selection, new OsmPrimitiveComparator());
     678            if (this.selection.size()>Main.pref.getInteger("selection.no_sort_above",100000)) return;
     679            if (this.selection.size()>Main.pref.getInteger("selection.fast_sort_above",10000)) {
     680                Collections.sort(this.selection, new OsmPrimitiveQuickComparator());
     681            } else {
     682                Collections.sort(this.selection, new OsmPrimitiveComparator());
     683            }
    679684        }
    680685
     
    911916    }
    912917
     918    /** Comparator, comparing by type and objects display names */
    913919    static private class OsmPrimitiveComparator implements Comparator<OsmPrimitive> {
    914920        final private HashMap<OsmPrimitive, String> cache= new HashMap<OsmPrimitive, String>();
     
    940946        private int compareType(OsmPrimitive a, OsmPrimitive b) {
    941947            // show ways before relations, then nodes
    942             //
    943             if (a.getType().equals(b.getType())) return 0;
    944948            if (a.getType().equals(OsmPrimitiveType.WAY)) return -1;
    945949            if (a.getType().equals(OsmPrimitiveType.NODE)) return 1;
     
    949953            return -1;
    950954        }
     955
    951956        public int compare(OsmPrimitive a, OsmPrimitive b) {
    952957            if (a.getType().equals(b.getType()))
     
    955960        }
    956961    }
     962
     963    /** Quicker comparator, comparing just by type and ID's */
     964    static private class OsmPrimitiveQuickComparator implements Comparator<OsmPrimitive> {
     965
     966        private int compareId(OsmPrimitive a, OsmPrimitive b) {
     967            long id_a=a.getUniqueId();
     968            long id_b=b.getUniqueId();
     969            if (id_a<id_b) return -1;
     970            if (id_a>id_b) return 1;
     971            return 0;
     972        }
     973
     974        private int compareType(OsmPrimitive a, OsmPrimitive b) {
     975            // show ways before relations, then nodes
     976            if (a.getType().equals(OsmPrimitiveType.WAY)) return -1;
     977            if (a.getType().equals(OsmPrimitiveType.NODE)) return 1;
     978            // a is a relation
     979            if (b.getType().equals(OsmPrimitiveType.WAY)) return 1;
     980            // b is a node
     981            return -1;
     982        }
     983
     984        public int compare(OsmPrimitive a, OsmPrimitive b) {
     985            if (a.getType().equals(b.getType()))
     986                return compareId(a, b);
     987            return compareType(a, b);
     988        }
     989    }
     990
    957991}
Note: See TracChangeset for help on using the changeset viewer.