polish code
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 24 Aug 2011 16:59:39 +0000 (18:59 +0200)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 24 Aug 2011 16:59:39 +0000 (18:59 +0200)
nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/fsScanner/AntPatternState.java
nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/fsScanner/DirectoryScanner.java
nuget-tests/src/testng-nuget-fast.xml

index 1d1da6fc51ff9c687da50fa929f11f187f577518..3e26f8c5c895b5ef369cd5fb72a4463d8e6a1426 100644 (file)
@@ -75,30 +75,37 @@ public class AntPatternState {
 \r
     //TODO:replace list with array operations\r
 \r
-    List<Integer> newPositions = new ArrayList<Integer>(myPatternPositions.size());\r
+    final List<Integer> newPositions = new ArrayList<Integer>(myPatternPositions.size());\r
+\r
     for (int pos : myPatternPositions) {\r
-      Wildcard wildcard = myPatternParts.get(pos);\r
+      final Wildcard wildcard = myPatternParts.get(pos);\r
+\r
       if (wildcard != null) {\r
-        if (wildcard.IsMatch(component))\r
-          if (pos == myPatternParts.size() - 1)\r
+        if (wildcard.IsMatch(component)) {\r
+          if (pos == myPatternParts.size() - 1) {\r
             match = MatchResult.YES;\r
-          else if (pos == myPatternParts.size() - 2 && myPatternParts.get(pos + 1) == null) {\r
+          else if (pos == myPatternParts.size() - 2 && myPatternParts.get(pos + 1) == null) {\r
             match = MatchResult.YES;\r
             newPositions.add(pos + 1);\r
-          } else newPositions.add(pos + 1);\r
-        else if (match == MatchResult.MAYBELATER) match = MatchResult.NO;\r
+          } else {\r
+            newPositions.add(pos + 1);\r
+          }\r
+        } else if (match == MatchResult.MAYBELATER) {\r
+          match = MatchResult.NO;\r
+        }\r
       } else {\r
         // **\r
         newPositions.add(pos);\r
 \r
-        if (pos == myPatternParts.size() - 1)\r
+        if (pos == myPatternParts.size() - 1) {\r
           match = MatchResult.YES;\r
-        else {\r
+        else {\r
           if (myPatternParts.get(pos + 1).IsMatch(component)) {\r
-            if (pos == myPatternParts.size() - 2)\r
+            if (pos == myPatternParts.size() - 2) {\r
               match = MatchResult.YES;\r
-            else\r
+            } else {\r
               newPositions.add(pos + 2);\r
+            }\r
           }\r
         }\r
       }\r
index 918b6fcb07f7b589aa86bec563665112fe180387..49bd9a55626f919ae4c44382cfae8b16d6ca01f0 100644 (file)
@@ -90,11 +90,12 @@ public class DirectoryScanner {
 \r
   private static boolean Any(List<AntPatternState> state, String component, AnyPredicate predicate, List<AntPatternState> newState) {\r
     boolean any = false;\r
+    newState.clear();\r
 \r
-    for (int i = 0; i < state.size(); i++) {\r
-      final AntPatternState.AntPatternStateMatch enter = state.get(i).Enter(component);\r
+    for (AntPatternState aState : state) {\r
+      final AntPatternState.AntPatternStateMatch enter = aState.Enter(component);\r
       AntPatternState.MatchResult match = enter.getResult();\r
-      newState.add(i, enter.getState());\r
+      newState.add(enter.getState());\r
 \r
       if (predicate.matches(match))\r
         any = true;\r
@@ -108,11 +109,11 @@ public class DirectoryScanner {
     for (IFileEntry file : directory.Files()) {\r
       List<AntPatternState> newState = new ArrayList<AntPatternState>();\r
 \r
-      if (!Any(includeState, file.Name(), AntPredicateImpl.Predicate(false, AntPatternState.MatchResult.YES), newState))\r
+      if (!Any(includeState, file.Name(), Predicate(false, AntPatternState.MatchResult.YES), newState))\r
         continue;\r
 \r
       newState.clear();\r
-      if (Any(excludeState, file.Name(), AntPredicateImpl.Predicate(false, AntPatternState.MatchResult.YES), newState))\r
+      if (Any(excludeState, file.Name(), Predicate(false, AntPatternState.MatchResult.YES), newState))\r
         continue;\r
 \r
       result.add(file.Path());\r
@@ -122,38 +123,23 @@ public class DirectoryScanner {
       String name = subEntry.Name();\r
 \r
       List<AntPatternState> newIncludeState = new ArrayList<AntPatternState>();\r
-      if (!Any(includeState, name, AntPredicateImpl.Predicate(true, AntPatternState.MatchResult.NO), newIncludeState))\r
+      if (!Any(includeState, name, Predicate(true, AntPatternState.MatchResult.NO), newIncludeState))\r
         continue;\r
 \r
       List<AntPatternState> newExcludeState = new ArrayList<AntPatternState>();\r
-      if (Any(excludeState, name, AntPredicateImpl.Predicate(false, AntPatternState.MatchResult.YES), newExcludeState))\r
+      if (Any(excludeState, name, Predicate(false, AntPatternState.MatchResult.YES), newExcludeState))\r
         continue;\r
 \r
       FindFilesRec(subEntry, result, newIncludeState, newExcludeState);\r
     }\r
   }\r
 \r
-  private static class AntPredicateImpl {\r
-    private final boolean myNegatiate;\r
-    private final AntPatternState.MatchResult myResult;\r
-\r
-    private AntPredicateImpl(boolean negatiate, AntPatternState.MatchResult result) {\r
-      myNegatiate = negatiate;\r
-      myResult = result;\r
-    }\r
-\r
-    private boolean AnyPredicateImpl(AntPatternState.MatchResult r) {\r
-      return myNegatiate ? myResult != r : myResult == r;\r
-    }\r
-\r
-\r
-    public static AnyPredicate Predicate(boolean not, AntPatternState.MatchResult state) {\r
-      final AntPredicateImpl antPredicate = new AntPredicateImpl(not, state);\r
-      return new AnyPredicate() {\r
-        public boolean matches(AntPatternState.MatchResult r) {\r
-          return antPredicate.AnyPredicateImpl(r);\r
-        }\r
-      };\r
-    }\r
+  public static AnyPredicate Predicate(final boolean not, final AntPatternState.MatchResult state) {\r
+    return new AnyPredicate() {\r
+      public boolean matches(AntPatternState.MatchResult r) {\r
+        return not ? state != r : state == r;\r
+      }\r
+    };\r
   }\r
+\r
 }\r
index 4800c28219736f674ea522e0da518b4cce4cfd41..a3e30c185d791ffcac0f08c3fa493b99003c9c40 100644 (file)
@@ -1,5 +1,16 @@
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">\r
 <suite name="nuget">\r
+  <test name="fs scanner">\r
+    <classes>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.DirectoryFileFilesystemTest"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestAntPatternState"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestAntPatternUtil"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestDirectoryScanner"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestReadFileSystem"/>\r
+      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestWildcard"/>\r
+    </classes>\r
+  </test>\r
+\r
   <test name="fast tests">\r
     <classes>\r
       <class name="jetbrains.buildServer.nuget.tests.RunTypeNameTest"/>\r
       <class name="jetbrains.buildServer.nuget.tests.agent.PackRunnerTest"/>\r
     </classes>\r
   </test>\r
-\r
-  <test name="fs scanner">\r
-    <classes>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.DirectoryFileFilesystemTest"/>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestAntPatternState"/>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestAntPatternUtil"/>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestDirectoryScanner"/>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestReadFileSystem"/>\r
-      <class name="jetbrains.buildServer.nuget.tests.util.fsScanner.TestWildcard"/>\r
-    </classes>\r
-  </test>\r
 </suite>\r
 \r