[Arakhnę-Dev] [122] - Add files to ignore in SVN repository.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 122
Author:   galland
Date:     2010-02-12 22:22:08 +0100 (Fri, 12 Feb 2010)
Log Message:
-----------
- Add files to ignore in SVN repository.
- Add ReflectionUtil.getAllDirectInterfaces() and ReflectionUtil.getSuperclasses().

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java

Property Changed:
----------------
    trunk/arakhneVmutils/java/

Property changes on: trunk/arakhneVmutils/java
___________________________________________________________________
Modified: svn:ignore
   - target

   + target
..settings
..classpath
..project


Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java	2010-02-12 21:21:16 UTC (rev 121)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java	2010-02-12 21:22:08 UTC (rev 122)
@@ -28,6 +28,8 @@
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
@@ -462,4 +464,75 @@
 		}
 	}
 	
+	/**
+     * Determines the interfaces implemented by the classes from the lowest type
+     * to the highestType which are extended the given interfaceType.
+     * <p>
+     * Insteed of {@link Class#getInterfaces()}, this function is exploring
+     * the super classes. This function does not explore super-interfaces
+     * of implemented interfaces.
+     * <p>
+     * <pre><code>
+     * interface IA {}
+     * interface IB extends IA {}
+     * interface IC {}
+     * interface ID extends IB, IC {}
+     * class CA implements IC {}
+     * class CB extends CA {}
+     * class CC extends CB implements IB {}
+     * </code></pre>
+     * This function replies for:
+     * <ul>
+     * <li><code>getAllDirectInterfaces(IA,null,null)</code>=<code>{}</code></li>
+     * <li><code>getAllDirectInterfaces(IB,null,null)</code>=<code>{IA}</code></li>
+     * <li><code>getAllDirectInterfaces(IC,null,null)</code>=<code>{}</code></li>
+     * <li><code>getAllDirectInterfaces(ID,null,null)</code>=<code>{IB,IC}</code></li>
+     * <li><code>getAllDirectInterfaces(CA,null,null)</code>=<code>{IC}</code></li>
+     * <li><code>getAllDirectInterfaces(CB,null,null)</code>=<code>{IC}</code></li>
+     * <li><code>getAllDirectInterfaces(CC,null,null)</code>=<code>{IB,IC}</code></li>
+     * </ul>
+	 * 
+	 * @param <T> is the highest type to explore in type hierarchy.
+	 * @param lowestType is the lowest type to explore in type hierarchy.
+	 * @param highestType is the highest type to explore in type hierarchy.
+	 * @param interfaceType indicates the type of the replied interfaces.
+	 * @return the implemented interfaces.
+	 */
+	public static <T> Set<Class<?>> getAllDirectInterfaces(Class<? extends T> lowestType, Class<T> highestType, Class<?> interfaceType) {
+		assert(lowestType!=null);
+		Set<Class<?>> collection = new TreeSet<Class<?>>();
+		Class<?> type = lowestType;
+		boolean cont;
+		do {
+			for(Class<?> directInterface : type.getInterfaces()) {
+				if (interfaceType==null || interfaceType.isAssignableFrom(directInterface))
+						collection.add(directInterface);
+			}
+			cont = (highestType==null || !type.equals(highestType));
+			type = type.getSuperclass();
+		}
+		while (type!=null && cont);
+		return collection;
+	}
+	
+	/**
+	 * Replies the list of all the superclasses of the given class.
+	 * <p>
+	 * This function does not replies <code>Object.class</code>.
+	 * 
+	 * @param <T> is the type of the lowest class.
+	 * @param className is the type of the lowest class.
+	 * @return the list of superclasses.
+	 */
+	public static <T> Collection<Class<? super T>> getSuperClasses(Class<T> className) {
+		assert(className!=null);
+		Collection<Class<? super T>> list = new ArrayList<Class<? super T>>();
+		Class<? super T> type = className.getSuperclass();
+		while (type!=null && !Object.class.equals(type)) {
+			list.add(type);
+			type = type.getSuperclass();
+		}
+		return list;
+	}
+
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/