further API simplification
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 3 Mar 2015 18:18:41 +0000 (20:18 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Tue, 3 Mar 2015 18:18:41 +0000 (20:18 +0200)
src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java
src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java
src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java [deleted file]
src/test/java/eu/svjatoslav/inspector/java/structure/example/RenderJavaInspect.java

index e43fe8d..9f657d1 100755 (executable)
@@ -335,7 +335,7 @@ public class ClassDescriptor implements GraphElement {
        public String getGraphId() {
                final String result = "class_"
                                + fullyQualifiedName.replace('.', '_').replace(";", "")
-                               .replace("[L", "").replace('$', '_');
+                                               .replace("[L", "").replace('$', '_');
                return result;
        }
 
@@ -471,7 +471,7 @@ public class ClassDescriptor implements GraphElement {
                if (Utils.isSystemPackage(fullyQualifiedName))
                        return false;
 
-               if (!getClassGraph().getFilter().isClassShown(fullyQualifiedName))
+               if (!getClassGraph().isClassShown(fullyQualifiedName))
                        return false;
 
                if (isArray)
index 27eff03..cee1ee4 100755 (executable)
@@ -12,10 +12,13 @@ package eu.svjatoslav.inspector.java.structure;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import eu.svjatoslav.commons.file.CommonPathResolver;
+import eu.svjatoslav.commons.string.WildCardMatcher;
 import eu.svjatoslav.inspector.java.methods.Clazz;
 import eu.svjatoslav.inspector.java.methods.ProjectScanner;
 
@@ -26,7 +29,9 @@ public class ClassGraph {
         */
        private final Map<String, ClassDescriptor> fullyQualifiedNameToClassMap = new HashMap<String, ClassDescriptor>();
 
-       private final Filter filter = new Filter();
+       private final List<String> blacklistClassPatterns = new ArrayList<String>();
+
+       private final List<String> whitelistClassPatterns = new ArrayList<String>();
 
        public ClassGraph() {
        }
@@ -69,6 +74,10 @@ public class ClassGraph {
                        }
        }
 
+       public void blacklistClassPattern(final String pattern) {
+               blacklistClassPatterns.add(pattern);
+       }
+
        /**
         * @param resultFileName
         *            file name for the generated graph. Existing file with the same
@@ -132,8 +141,8 @@ public class ClassGraph {
                        // execute GraphViz to visualize graph
                        try {
                                Runtime.getRuntime()
-                                               .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o",
-                                                               imageFilePath }).waitFor();
+                               .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o",
+                                               imageFilePath }).waitFor();
                        } catch (final InterruptedException e) {
                        } finally {
                        }
@@ -165,10 +174,6 @@ public class ClassGraph {
                return resultStr;
        }
 
-       public Filter getFilter() {
-               return filter;
-       }
-
        /**
         * @param clazz
         *            class that shall be added to graph
@@ -205,4 +210,23 @@ public class ClassGraph {
 
        }
 
+       public boolean isClassShown(final String className) {
+               for (final String pattern : blacklistClassPatterns)
+                       if (WildCardMatcher.match(className, pattern))
+                               return false;
+
+               if (!whitelistClassPatterns.isEmpty()) {
+                       for (final String pattern : whitelistClassPatterns)
+                               if (WildCardMatcher.match(className, pattern))
+                                       return true;
+                       return false;
+               }
+
+               return true;
+       }
+
+       public void whitelistClassPattern(final String pattern) {
+               whitelistClassPatterns.add(pattern);
+       }
+
 }
diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java b/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java
deleted file mode 100755 (executable)
index 0519c36..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.inspector.java.structure;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import eu.svjatoslav.commons.string.WildCardMatcher;
-
-public class Filter {
-
-       /**
-        * This class implements filter of classes that will be included or excluded
-        * from resulting graph.
-        * 
-        * Filtering is done by lists of whitelist and blacklist patterns using
-        * wildcards.
-        * 
-        * Filtering logic is such that if at least single whitelist entry is
-        * defined then every class that is not whitelisted is automatically
-        * excluded from graph.
-        * 
-        * Otherwise every class in included in graph that is not blacklisted.
-        */
-
-       private final List<String> blacklistClassPatterns = new ArrayList<String>();
-
-       private final List<String> whitelistClassPatterns = new ArrayList<String>();
-
-       public void blacklistClassPattern(final String pattern) {
-               blacklistClassPatterns.add(pattern);
-       }
-
-       public boolean isClassShown(final String className) {
-               for (final String pattern : blacklistClassPatterns)
-                       if (WildCardMatcher.match(className, pattern))
-                               return false;
-
-               if (!whitelistClassPatterns.isEmpty()) {
-                       for (final String pattern : whitelistClassPatterns)
-                               if (WildCardMatcher.match(className, pattern))
-                                       return true;
-                       return false;
-               }
-
-               return true;
-       }
-
-       public void whitelistClassPattern(final String pattern) {
-               whitelistClassPatterns.add(pattern);
-       }
-
-}
index 7d9eb80..2bfd560 100755 (executable)
@@ -24,8 +24,7 @@ public class RenderJavaInspect {
                graph.addProject(".");
 
                // Blacklist example classes from being shown on the graph
-               graph.getFilter().blacklistClassPattern(
-                               "eu.svjatoslav.inspector.java.structure.example.*");
+               graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*");
 
                // do not show single classes with no relationships on the graph
                graph.hideOrphanedClasses();