List of usage examples for java.lang Class isEnum
public boolean isEnum()
From source file:Main.java
public static String canBeABeanType(Class<?> paramClass) { if (paramClass.isAnnotation()) return "annotation"; if (paramClass.isArray()) return "array"; if (paramClass.isEnum()) return "enum"; if (paramClass.isPrimitive()) return "primitive"; return null;// ww w. ja va2s . c om }
From source file:com.mtgi.analytics.aop.BehaviorTrackingAdvice.java
private static final boolean shouldLog(Class<?> type) { return (type.isPrimitive()) || type.isEnum() || type.getName().startsWith("java.lang"); }
From source file:com.netflix.zeno.genericobject.GenericObjectFrameworkSerializer.java
private static boolean isPrimitive(Class<?> type) { return type.isEnum() || PrimitiveObjectIdentifier.isPrimitiveOrWrapper(type); }
From source file:net.eledge.android.toolkit.db.internal.FieldType.java
public static FieldType getType(Class<?> clazz) { if (clazz.isEnum()) { return ENUM; }/*from w w w .j a va2 s. c om*/ String type = clazz.getSimpleName(); if ("int".equals(type)) { return INTEGER; } return valueOf(type.toUpperCase(Locale.ENGLISH)); }
From source file:org.apache.shiro.guice.BeanTypeListener.java
private static boolean requiresName(Type propertyType) { if (propertyType instanceof Class) { Class<?> aClass = (Class<?>) propertyType; return aClass.isPrimitive() || aClass.isEnum() || WRAPPER_TYPES.contains(aClass) || CharSequence.class.isAssignableFrom(aClass); } else {/*from w ww.j a v a2 s . c o m*/ return false; } }
From source file:Main.java
/** * @param type the type can be converted to simple String * @return true of the type is simple/* ww w. j a va 2 s . com*/ */ public static boolean isSimpleType(Type type) { boolean simpleType = false; if (type instanceof Class) { Class<?> typeClass = (Class<?>) type; simpleType = SIMPLECLASSES.contains(typeClass) || Number.class.isAssignableFrom(typeClass) || typeClass.isPrimitive() || typeClass.isEnum(); } return simpleType; }
From source file:org.grails.orm.hibernate.cfg.AbstractIdentityEnumType.java
@SuppressWarnings("unchecked") public static boolean supports(@SuppressWarnings("rawtypes") Class enumClass) { if (enumClass.isEnum()) { try {/*ww w . ja va 2 s. c o m*/ Method idAccessor = enumClass.getMethod(ENUM_ID_ACCESSOR); int mods = idAccessor.getModifiers(); if (Modifier.isPublic(mods) && !Modifier.isStatic(mods)) { Class<?> returnType = idAccessor.getReturnType(); return returnType != null && typeResolver.basic(returnType.getName()) instanceof AbstractStandardBasicType; } } catch (NoSuchMethodException e) { // ignore } } return false; }
From source file:Main.java
/** * @return Null if class might be a bean; type String (that identifies * why it's not a bean) if not// w ww . j a v a 2 s . c o m */ public static String canBeABeanType(Class<?> type) { // First: language constructs that ain't beans: if (type.isAnnotation()) { return "annotation"; } if (type.isArray()) { return "array"; } if (type.isEnum()) { return "enum"; } if (type.isPrimitive()) { return "primitive"; } // Anything else? Seems valid, then return null; }
From source file:com.microsoft.rest.Validator.java
/** * Validates a user provided required parameter to be not null. * A {@link ServiceException} is thrown if a property fails the validation. * * @param parameter the parameter to validate * @throws ServiceException failures wrapped in {@link ServiceException} *///from ww w .j av a2 s . c o m public static void validate(Object parameter) throws ServiceException { // Validation of top level payload is done outside if (parameter == null) { return; } Class parameterType = parameter.getClass(); if (ClassUtils.isPrimitiveOrWrapper(parameterType) || parameterType.isEnum() || ClassUtils.isAssignable(parameterType, LocalDate.class) || ClassUtils.isAssignable(parameterType, DateTime.class) || ClassUtils.isAssignable(parameterType, String.class) || ClassUtils.isAssignable(parameterType, DateTimeRfc1123.class) || ClassUtils.isAssignable(parameterType, Period.class)) { return; } Field[] fields = FieldUtils.getAllFields(parameterType); for (Field field : fields) { field.setAccessible(true); JsonProperty annotation = field.getAnnotation(JsonProperty.class); Object property; try { property = field.get(parameter); } catch (IllegalAccessException e) { throw new ServiceException(e); } if (property == null) { if (annotation != null && annotation.required()) { throw new ServiceException( new IllegalArgumentException(field.getName() + " is required and cannot be null.")); } } else { try { Class propertyType = property.getClass(); if (ClassUtils.isAssignable(propertyType, List.class)) { List<?> items = (List<?>) property; for (Object item : items) { Validator.validate(item); } } else if (ClassUtils.isAssignable(propertyType, Map.class)) { Map<?, ?> entries = (Map<?, ?>) property; for (Map.Entry<?, ?> entry : entries.entrySet()) { Validator.validate(entry.getKey()); Validator.validate(entry.getValue()); } } else if (parameter.getClass().getDeclaringClass() != propertyType) { Validator.validate(property); } } catch (ServiceException ex) { IllegalArgumentException cause = (IllegalArgumentException) (ex.getCause()); if (cause != null) { // Build property chain throw new ServiceException( new IllegalArgumentException(field.getName() + "." + cause.getMessage())); } else { throw ex; } } } } }
From source file:com.darkstar.beanCartography.utils.NameUtils.java
/** * For the purposes of this project, 'immutable' types will be those types that we do not want to * delve down into. We want to treat them as if they were leaf nodes. * * @param clazz class to check for immutability * @return <code>true</code> if immutable *//*from w w w . j a v a2s . c o m*/ public static boolean isImmutable(Class<?> clazz) { return clazz == null || clazz.isEnum() || immutableClasses.contains(clazz); }