public final class Util extends Object
| Modifier and Type | Method and Description |
|---|---|
static TypeToken<?> |
findLowestCommonAncestor(Iterable<TypeToken<?>> types)
Find the narrowest type that is a supertype of all of the given types.
|
static TypeToken<?> |
findLowestCommonAncestorOfClasses(Iterable<Class<?>> types)
Find the narrowest type that is a supertype of all of the given types.
|
static Set<TypeToken<?>> |
findLowestCommonAncestors(Iterable<TypeToken<?>> types)
Find the narrowest type(s) each of which is a supertype of all of the given types.
|
static Set<TypeToken<?>> |
findLowestCommonAncestorsOfClasses(Iterable<Class<?>> types)
Find the narrowest type(s) each of which is a supertype of all of the given types.
|
static Type |
getTypeParameter(Type type,
int index)
Get the n'th generic type parameter.
|
static <T> TypeToken<? extends T> |
getWildcardedType(Class<T> type)
Parameterize the raw type with wildcards.
|
static boolean |
hasDefaultValidationAnnotation(AnnotatedElement obj)
Determine whether the given object has any JSR 303 annotation(s) defining validation constraints in the default group.
|
static AnnotatedElement |
hasValidation(Class<?> type)
Determine if any JSR 303 validation annotations are present on the given type itself
or any of its methods (public methods only).
|
static boolean |
hasValidationAnnotation(AnnotatedElement obj)
Determine whether the given object has any JSR 303 annotation(s).
|
static Object |
invoke(Method method,
Object target,
Object... params)
Invoke method via reflection and re-throw any checked exception wrapped in an
JSimpleDBException. |
static boolean |
isAnyGroupBeingValidated(Class<?>[] constraintGroups,
Class<?>[] validationGroups)
Determine if a constraint whose
groups() contain the given constraint groups should be applied
when validating with the given validation groups. |
static boolean |
isGroupBeingValidated(Class<?> constraintGroup,
Class<?>[] validationGroups)
Determine if a constraint whose
groups() contain the given constraint group should be applied
when validating with the given validation groups. |
static <T> TypeToken<? extends T> |
newParameterizedType(Class<T> target,
Type[] params)
Convert a raw class back into its generic type using caller-supplied type parameters.
|
static boolean |
requiresDefaultValidation(Class<?> type)
Determine if instances of the given type require any validation under the default validation group.
|
static boolean |
requiresDefaultValidation(Method method)
Determine if the given getter method, or any method it overrides, has a JSR 303 validation constraint
applicable under the default validation group.
|
public static AnnotatedElement hasValidation(Class<?> type)
type - object typeIllegalArgumentException - if type is nullpublic static boolean requiresDefaultValidation(Class<?> type)
This will be true if type or any of its declared methods has a JSR 303 (public methods only)
or @OnValidate annotation, or if any of its super-types requires validation.
type - object typetype has any validation requirementsIllegalArgumentException - if type is nullValidationModepublic static boolean requiresDefaultValidation(Method method)
method - annotated methodobj has one or more JSR 303 annotationsIllegalArgumentException - if method is nullpublic static boolean hasDefaultValidationAnnotation(AnnotatedElement obj)
obj - annotated elementobj has one or more JSR 303 default validation constraint annotationsIllegalArgumentException - if obj is nullpublic static boolean hasValidationAnnotation(AnnotatedElement obj)
obj - annotated elementobj has one or more JSR 303 validation constraint annotationsIllegalArgumentException - if obj is nullpublic static boolean isGroupBeingValidated(Class<?> constraintGroup, Class<?>[] validationGroups)
groups() contain the given constraint group should be applied
when validating with the given validation groups.constraintGroup - validation group associated with a validation constraintvalidationGroups - groups for which validation is being performedIllegalArgumentException - if any null values are encounteredpublic static boolean isAnyGroupBeingValidated(Class<?>[] constraintGroups, Class<?>[] validationGroups)
groups() contain the given constraint groups should be applied
when validating with the given validation groups.constraintGroups - validation groups associated with a validation constraintvalidationGroups - groups for which validation is being performedIllegalArgumentException - if any null values are encounteredpublic static TypeToken<?> findLowestCommonAncestorOfClasses(Iterable<Class<?>> types)
This method delegates to findLowestCommonAncestor()
after converting the Class instances to TypeTokens.
types - sub-typesIllegalArgumentException - if any type in types is nullfindLowestCommonAncestor()public static Set<TypeToken<?>> findLowestCommonAncestorsOfClasses(Iterable<Class<?>> types)
This method delegates to findLowestCommonAncestors()
after converting the Class instances to TypeTokens.
types - sub-typesIllegalArgumentException - if any type in types is nullfindLowestCommonAncestors()public static TypeToken<?> findLowestCommonAncestor(Iterable<TypeToken<?>> types)
Note that there may be more than one such type. The returned type will always be as narrow as possible, but it's possible there for there to be multiple such types for which none is a sub-type of any other.
When there is more than one choice, heuristics are used. For example, we prefer
non-interface types, and JObject over other interface types.
types - sub-typespublic static Set<TypeToken<?>> findLowestCommonAncestors(Iterable<TypeToken<?>> types)
types - sub-typespublic static <T> TypeToken<? extends T> getWildcardedType(Class<T> type)
T - raw typetype - raw typetype genericized with wildcardspublic static Type getTypeParameter(Type type, int index)
type - parameterized generic typeindex - type parameter index (zero based)indexIllegalArgumentException - if type is not a parameterized type with more than index type variablespublic static Object invoke(Method method, Object target, Object... params)
JSimpleDBException.method - method to invoketarget - instance, or null if method is staticparams - method parameterspublic static <T> TypeToken<? extends T> newParameterizedType(Class<T> target, Type[] params)
T - raw class typetarget - raw classparams - type parametersTypeToken for targetCopyright © 2017. All rights reserved.