List of usage examples for java.lang Class isEnum
public boolean isEnum()
From source file:org.structr.files.cmis.CMISRepositoryService.java
private MutablePropertyDefinition createProperty(final Class type, final PropertyKey key) { // include all dynamic and CMIS-enabled keys in definition if (key.isDynamic() || key.isCMISProperty()) { // only include primitives here final TypeDefinitionFactory factory = TypeDefinitionFactory.newInstance(); final PropertyType dataType = key.getDataType(); if (dataType != null) { final String propertyId = key.jsonName(); final String displayName = propertyId; final String description = StringUtils.capitalize(propertyId); final Class declaringClass = key.getDeclaringClass(); final boolean isInherited = !type.getSimpleName().equals(declaringClass.getSimpleName()); final Cardinality cardinality = Cardinality.SINGLE; final Updatability updatability = Updatability.READWRITE; final boolean required = key.isNotNull(); final boolean queryable = key.isIndexed(); final boolean orderable = key.isIndexed(); final MutablePropertyDefinition property = factory.createPropertyDefinition(propertyId, displayName, description, dataType, cardinality, updatability, isInherited, required, queryable, orderable);// w ww. ja v a 2 s .c o m // add enum choices if present final Class valueType = key.valueType(); if (valueType != null && valueType.isEnum()) { final List<Choice> choices = new LinkedList<>(); for (final Object option : valueType.getEnumConstants()) { final String optionName = option.toString(); choices.add(factory.createChoice(optionName, optionName)); } property.setIsOpenChoice(false); property.setChoices(choices); } return property; } } return null; }
From source file:com.github.helenusdriver.driver.impl.DataDecoder.java
/** * Gets a "map" to {@link Map} decoder based on the given key and value classes. * * @author paouelle/*from w w w.jav a2 s . c om*/ * * @param ekclazz the non-<code>null</code> class of keys * @param evclazz the non-<code>null</code> class of values * @param mandatory if the field associated with the decoder is mandatory or * represents a primary key * @return the non-<code>null</code> decoder for maps of the specified key and * value classes */ @SuppressWarnings("rawtypes") public final static DataDecoder<Map> map(final Class<?> ekclazz, final Class<?> evclazz, final boolean mandatory) { return new DataDecoder<Map>(Map.class) { @SuppressWarnings("unchecked") private Map decodeImpl(Class<?> ektype, Class<?> evtype, Map<Object, Object> map) { if (map == null) { // safe to return as is unless mandatory, that is because Cassandra // returns null for empty list and the schema definition requires // that mandatory and primary keys be non null if (mandatory) { if (ekclazz.isEnum()) { // for enum keys we create an enum map. Now we won't preserve the order // the entries were added but that should be fine anyways in this case return new EnumMap(ekclazz); } return new LinkedHashMap(16); // to keep order } return map; } final Map nmap; if (ekclazz.isEnum()) { // for enum keys we create an enum map. Now we won't preserve the order // the entries were added but that should be fine anyways in this case nmap = new EnumMap(ekclazz); } else { nmap = new LinkedHashMap(map.size()); // to keep order } if (ekclazz.isAssignableFrom(ektype) && evclazz.isAssignableFrom(evtype)) { nmap.putAll(map); } else { // will need to do some conversion of each element final ElementConverter kconverter = ElementConverter.getConverter(ekclazz, ektype); final ElementConverter vconverter = ElementConverter.getConverter(evclazz, evtype); for (final Map.Entry e : map.entrySet()) { final Object k = e.getKey(); final Object v = e.getValue(); nmap.put((k != null) ? kconverter.convert(k) : null, (v != null) ? vconverter.convert(v) : null); } } return nmap; } @SuppressWarnings("unchecked") @Override protected Map decodeImpl(Row row, String name, Class clazz) { return decodeImpl( // get the element type from the row's metadata row.getColumnDefinitions().getType(name).getTypeArguments().get(0).getName().asJavaClass(), row.getColumnDefinitions().getType(name).getTypeArguments().get(1).getName().asJavaClass(), row.isNull(name) ? null : row.getMap(name, Object.class, Object.class) // keeps things generic so we can handle our own errors ); } @SuppressWarnings("unchecked") @Override protected Map decodeImpl(UDTValue uval, String name, Class clazz) { return decodeImpl( // get the element type from the row's metadata uval.getType().getFieldType(name).getTypeArguments().get(0).getName().asJavaClass(), uval.getType().getFieldType(name).getTypeArguments().get(1).getName().asJavaClass(), uval.isNull(name) ? null : uval.getMap(name, Object.class, Object.class) // keeps things generic so we can handle our own errors ); } }; }
From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java
/** * Interfaces, enums, annotations, and abstract classes cannot be * instantiated./*from w ww. ja v a2s . c o m*/ * * @param actionClass * class to check * @return returns true if the class cannot be instantiated or should be * ignored */ protected boolean cannotInstantiate(Class<?> actionClass) { return actionClass.isAnnotation() || actionClass.isInterface() || actionClass.isEnum() || (actionClass.getModifiers() & Modifier.ABSTRACT) != 0 || actionClass.isAnonymousClass(); }
From source file:org.devproof.portal.core.module.configuration.page.ConfigurationPage.java
/** * Override this method to provide custom editors for your fields. * * @param configuration {@link org.devproof.portal.core.module.configuration.entity.Configuration} * @return editor fragment for for the matching configuration type *//*from w w w.ja v a 2 s . co m*/ protected Component createEditorForConfiguration(Configuration configuration) { if (configuration.getKey().startsWith(ConfigurationConstants.SPRING_CONFIGURATION_PREFIX)) { // special case for accessing a spring dao return new SpringBeanEditor("editor", configuration); } else { Class<?> clazz; try { clazz = Class.forName(configuration.getType()); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } if (Boolean.class.isAssignableFrom(clazz)) { return new BooleanEditor("editor", configuration); } else if (clazz.isEnum()) { return new EnumEditor("editor", configuration); } else if (Date.class.isAssignableFrom(clazz)) { return new DateEditor("editor", configuration); } else { return new ValueEditor("editor", configuration); } } }
From source file:java2typescript.jackson.module.StaticFieldExporter.java
private Value constructValue(Module module, Class<?> type, Object rawValue) throws IllegalArgumentException, IllegalAccessException { if (type == boolean.class) { return new Value(BooleanType.getInstance(), rawValue); } else if (type == int.class) { return new Value(NumberType.getInstance(), rawValue); } else if (type == double.class) { return new Value(NumberType.getInstance(), rawValue); } else if (type == String.class) { return new Value(StringType.getInstance(), "'" + (String) rawValue + "'"); } else if (type.isEnum()) { final EnumType enumType = tsJsonFormatVisitorWrapper.parseEnumOrGetFromCache(module, SimpleType.construct(type)); return new Value(enumType, enumType.getName() + "." + rawValue); } else if (type.isArray()) { final Class<?> componentType = type.getComponentType(); final Object[] array; if (componentType == boolean.class) { boolean[] tmpArray = (boolean[]) rawValue; array = new Boolean[tmpArray.length]; for (int i = 0; i < array.length; i++) { array[i] = Boolean.valueOf(tmpArray[i]); }//from w ww . j a v a 2 s . c o m } else if (componentType == int.class) { int[] tmpArray = (int[]) rawValue; array = new Integer[tmpArray.length]; for (int i = 0; i < array.length; i++) { array[i] = Integer.valueOf(tmpArray[i]); } } else if (componentType == double.class) { double[] tmpArray = (double[]) rawValue; array = new Double[tmpArray.length]; for (int i = 0; i < array.length; i++) { array[i] = Double.valueOf(tmpArray[i]); } } else { array = (Object[]) rawValue; } final StringBuilder arrayValues = new StringBuilder(); arrayValues.append("[ "); for (int i = 0; i < array.length; i++) { arrayValues.append(constructValue(module, componentType, array[i]).getValue()); if (i < array.length - 1) { arrayValues.append(", "); } } arrayValues.append(" ]"); return new Value(new ArrayType(typeScriptTypeFromJavaType(module, componentType)), arrayValues.toString()); } return null; }
From source file:com.haulmont.chile.core.loader.ChileAnnotationsLoader.java
@SuppressWarnings({ "unchecked" }) protected MetadataObjectInfo<Range> loadRange(MetaProperty metaProperty, Class type, Map<String, Object> map) { Datatype datatype = (Datatype) map.get("datatype"); if (datatype != null) { return new MetadataObjectInfo<>(new DatatypeRange(datatype)); }//from www. j a va 2 s.c o m datatype = Datatypes.get(type); if (datatype != null) { MetaClass metaClass = metaProperty.getDomain(); Class javaClass = metaClass.getJavaClass(); try { String name = "get" + StringUtils.capitalize(metaProperty.getName()); Method method = javaClass.getMethod(name); Class<Enum> returnType = (Class<Enum>) method.getReturnType(); if (returnType.isEnum()) { return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(returnType))); } } catch (NoSuchMethodException e) { // ignore } return new MetadataObjectInfo<>(new DatatypeRange(datatype)); } else if (type.isEnum()) { return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(type))); } else { MetaClassImpl rangeClass = (MetaClassImpl) session.getClass(type); if (rangeClass != null) { return new MetadataObjectInfo<>(new ClassRange(rangeClass)); } else { return new MetadataObjectInfo<>(null, Collections.singletonList(new RangeInitTask(metaProperty, type, map))); } } }
From source file:org.geoserver.jdbcconfig.internal.DbMappings.java
private void addDirectPropertyTypes(final Class<? extends Info> clazz, final NamedParameterJdbcOperations template) { log("Creating property mappings for " + clazz.getName()); final ClassProperties classProperties = new ClassProperties(clazz); List<String> properties = Lists.newArrayList(classProperties.properties()); Collections.sort(properties); for (String propertyName : properties) { propertyName = fixCase(propertyName); Method getter = classProperties.getter(propertyName, null); if (getter == null) { continue; }/*w w w . ja va2 s. c o m*/ Class<?> returnType = getter.getReturnType(); if (returnType.isPrimitive() || returnType.isEnum() || INDEXABLE_TYPES.contains(returnType)) { final Class<?> componentType = returnType.isArray() ? returnType.getComponentType() : returnType; boolean isText = componentType.isEnum() || CharSequence.class.isAssignableFrom(componentType); isText &= !"id".equals(propertyName);// id is not on the full text search list of // properties addPropertyType(template, clazz, propertyName, null, false, isText); } else { log("Ignoring property " + propertyName + ":" + returnType.getSimpleName()); } } log("----------------------"); }
From source file:com.vmware.photon.controller.deployer.helpers.TestHelper.java
public static Object[][] getValidStageTransitions(@Nullable Class<? extends Enum> subStages) { if (subStages == null) { //// w w w.ja va 2 s . c o m // N.B. Tasks without defined sub-stages must allow these default stage transitions. // return new Object[][] { { TaskState.TaskStage.CREATED, TaskState.TaskStage.STARTED }, { TaskState.TaskStage.CREATED, TaskState.TaskStage.FINISHED }, { TaskState.TaskStage.CREATED, TaskState.TaskStage.FAILED }, { TaskState.TaskStage.CREATED, TaskState.TaskStage.CANCELLED }, { TaskState.TaskStage.STARTED, TaskState.TaskStage.STARTED }, { TaskState.TaskStage.STARTED, TaskState.TaskStage.FINISHED }, { TaskState.TaskStage.STARTED, TaskState.TaskStage.FAILED }, { TaskState.TaskStage.STARTED, TaskState.TaskStage.CANCELLED }, }; } if (!subStages.isEnum() || subStages.getEnumConstants().length == 0) { throw new IllegalStateException("Class " + subStages.getName() + " is not a valid enum"); } // // Add the normal task stage progression transitions. // Enum[] enumConstants = subStages.getEnumConstants(); List<Object[]> validStageTransitions = new ArrayList<>(); validStageTransitions.add( new Object[] { TaskState.TaskStage.CREATED, null, TaskState.TaskStage.STARTED, enumConstants[0] }); for (int i = 0; i < enumConstants.length - 1; i++) { validStageTransitions.add(new Object[] { TaskState.TaskStage.STARTED, enumConstants[i], TaskState.TaskStage.STARTED, enumConstants[i + 1] }); } // // N.B. The transition to the final FINISHED stage is handled below. // // Add transitions to the terminal task stages. // validStageTransitions .add(new Object[] { TaskState.TaskStage.CREATED, null, TaskState.TaskStage.FINISHED, null }); validStageTransitions .add(new Object[] { TaskState.TaskStage.CREATED, null, TaskState.TaskStage.FAILED, null }); validStageTransitions .add(new Object[] { TaskState.TaskStage.CREATED, null, TaskState.TaskStage.CANCELLED, null }); for (int i = 0; i < enumConstants.length; i++) { validStageTransitions.add(new Object[] { TaskState.TaskStage.STARTED, enumConstants[i], TaskState.TaskStage.FINISHED, null }); validStageTransitions.add(new Object[] { TaskState.TaskStage.STARTED, enumConstants[i], TaskState.TaskStage.FAILED, null }); validStageTransitions.add(new Object[] { TaskState.TaskStage.STARTED, enumConstants[i], TaskState.TaskStage.CANCELLED, null }); } Object[][] returnValue = new Object[validStageTransitions.size()][4]; for (int i = 0; i < validStageTransitions.size(); i++) { returnValue[i][0] = validStageTransitions.get(i)[0]; returnValue[i][1] = validStageTransitions.get(i)[1]; returnValue[i][2] = validStageTransitions.get(i)[2]; returnValue[i][3] = validStageTransitions.get(i)[3]; } return returnValue; }
From source file:com.feilong.core.lang.ClassUtilTest.java
/** * class info map for LOGGER.// w ww.j av a 2 s.c o m * * @param klass * the klass * @return <code>klass</code> nullempty, {@link Collections#emptyMap()}<br> */ public static Map<String, Object> getClassInfoMapForLog(Class<?> klass) { if (isNullOrEmpty(klass)) { return Collections.emptyMap(); } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.put("clz.getCanonicalName()", klass.getCanonicalName());//"com.feilong.core.date.DatePattern" map.put("clz.getName()", klass.getName());//"com.feilong.core.date.DatePattern" map.put("clz.getSimpleName()", klass.getSimpleName());//"DatePattern" map.put("clz.getComponentType()", klass.getComponentType()); // ?"". ,voidboolean?byte?char?short?int?long?float double?. map.put("clz.isPrimitive()", klass.isPrimitive()); // ?"".,. map.put("clz.isLocalClass()", klass.isLocalClass()); // ?"?".?,?,?"""??". map.put("clz.isMemberClass()", klass.isMemberClass()); //isSynthetic()?Class?"??".java??false,?true.,JVM???,java??"??"? map.put("clz.isSynthetic()", klass.isSynthetic()); map.put("clz.isArray()", klass.isArray()); map.put("clz.isAnnotation()", klass.isAnnotation()); //??true. map.put("clz.isAnonymousClass()", klass.isAnonymousClass()); map.put("clz.isEnum()", klass.isEnum()); return map; }
From source file:com.spotify.docgenerator.DocgeneratorMojo.java
private void processEnum(Sink sink, String className) { Class<?> clazz = getClassForNameIsh(sink, className); if (clazz == null) { sink.text("Was not able to find class: " + className); sink.lineBreak();// www .ja v a 2 s. c o m return; } if (clazz.isEnum()) { classHeading(sink, className); final Object[] constants = clazz.getEnumConstants(); final List<String> constantsWrapped = Lists.newArrayList(); for (Object c : constants) { constantsWrapped.add("\"" + c + "\""); } sink.text("Enumerated Type. Valid values are: "); sink.monospaced(); sink.text(Joiner.on(", ").join(constantsWrapped)); sink.monospaced_(); sink.lineBreak(); } else { sink.text("!??!?!!?" + clazz); sink.lineBreak(); } }