[Swift-commit] r4796 - trunk/src/org/griphyn/vdl/mapping

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Thu Jul 7 13:25:08 CDT 2011


Author: hategan
Date: 2011-07-07 13:25:08 -0500 (Thu, 07 Jul 2011)
New Revision: 4796

Modified:
   trunk/src/org/griphyn/vdl/mapping/AbsFile.java
Log:
implement hasCode and equals so that the garbage collector can properly check equality

Modified: trunk/src/org/griphyn/vdl/mapping/AbsFile.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbsFile.java	2011-07-07 18:23:43 UTC (rev 4795)
+++ trunk/src/org/griphyn/vdl/mapping/AbsFile.java	2011-07-07 18:25:08 UTC (rev 4796)
@@ -7,8 +7,6 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.globus.cog.abstraction.impl.common.task.ServiceContactImpl;
@@ -116,17 +114,14 @@
 		try {
 			FileResource fr = getFileResource();
 			try {
-				List l = new ArrayList();
-				Collection c = fr.list(path);
-				Iterator i = c.iterator();
-				while (i.hasNext()) {
-					GridFile gf = (GridFile) i.next();
+				List<AbsFile> l = new ArrayList<AbsFile>();
+				for (GridFile gf : fr.list(path)) {
 					AbsFile f = new AbsFile(protocol, host, gf.getAbsolutePathName());
 					if (filter == null || filter.accept(new File(f.getDir()), f.getName())) {
 						l.add(f);
 					}
 				}
-				return (AbsFile[]) l.toArray(FILE_ARRAY);
+				return l.toArray(FILE_ARRAY);
 			}
 			finally {
 				releaseResource(fr);
@@ -179,4 +174,20 @@
             throw new RuntimeException(e);
         }
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof AbsFile) {
+            AbsFile a = (AbsFile) obj;
+            return protocol.equals(a.protocol) && host.equals(a.host) && path.equals(a.path);
+        }
+        else {
+            return false;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return protocol.hashCode() + host.hashCode() + path.hashCode();
+    }
 }




More information about the Swift-commit mailing list