]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Common.java
func name changed & modify common.todoall
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Common.java
index 44b25e7e12d9b630c367c13a1c185b8855da05ca..5b4d33adb8299e8fa0633a90d5b1250a3d5a2503 100644 (file)
@@ -60,7 +60,13 @@ public final class Common {
        //-----------------------------------file&string---------------------------------------//\r
 \r
        //--------------------------------------dir--------------------------------------------//\r
-       \r
+       /*\r
+       public static final HashSet<String> walkDir(String path, int mode) throws Exception {\r
+               HashSet<String> pathlist = new HashSet<String>();\r
+               Common.toDoAll(path, Common.class.getMethod("walkDir", String.class), null, null, mode);\r
+               return pathlist;\r
+       }\r
+       */\r
        public static final void ensureDir(String objFileWhole) {\r
                File tempdir;\r
                Matcher mtrseparate = ptnseparate.matcher(objFileWhole);\r
@@ -137,16 +143,21 @@ public final class Common {
                }\r
        }\r
        \r
-       public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo\r
+       public static void toDoAll(String path, ForDoAll fda, int type) throws Exception { // filter of file type can be done in toDo\r
                String[] list = new File(path).list();\r
                File test;\r
 \r
+               if (type == DIR || type == BOTH) {\r
+                       fda.toDo(path);\r
+               }\r
                for (int i = 0 ; i < list.length ; i++) {\r
                        test = new File(path + File.separator + list[i]);\r
                        if (test.isDirectory()) {\r
-                               toDoAll(path + File.separator + list[i], fda);\r
+                               toDoAll(path + File.separator + list[i], fda, type);\r
                        } else {\r
-                               fda.toDo(path + File.separator + list[i]);\r
+                               if (type == FILE || type == BOTH) {\r
+                                       fda.toDo(path + File.separator + list[i]);\r
+                               }\r
                        }\r
                }\r
        }\r
@@ -154,4 +165,42 @@ public final class Common {
        public static interface ForDoAll {\r
                public void toDo(String filepath) throws Exception;\r
        }\r
+       /*\r
+       // this PathIterator is based on HashSet, an thread implementation is required.\r
+       private final class PathIterator implements ForDoAll{\r
+               PathIterator(String path) throws Exception {\r
+                       startpath = path;\r
+                       Common.toDoAll(startpath, this, mode);\r
+               }\r
+               PathIterator(String path, int md) throws Exception {\r
+                       startpath = path;\r
+                       mode = md;\r
+                       Common.toDoAll(startpath, this, mode);\r
+               }\r
+               private String startpath;\r
+               private int mode = Common.BOTH;\r
+               private HashSet<String> pathlist = new HashSet<String>();\r
+               private Iterator<String> it = pathlist.iterator();\r
+               \r
+               public final void toDo(String path) throws Exception {\r
+                       pathlist.add(path);\r
+               }\r
+               \r
+               public final String next() {\r
+                       return it.next();\r
+               }\r
+               \r
+               public final boolean hasNext() {\r
+                       return it.hasNext();\r
+               }\r
+               \r
+               public final String toString() {\r
+                       return pathlist.toString();\r
+               }\r
+       }\r
+       \r
+       public final PathIterator getPathIterator(String path, int md) throws Exception {\r
+               return new PathIterator(path, md);\r
+       }\r
+       */\r
 }\r