]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Common.java
REMODEL OF SourceFileReplacer.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Common.java
index 2fcd092315a43553c9d0f7bd0287b1eb6c1a62d1..fb89dcae4dfa452e65d43b2e05ade852a577caca 100644 (file)
@@ -22,6 +22,7 @@ public final class Common {
        public static final int FILE = 1;\r
        public static final int DIR = 2;\r
        \r
+       public static final String strseparate = "(.*)\\\\([^\\\\]*)";\r
        public static final Pattern ptnseparate = Pattern.compile("(.*)\\\\([^\\\\]*)");\r
 \r
        //-------------------------------------regex------------------------------------------//\r
@@ -59,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
@@ -135,22 +142,42 @@ public final class Common {
                        }\r
                }\r
        }\r
+\r
+       public static final void toDoAll(Set<String> set, ForDoAll fda) throws Exception {\r
+               Iterator<String> di = set.iterator();\r
+               while (di.hasNext()) {\r
+                       fda.run(di.next());\r
+               }\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 final 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
+                       if (fda.dirFilter(path)) {\r
+                               fda.run(path);\r
+                       }\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
+                                       if (fda.fileFilter(path + File.separator + list[i])) {\r
+                                               fda.run(path + File.separator + list[i]);\r
+                                       }\r
+                               }\r
                        }\r
                }\r
        }\r
        \r
        public static interface ForDoAll {\r
-               public void toDo(String filepath) throws Exception;\r
+               public void run(String filepath) throws Exception;\r
+               \r
+               public boolean dirFilter(String filepath);\r
+               \r
+               public boolean fileFilter(String filepath);\r
        }\r
 }\r