[Arakhnę-Dev] [367] * Add the function ReflectionUtil.matcheParameters(). |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 367
Author: galland
Date: 2012-08-14 23:11:16 +0200 (Tue, 14 Aug 2012)
Log Message:
-----------
* Add the function ReflectionUtil.matcheParameters().
Modified Paths:
--------------
trunk/arakhneVmutils/arakhneVmutils-java/pom.xml
trunk/arakhneVmutils/arakhneVmutils-java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java
trunk/arakhneVmutils/arakhneVmutils-native/pom.xml
Modified: trunk/arakhneVmutils/arakhneVmutils-java/pom.xml
===================================================================
--- trunk/arakhneVmutils/arakhneVmutils-java/pom.xml 2012-08-13 11:36:14 UTC (rev 366)
+++ trunk/arakhneVmutils/arakhneVmutils-java/pom.xml 2012-08-14 21:11:16 UTC (rev 367)
@@ -10,7 +10,7 @@
<artifactId>afc</artifactId>
<groupId>org.arakhne.afc</groupId>
<version>4.4-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
+ <relativePath>../..</relativePath>
</parent>
<artifactId>arakhneVmutils-java</artifactId>
Modified: trunk/arakhneVmutils/arakhneVmutils-java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java
===================================================================
--- trunk/arakhneVmutils/arakhneVmutils-java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java 2012-08-13 11:36:14 UTC (rev 366)
+++ trunk/arakhneVmutils/arakhneVmutils-java/src/main/java/org/arakhne/vmutil/ReflectionUtil.java 2012-08-14 21:11:16 UTC (rev 367)
@@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
@@ -654,5 +655,110 @@
}
return top;
}
+
+ /** Replies the outboxing type for the given type.
+ *
+ * @param type
+ * @return the outboxing of the given type.
+ * @since 7.1
+ */
+ public static Class<?> getOutboxingType(Class<?> type) {
+ if (void.class.equals(type)) {
+ return Void.class;
+ }
+ if (boolean.class.equals(type)) {
+ return Boolean.class;
+ }
+ if (byte.class.equals(type)) {
+ return Byte.class;
+ }
+ if (char.class.equals(type)) {
+ return Character.class;
+ }
+ if (double.class.equals(type)) {
+ return Double.class;
+ }
+ if (float.class.equals(type)) {
+ return Float.class;
+ }
+ if (int.class.equals(type)) {
+ return Integer.class;
+ }
+ if (long.class.equals(type)) {
+ return Long.class;
+ }
+ if (short.class.equals(type)) {
+ return Short.class;
+ }
+ return type;
+ }
+ /** Replies the outboxing type for the given type.
+ *
+ * @param type
+ * @return the outboxing of the given type.
+ * @since 7.1
+ */
+ public static Class<?> getInboxingType(Class<?> type) {
+ if (Void.class.equals(type)) {
+ return void.class;
+ }
+ if (Boolean.class.equals(type)) {
+ return boolean.class;
+ }
+ if (Byte.class.equals(type)) {
+ return byte.class;
+ }
+ if (Character.class.equals(type)) {
+ return char.class;
+ }
+ if (Double.class.equals(type)) {
+ return double.class;
+ }
+ if (Float.class.equals(type)) {
+ return float.class;
+ }
+ if (Integer.class.equals(type)) {
+ return int.class;
+ }
+ if (Long.class.equals(type)) {
+ return long.class;
+ }
+ if (Short.class.equals(type)) {
+ return short.class;
+ }
+ return type;
+ }
+
+ /** Replies if the formal parameters are matching the given values.
+ *
+ * @param formalParameters
+ * @param parameters
+ * @return <code>true</code> if the values could be passed to the method.
+ * @since 7.1
+ */
+ public static boolean matchesParameters(Class<?>[] formalParameters, Object... parameterValues) {
+ if (formalParameters==null) return parameterValues==null;
+ if (parameterValues!=null && formalParameters.length==parameterValues.length) {
+ for(int i=0; i<formalParameters.length; ++i) {
+ if (!isInstance(formalParameters[i], parameterValues[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /** Replies if the parameters of the given method are matching the given values.
+ *
+ * @param method
+ * @param parameters
+ * @return <code>true</code> if the values could be passed to the method.
+ * @since 7.1
+ */
+ public static boolean mathesParameters(Method method, Object... parameters) {
+ return matchesParameters(method.getParameterTypes(), parameters);
+ }
+
}
Modified: trunk/arakhneVmutils/arakhneVmutils-native/pom.xml
===================================================================
--- trunk/arakhneVmutils/arakhneVmutils-native/pom.xml 2012-08-13 11:36:14 UTC (rev 366)
+++ trunk/arakhneVmutils/arakhneVmutils-native/pom.xml 2012-08-14 21:11:16 UTC (rev 367)
@@ -11,7 +11,7 @@
<artifactId>afc</artifactId>
<groupId>org.arakhne.afc</groupId>
<version>4.4-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
+ <relativePath>../..</relativePath>
</parent>
<artifactId>arakhneVmutils-native</artifactId>