List of usage examples for java.lang Class isEnum
public boolean isEnum()
From source file:EnumSpy.java
public static void main(String... args) { try {/*from w w w . j av a 2 s.c om*/ Class<?> c = Class.forName(args[0]); if (!c.isEnum()) { out.format("%s is not an enum type%n", c); return; } out.format("Class: %s%n", c); Field[] flds = c.getDeclaredFields(); List<Field> cst = new ArrayList<Field>(); // enum constants List<Field> mbr = new ArrayList<Field>(); // member fields for (Field f : flds) { if (f.isEnumConstant()) cst.add(f); else mbr.add(f); } if (!cst.isEmpty()) print(cst, "Constant"); if (!mbr.isEmpty()) print(mbr, "Field"); Constructor[] ctors = c.getDeclaredConstructors(); for (Constructor ctor : ctors) { out.format(fmt, "Constructor", ctor.toGenericString(), synthetic(ctor)); } Method[] mths = c.getDeclaredMethods(); for (Method m : mths) { out.format(fmt, "Method", m.toGenericString(), synthetic(m)); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:Main.java
public static boolean isEnum(Class<?> cls) { return cls.isEnum(); }
From source file:Main.java
/** * @param stringConvertibleTypes A collection of interfaces. * @param clazz An interface to test.//from w w w . j a v a 2 s . com * @return <code>true</code> if the given interface is an Enum, or if the collection contains a super-interface. */ public static boolean isStringConvertibleType(Set<Class> stringConvertibleTypes, Class clazz) { if (clazz.isEnum()) return true; for (Class toStringOutputType : stringConvertibleTypes) { if (toStringOutputType.isAssignableFrom(clazz)) { return true; } } return false; }
From source file:org.qi4j.runtime.types.EnumType.java
public static boolean isEnum(Type type) { if (type instanceof Class) { Class typeClass = (Class) type; return (typeClass.isEnum()); }// w w w. j a v a 2 s . co m return false; }
From source file:com.yahoo.elide.utils.coerce.CoerceUtil.java
/** * Perform CoerceUtil setup./* www .j a v a 2s . c om*/ */ private static void setup() { BeanUtilsBean.setInstance(new BeanUtilsBean(new ConvertUtilsBean() { @Override /* * Overriding lookup to execute enum converter if target is enum * or map convert if source is map */ public Converter lookup(Class<?> sourceType, Class<?> targetType) { if (targetType.isEnum()) { return TO_ENUM_CONVERTER; } else if (Map.class.isAssignableFrom(sourceType)) { return FROM_MAP_CONVERTER; } else { return super.lookup(sourceType, targetType); } } })); }
From source file:springfox.documentation.schema.Enums.java
public static AllowableValues allowableValues(Class<?> type) { if (type.isEnum()) { List<String> enumValues = getEnumValues(type); return new AllowableListValues(enumValues, "LIST"); }/*from w ww . ja v a 2 s.co m*/ return null; }
From source file:org.raml.parser.utils.ConvertUtils.java
/** * <p>convertTo.</p>/* w ww. ja v a 2s . c o m*/ * * @param value a {@link java.lang.String} object. * @param type a {@link java.lang.Class} object. * @param <T> a T object. * @return a T object. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> T convertTo(String value, Class<T> type) { if (type.isEnum()) { return type.cast(Enum.valueOf((Class) type, value.toUpperCase())); } Class<T> clazz = type; if (type.isPrimitive()) { clazz = ClassUtils.primitiveToWrapper(type); } if (clazz.getName().equals(Boolean.class.getName())) { return clazz.cast(booleanConverter.convert(Boolean.class, value)); } try { Constructor constructor = type.getConstructor(String.class); return (T) constructor.newInstance(value); } catch (Exception e) { //ignore; } return clazz.cast(org.apache.commons.beanutils.ConvertUtils.convert(value, type)); }
From source file:org.raml.parser.utils.ConvertUtils.java
/** * <p>canBeConverted.</p>// www. j a v a2 s. co m * * @param value a {@link java.lang.String} object. * @param type a {@link java.lang.Class} object. * @return a boolean. */ public static boolean canBeConverted(String value, Class<?> type) { if (type.isEnum()) { Object[] enumConstants = type.getEnumConstants(); for (Object enumConstant : enumConstants) { if (enumConstant.toString().equals(value.toUpperCase())) { return true; } } return false; } if (type.isInstance(value)) { return true; } try { type.getConstructor(String.class); return true; } catch (NoSuchMethodException e) { //ignore } try { Class<?> wrapperClass = ClassUtils.primitiveToWrapper(type); convertTo(value, wrapperClass); return true; } catch (ClassCastException e) { return false; } catch (ConversionException e) { return false; } }
From source file:org.raml.parser.utils.ReflectionUtils.java
/** * <p>isEnum.</p>/*from w w w. j a va 2 s . c o m*/ * * @param type a {@link java.lang.Class} object. * @return a boolean. */ public static boolean isEnum(Class<?> type) { return type.isEnum() || (type.getSuperclass() != null && type.getSuperclass().isEnum()); }
From source file:com.wavemaker.tools.apidocs.tools.parser.util.DataTypeUtil.java
/** * @param type data type/*w ww .j a va 2 s . c om*/ * @return true if type is instance of {@link Enum} */ public static boolean isEnum(Class<?> type) { return type.isEnum(); }