Changeset 12069 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSelectionListener.java
r12058 r12069 4 4 import java.util.Collections; 5 5 import java.util.HashSet; 6 import java.util.LinkedHashSet; 6 7 import java.util.Set; 7 8 import java.util.stream.Collectors; … … 39 40 40 41 /** 41 * Gets the new selection 42 * Gets the new selection. New elements are added to the end of the collection. 42 43 * <p> 43 44 * This collection cannot be modified and will not change. … … 175 176 this.current = this.getOldSelection(); 176 177 } else { 177 this.current = new HashSet<>(old);178 this.current = new LinkedHashSet<>(old); 178 179 this.current.addAll(add); 179 180 } … … 217 218 this.current = this.getOldSelection(); 218 219 } else { 219 HashSet<OsmPrimitive> currentSet = new HashSet<>(old);220 HashSet<OsmPrimitive> currentSet = new LinkedHashSet<>(old); 220 221 currentSet.removeAll(remove); 221 222 current = Collections.unmodifiableSet(currentSet); … … 257 258 public SelectionToggleEvent(DataSet source, Set<OsmPrimitive> old, Stream<OsmPrimitive> toToggle) { 258 259 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<>(); 262 263 toToggle.forEach(p -> { 263 264 if (currentSet.remove(p)) { -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r12065 r12069 177 177 /** 178 178 * 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. 179 181 */ 180 182 private Set<OsmPrimitive> currentSelectedPrimitives = Collections.emptySet(); … … 705 707 * in this dataset, except deleted ones. May be empty, but not null. 706 708 * 709 * When iterating through the set it is ordered by the order in which the primitives were added to the selection. 710 * 707 711 * @return unmodifiable collection of primitives 708 712 */ … … 714 718 * Replies an unmodifiable collection of primitives currently selected 715 719 * 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. 716 722 * 717 723 * @return unmodifiable collection of primitives -
trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java
r12036 r12069 5 5 import static org.junit.Assert.assertTrue; 6 6 7 import java.util.ArrayList; 7 8 import java.util.Arrays; 8 9 import java.util.HashSet; … … 124 125 ds.unlinkNodeFromWays(n2); 125 126 } 127 128 /** 129 * Test the selection order. 130 * See <a href="https://josm.openstreetmap.de/ticket/14737">#14737</a> 131 * @since 12069 132 */ 133 @Test 134 public void testSelectionOrderPreserved() { 135 final DataSet ds = new DataSet(); 136 Node n1 = new Node(1); 137 Node n2 = new Node(2); 138 Node n3 = new Node(3); 139 ds.addPrimitive(n1); 140 ds.addPrimitive(n2); 141 ds.addPrimitive(n3); 142 143 assertEquals(Arrays.asList(), new ArrayList<>(ds.getSelected())); 144 145 ds.setSelected(n1.getPrimitiveId(), n2.getPrimitiveId()); 146 assertEquals(Arrays.asList(n1, n2), new ArrayList<>(ds.getSelected())); 147 148 ds.clearSelection(); 149 assertEquals(Arrays.asList(), new ArrayList<>(ds.getSelected())); 150 151 ds.addSelected(n3.getPrimitiveId()); 152 ds.addSelected(n1.getPrimitiveId(), n2.getPrimitiveId()); 153 assertEquals(Arrays.asList(n3, n1, n2), new ArrayList<>(ds.getSelected())); 154 155 ds.addSelected(n3.getPrimitiveId()); 156 assertEquals(Arrays.asList(n3, n1, n2), new ArrayList<>(ds.getSelected())); 157 158 ds.clearSelection(n1.getPrimitiveId()); 159 assertEquals(Arrays.asList(n3, n2), new ArrayList<>(ds.getSelected())); 160 161 ds.toggleSelected(n1.getPrimitiveId()); 162 assertEquals(Arrays.asList(n3, n2, n1), new ArrayList<>(ds.getSelected())); 163 164 ds.toggleSelected(n2.getPrimitiveId()); 165 assertEquals(Arrays.asList(n3, n1), new ArrayList<>(ds.getSelected())); 166 167 } 126 168 }
Note:
See TracChangeset
for help on using the changeset viewer.