Commits

gigadot committed 15a96e9

new rebound constructor added to allow exclusion of either abstract or interface

  • Participants
  • Parent commits fb6f4c1

Comments (0)

Files changed (2)

     <groupId>gigadot.rebound</groupId>
     <artifactId>rebound</artifactId>
     <packaging>jar</packaging>
-    <version>0.1.4</version>
+    <version>0.2</version>
     <name>Rebound - Java Reflection Utilities</name>
     <url>http://maven.apache.org</url>
     <build>

src/main/java/gigadot/rebound/Rebound.java

 /**
  * Copyright 2010 Gigadot [Weerapong Phadungsukanan]
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
  *
  * email : gigadot@gmail.com
  *
     private static Logger logger = Logger.getLogger(Rebound.class);
     private String packagePrefix;
     private static boolean logging = false;
-    private boolean includeAbstractAndInteface;
+    private boolean includeAbstract;
+    private boolean includeInterface;
 
     /**
-     * Default Rebound constructor with empty prefix, the abstract classes
-     * and interfaces are both excluded from search results.
+     * Default Rebound constructor with empty prefix, the abstract classes and interfaces are both excluded from search
+     * results.
      *
-     * Use setIncludeAbstractAndInteface method to change this
-     * property.
+     * Use setIncludeAbstractAndInteface method to change this property.
      */
     public Rebound() {
         this("");
     }
 
     /**
-     * Construct a Rebound object from a given package prefix. Rebound excludes
-     * the abstract classes and interfaces in the search results using this
-     * constructor. Use setIncludeAbstractAndInteface method to change this
-     * property.
+     * Construct a Rebound object from a given package prefix. Rebound excludes the abstract classes and interfaces in
+     * the search results using this constructor. Use setIncludeAbstractAndInteface method to change this property.
      *
      * @param packagePrefix
      */
     }
 
     /**
-     * Construct a Rebound object from a given package prefix and set whether
-     * to include the abstract classes and interfaces in the search results.
+     * Construct a Rebound object from a given package prefix and set whether to include the abstract classes and
+     * interfaces in the search results.
      *
      * @param packagePrefix
      * @param includeAbstractAndInteface
      */
     public Rebound(String packagePrefix, boolean includeAbstractAndInteface) {
         this.packagePrefix = packagePrefix == null ? "" : packagePrefix;
-        this.includeAbstractAndInteface = includeAbstractAndInteface;
+        this.includeAbstract = includeAbstractAndInteface;
+        this.includeInterface = includeAbstractAndInteface;
+    }
+
+    public Rebound(String packagePrefix, boolean includeAbstract, boolean includeInteface) {
+        this.packagePrefix = packagePrefix == null ? "" : packagePrefix;
+        this.includeAbstract = includeAbstract;
+        this.includeInterface = includeInteface;
     }
 
     /**
      * Set package prefix.
+     *
      * @param packagePrefix
      */
     public void setPackagePrefix(String packagePrefix) {
 
     /**
      * Set whether to include the abstract classes and interfaces in the search results.
+     *
      * @param includeAbstractAndInteface
      */
     public void setIncludeAbstractAndInteface(boolean includeAbstractAndInteface) {
-        this.includeAbstractAndInteface = includeAbstractAndInteface;
+        this.includeAbstract = includeAbstractAndInteface;
+        this.includeInterface = includeAbstractAndInteface;
+    }
+
+    public void setIncludeAbstract(boolean includeAbstract) {
+        this.includeAbstract = includeAbstract;
+    }
+
+    public void setIncludeInterface(boolean includeInterface) {
+        this.includeInterface = includeInterface;
     }
 
     /**
      * Find subclasses of a given super class or interface.
+     *
      * @param <T>
      * @param clazz
      * @return
                 logger.error(ex);
             }
         }
-        if (!includeAbstractAndInteface) {
+        if (!includeAbstract) {
             for (Iterator<Class<? extends T>> it = subClazzes.iterator(); it.hasNext();) {
                 int modifiers = it.next().getModifiers();
-                if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) {
+                if (Modifier.isAbstract(modifiers)) {
+                    it.remove();
+                }
+            }
+        }
+        if (!includeInterface) {
+            for (Iterator<Class<? extends T>> it = subClazzes.iterator(); it.hasNext();) {
+                int modifiers = it.next().getModifiers();
+                if (Modifier.isInterface(modifiers)) {
                     it.remove();
                 }
             }
     private Set<Class> temp_classes_set;
 
     /**
-     * When use with empty package name, it look up inside every jar file.
-     * This is a lengthy and time consuming process. Please consider using Rebound with prefix.
+     * When use with empty package name, it look up inside every jar file. This is a lengthy and time consuming process.
+     * Please consider using Rebound with prefix.
      *
      * @param packagePrefix
      * @return
     }
 
     /**
-     * Get a jar file object from given resource URL. The bits after !/ in jar URL
-     * is removed before processing it to jar file object.
+     * Get a jar file object from given resource URL. The bits after !/ in jar URL is removed before processing it to
+     * jar file object.
+     *
      * @param url
      * @return
      */
 
     /**
      * Get a jar file object from given file object.
+     *
      * @param url
      * @return
      */