Package com.noleme.vault.reflect
Class ClassUtils
- java.lang.Object
-
- com.noleme.vault.reflect.ClassUtils
-
public final class ClassUtils extends Object
- Author:
- Pierre Lecerf ([email protected]) Created on 2020/11/27
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Constructor<?>
getConstructor(Class<?> type, Class<?>[] parameterTypes)
Attempts to find a constructor for the provided class matching with the provided parameter types.static Method
getMethod(Class<?> type, String methodName, Class<?>[] parameterTypes)
Attempts to find a method for the provided class matching with the provided parameter types.static boolean
isBoxedTypeFor(Class<?> c1, Class<?> c2)
static boolean
isParseableAsBoolean(String value)
static boolean
matchesArgumentType(Class<?> providedType, Class<?> argumentType)
Checks whether a given type "matches" with another type found in a method/ctor signature.
-
-
-
Method Detail
-
getConstructor
public static Constructor<?> getConstructor(Class<?> type, Class<?>[] parameterTypes) throws NoSuchMethodException
Attempts to find a constructor for the provided class matching with the provided parameter types.- Parameters:
type
- the type of the class on which to perform the lookupparameterTypes
- the types of arguments expected for the constructor signature- Returns:
- a matching Constructor instance
- Throws:
NoSuchMethodException
- thrown if no matching constructor could be found
-
getMethod
public static Method getMethod(Class<?> type, String methodName, Class<?>[] parameterTypes) throws NoSuchMethodException
Attempts to find a method for the provided class matching with the provided parameter types.- Parameters:
type
- the type of the class on which to perform the lookupmethodName
- the name of the methodparameterTypes
- the types of the arguments expected for the method signature- Returns:
- a matching Method instance
- Throws:
NoSuchMethodException
- thrown if no matching method could be found
-
matchesArgumentType
public static boolean matchesArgumentType(Class<?> providedType, Class<?> argumentType)
Checks whether a given type "matches" with another type found in a method/ctor signature.- Parameters:
providedType
- the type of an inputargumentType
- the type found in a method/ctor signature- Returns:
- true if the types are compatible, false otherwise
-
isBoxedTypeFor
public static boolean isBoxedTypeFor(Class<?> c1, Class<?> c2)
- Parameters:
c1
-c2
-- Returns:
-
isParseableAsBoolean
public static boolean isParseableAsBoolean(String value)
- Parameters:
value
-- Returns:
-
-