Changeset 12069 in josm for trunk/src/org


Ignore:
Timestamp:
2017-05-06T14:10:40+02:00 (8 years ago)
Author:
michael2402
Message:

Fix #14737: Preserve selection order and add comments that it is ordered. Add unit tests.

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSelectionListener.java

    r12058 r12069  
    44import java.util.Collections;
    55import java.util.HashSet;
     6import java.util.LinkedHashSet;
    67import java.util.Set;
    78import java.util.stream.Collectors;
     
    3940
    4041        /**
    41          * Gets the new selection
     42         * Gets the new selection. New elements are added to the end of the collection.
    4243         * <p>
    4344         * This collection cannot be modified and will not change.
     
    175176                this.current = this.getOldSelection();
    176177            } else {
    177                 this.current = new HashSet<>(old);
     178                this.current = new LinkedHashSet<>(old);
    178179                this.current.addAll(add);
    179180            }
     
    217218                this.current = this.getOldSelection();
    218219            } else {
    219                 HashSet<OsmPrimitive> currentSet = new HashSet<>(old);
     220                HashSet<OsmPrimitive> currentSet = new LinkedHashSet<>(old);
    220221                currentSet.removeAll(remove);
    221222                current = Collections.unmodifiableSet(currentSet);
     
    257258        public SelectionToggleEvent(DataSet source, Set<OsmPrimitive> old, Stream<OsmPrimitive> toToggle) {
    258259            super(source, old);
    259             HashSet<OsmPrimitive> currentSet = new HashSet<>(old);
    260             HashSet<OsmPrimitive> removeSet = new HashSet<>();
    261             HashSet<OsmPrimitive> addSet = new HashSet<>();
     260            HashSet<OsmPrimitive> currentSet = new LinkedHashSet<>(old);
     261            HashSet<OsmPrimitive> removeSet = new LinkedHashSet<>();
     262            HashSet<OsmPrimitive> addSet = new LinkedHashSet<>();
    262263            toToggle.forEach(p -> {
    263264                if (currentSet.remove(p)) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12065 r12069  
    177177    /**
    178178     * The current selected primitives. This is always a unmodifiable set.
     179     *
     180     * The set should be ordered in the order in which the primitives have been added to the selection.
    179181     */
    180182    private Set<OsmPrimitive> currentSelectedPrimitives = Collections.emptySet();
     
    705707     * in this dataset, except deleted ones. May be empty, but not null.
    706708     *
     709     * When iterating through the set it is ordered by the order in which the primitives were added to the selection.
     710     *
    707711     * @return unmodifiable collection of primitives
    708712     */
     
    714718     * Replies an unmodifiable collection of primitives currently selected
    715719     * in this dataset, including deleted ones. May be empty, but not null.
     720     *
     721     * When iterating through the set it is ordered by the order in which the primitives were added to the selection.
    716722     *
    717723     * @return unmodifiable collection of primitives
Note: See TracChangeset for help on using the changeset viewer.