Changeset 2220 in josm for trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
- Timestamp:
- 2009-09-30T20:00:57+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r2070 r2220 38 38 39 39 static private List<Class<? extends OsmPrimitive>> osmPrimitiveClasses; 40 {40 static { 41 41 osmPrimitiveClasses = new ArrayList<Class<? extends OsmPrimitive>>(); 42 42 osmPrimitiveClasses.add(Node.class); … … 60 60 61 61 /** 62 * Replies the subset of {@see OsmPrimitive}s of <code>type</code> from <code>superSet</code>.63 *64 * @param <T>65 * @param superSet the super set of primitives66 * @param type the type67 * @return68 */69 protected <T extends OsmPrimitive> Collection<? extends OsmPrimitive> getSubcollectionByType(Collection<? extends OsmPrimitive> superSet, Class<T> type) {70 Collection<OsmPrimitive> ret = new ArrayList<OsmPrimitive>();71 for (OsmPrimitive p : superSet) {72 if (type.isInstance(p)) {73 ret.add(p);74 }75 }76 return ret;77 }78 79 /**80 62 * Replies all primitives of type <code>type</code> in the current selection. 81 63 * … … 85 67 */ 86 68 protected <T extends OsmPrimitive> Collection<? extends OsmPrimitive> getSourcePrimitivesByType(Class<T> type) { 87 return getSubcollectionByType(Main.pasteBuffer.getSelected(), type);69 return OsmPrimitive.getFilteredList(Main.pasteBuffer.getSelected(), type); 88 70 } 89 71 … … 145 127 HashMap<OsmPrimitiveType, Integer> ret = new HashMap<OsmPrimitiveType, Integer>(); 146 128 for (Class<? extends OsmPrimitive> type: osmPrimitiveClasses) { 147 int count = getSubcollectionByType(getEditLayer().data.getSelected(), type).size();129 int count = OsmPrimitive.getFilteredList(getEditLayer().data.getSelected(), type).size(); 148 130 if (count > 0) { 149 131 ret.put(OsmPrimitiveType.from(type), count); … … 173 155 // no tags found to paste. Abort. 174 156 return; 175 176 157 177 158 if (!tc.isApplicableToPrimitive()) { … … 202 183 * <code>selection</code> 203 184 */ 204 protected <T extends OsmPrimitive> boolean hasTargetPrimitives(Collection< ? extendsOsmPrimitive> selection, Class<T> type) {205 return ! getSubcollectionByType(selection, type).isEmpty();185 protected <T extends OsmPrimitive> boolean hasTargetPrimitives(Collection<OsmPrimitive> selection, Class<T> type) { 186 return !OsmPrimitive.getFilteredList(selection, type).isEmpty(); 206 187 } 207 188 … … 212 193 * @return true if this a heterogeneous source can be pasted without conflicts to targets 213 194 */ 214 protected boolean canPasteFromHeterogeneousSourceWithoutConflict(Collection< ? extendsOsmPrimitive> targets) {195 protected boolean canPasteFromHeterogeneousSourceWithoutConflict(Collection<OsmPrimitive> targets) { 215 196 if (hasTargetPrimitives(targets, Node.class)) { 216 197 TagCollection tc = TagCollection.unionOfAllPrimitives(getSourcePrimitivesByType(Node.class)); … … 237 218 * @param targets the collection of target primitives 238 219 */ 239 protected void pasteFromHeterogeneousSource(Collection< ? extendsOsmPrimitive> targets) {220 protected void pasteFromHeterogeneousSource(Collection<OsmPrimitive> targets) { 240 221 if (canPasteFromHeterogeneousSourceWithoutConflict(targets)) { 241 222 if (hasSourceTagsByType(Node.class) && hasTargetPrimitives(targets, Node.class)) { … … 264 245 return; 265 246 if (hasSourceTagsByType(Node.class) && hasTargetPrimitives(targets, Node.class)) { 266 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Node.class), dialog.getResolution(OsmPrimitiveType.NODE));247 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Node.class), dialog.getResolution(OsmPrimitiveType.NODE)); 267 248 Main.main.undoRedo.add(cmd); 268 249 } 269 250 if (hasSourceTagsByType(Way.class) && hasTargetPrimitives(targets, Way.class)) { 270 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Way.class), dialog.getResolution(OsmPrimitiveType.WAY));251 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Way.class), dialog.getResolution(OsmPrimitiveType.WAY)); 271 252 Main.main.undoRedo.add(cmd); 272 253 } 273 254 if (hasSourceTagsByType(Relation.class) && hasTargetPrimitives(targets, Relation.class)) { 274 Command cmd = buildChangeCommand( getSubcollectionByType(targets, Relation.class), dialog.getResolution(OsmPrimitiveType.RELATION));255 Command cmd = buildChangeCommand(OsmPrimitive.getFilteredList(targets, Relation.class), dialog.getResolution(OsmPrimitiveType.RELATION)); 275 256 Main.main.undoRedo.add(cmd); 276 257 }
Note:
See TracChangeset
for help on using the changeset viewer.