Browse Source

Fix the inefficient use of keySet iterator with entrySet iterator.

The current source code accesses the key and value of a Hashtable entry, using a key that is retrieved from a keySet iterator.
It is more efficient to use an iterator on the entrySet of the Hashtable, to avoid the Map.get(key) lookup.
http://findbugs.sourceforge.net/bugDescriptions.html#WMI_WRONG_MAP_ITERATOR
master
Kui LIU Stefan Bodewig 7 years ago
parent
commit
3e101e28a9
1 changed files with 9 additions and 6 deletions
  1. +9
    -6
      src/main/org/apache/tools/ant/taskdefs/Move.java

+ 9
- 6
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -105,8 +105,9 @@ public class Move extends Copy {
protected void doFileOperations() {
//Attempt complete directory renames, if any, first.
if (completeDirMap.size() > 0) {
for (File fromDir : completeDirMap.keySet()) {
File toDir = completeDirMap.get(fromDir);
for (Map.Entry<File, File> entry : completeDirMap.entrySet()) {
File fromDir = entry.getKey();
File toDir = entry.getValue();
boolean renamed = false;
try {
log("Attempting to rename dir: " + fromDir + " to " + toDir, verbosity);
@@ -133,11 +134,12 @@ public class Move extends Copy {
log("Moving " + moveCount + " file" + ((moveCount == 1) ? "" : "s")
+ " to " + destDir.getAbsolutePath());

for (String fromFile : fileCopyMap.keySet()) {
for (Map.Entry<String, String[]> entry : fileCopyMap.entrySet) {
String fromFile = entry.getKey();
File f = new File(fromFile);
boolean selfMove = false;
if (f.exists()) { //Is this file still available to be moved?
String[] toFiles = fileCopyMap.get(fromFile);
String[] toFiles = entry.getValue();
for (int i = 0; i < toFiles.length; i++) {
String toFile = toFiles[i];

@@ -164,8 +166,9 @@ public class Move extends Copy {

if (includeEmpty) {
int createCount = 0;
for (String fromDirName : dirCopyMap.keySet()) {
String[] toDirNames = dirCopyMap.get(fromDirName);
for (Map<String, String[]> entry : dirCopyMap.entrySet()) {
String fromDirName = entry.getKey();
String[] toDirNames = entry.getValue();;
boolean selfMove = false;
for (int i = 0; i < toDirNames.length; i++) {
if (fromDirName.equals(toDirNames[i])) {


Loading…
Cancel
Save