Example usage for java.lang Enum name

List of usage examples for java.lang Enum name

Introduction

In this page you can find the example usage for java.lang Enum name.

Prototype

String name

To view the source code for java.lang Enum name.

Click Source Link

Document

The name of this enum constant, as declared in the enum declaration.

Usage

From source file:gov.nih.nci.caarray.plugins.illumina.IlluminaCsvDesignHandler.java

private void validateHeader(List<String> headers, FileValidationResult result) throws IOException {
    final Set<? extends Enum> requiredHeaders = this.helper.getRequiredColumns();
    final Set<Enum> tmp = new HashSet<Enum>(requiredHeaders);
    for (final String v : headers) {
        for (final Enum h : requiredHeaders) {
            if (h.name().equalsIgnoreCase(v)) {
                tmp.remove(h);//from  w w  w  . j  a  v  a 2  s .  c o  m
            }
        }
    }
    if (!tmp.isEmpty()) {
        result.addMessage(ValidationMessage.Type.ERROR,
                "Illumina CSV file didn't contain the expected columns " + tmp.toString());
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswRecordConverter.java

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> cswAttrMap = new CaseInsensitiveMap(
            DefaultCswRecordMap.getDefaultCswRecordMap().getCswToMetacardAttributeNames());
    Object mappingObj = context.get(CswConstants.CSW_MAPPING);

    if (mappingObj instanceof Map<?, ?>) {
        CswUnmarshallHelper.removeExistingAttributes(cswAttrMap, (Map<String, String>) mappingObj);
    }/*from   w w w.j a va  2 s .  com*/

    String resourceUriMapping = (isString(context.get(Metacard.RESOURCE_URI)))
            ? (String) context.get(Metacard.RESOURCE_URI)
            : null;

    String thumbnailMapping = (isString(context.get(Metacard.THUMBNAIL)))
            ? (String) context.get(Metacard.THUMBNAIL)
            : null;

    CswAxisOrder cswAxisOrder = CswAxisOrder.LON_LAT;
    Object cswAxisOrderObject = context.get(CswConstants.AXIS_ORDER_PROPERTY);

    if (cswAxisOrderObject != null && cswAxisOrderObject.getClass().isEnum()) {
        Enum value = (Enum) cswAxisOrderObject;
        cswAxisOrder = CswAxisOrder.valueOf(value.name());
    }

    Map<String, String> namespaceMap = null;
    Object namespaceObj = context.get(CswConstants.NAMESPACE_DECLARATIONS);

    if (namespaceObj instanceof Map<?, ?>) {
        namespaceMap = (Map<String, String>) namespaceObj;
    }

    Metacard metacard = CswUnmarshallHelper.createMetacardFromCswRecord(reader, cswAttrMap, resourceUriMapping,
            thumbnailMapping, cswAxisOrder, namespaceMap);

    Object sourceIdObj = context.get(Metacard.SOURCE_ID);

    if (sourceIdObj instanceof String) {
        metacard.setSourceId((String) sourceIdObj);
    }

    return metacard;
}

From source file:org.nextframework.util.StringUtils.java

@SuppressWarnings("unchecked")
public String toStringIdStyled(Object o, boolean includeDescription) {
    if (o == null) {
        return "<null>";
    }//from  w  w  w. ja  v a2  s .co  m
    BeanDescriptor beanDescriptor = BeanDescriptorFactory.forBean(o);
    String idProperty = beanDescriptor.getIdPropertyName();
    if (idProperty == null) {
        //CODIGO INSERIDO EM 16 DE NOVEMBRO DE 2006 PARA O AJAX SUPORTAR LISTAS QUE NAO SO DE BEANS (EX LISTA DE INTEIROS)      
        if (o.getClass().isEnum()) {
            Enum e = (Enum) o;
            return e.name();
        }
        return o.toString();
    }

    Object value = beanDescriptor.getId();
    if (value == null) {
        value = "<null>";
    }

    StringBuilder stringBuilder = new StringBuilder();
    Class clazz = o.getClass();
    while (clazz.getName().contains("$$")) {
        clazz = clazz.getSuperclass();
    }
    stringBuilder.append(clazz.getName());
    stringBuilder.append("[");

    stringBuilder.append(idProperty);
    stringBuilder.append("=");
    stringBuilder.append(value);

    if (includeDescription) {
        Object description = beanDescriptor.getDescription();
        if (description != null) {
            String descriptionPropertyName = beanDescriptor.getDescriptionPropertyName();
            stringBuilder.append(";");//TODO refactor. defined in ServletRequestDataBinderNext
            stringBuilder.append(descriptionPropertyName);
            stringBuilder.append("=");
            stringBuilder.append(description);
        }
    }
    stringBuilder.append("]");
    return stringBuilder.toString();
}

From source file:com.jaceace.utils.Bundle.java

public void put(String key, Enum<?> value) {
    if (value != null) {
        try {//from   w w  w  . jav a 2s  . co  m
            data.put(key, value.name());
        } catch (JSONException e) {
        }
    }
}

From source file:org.logic2j.contrib.library.pojo.PojoLibrary.java

/**
 * @param theListener//from w w w  . j  av  a  2  s .  com
 * @param currentVars
 * @param args
 * @return Java invocation of constructor
 */
@Functor
public Object javaNew(SolutionListener theListener, UnifyContext currentVars, Object... args) {
    // More generic instantiation than the TermFactory
    final Object className = currentVars.reify(args[0]);
    ensureBindingIsNotAFreeVar(className, "javaNew", 0);
    try {
        final Class<?> aClass = Class.forName(className.toString());
        if (Enum.class.isAssignableFrom(aClass)) {
            final String enumName = currentVars.reify(args[1]).toString();

            final Enum[] enumConstants = ((Class<Enum<?>>) aClass).getEnumConstants();
            for (Enum c : enumConstants) {
                if (c.name().equals(enumName)) {
                    return c;
                }
            }
            throw new IllegalArgumentException("Enum class " + aClass + ": no such enum value " + enumName);
        } else {
            // Regular Pojo
            try {
                final int nbArgs = args.length - 1;
                if (nbArgs == 0) {
                    return aClass.newInstance();
                } else {
                    // Collect arguments and their types
                    final Object constructorArgs[] = new Object[nbArgs];
                    final Class<?> constructorClasses[] = new Class<?>[nbArgs];
                    for (int i = 1; i <= nbArgs; i++) {
                        constructorArgs[i - 1] = currentVars.reify(args[i]);
                        constructorClasses[i - 1] = constructorArgs[i - 1].getClass();
                    }
                    // Instantiation - this is very far from being robust !
                    return aClass.getConstructor(constructorClasses).newInstance(constructorArgs);
                }
            } catch (InstantiationException e) {
                throw new PrologNonSpecificError(this + " could not create instance of " + aClass + ", args="
                        + Arrays.asList(args) + " : " + e);
            } catch (IllegalAccessException e) {
                throw new PrologNonSpecificError(this + " could not create instance of " + aClass + ", args="
                        + Arrays.asList(args) + " : " + e);
            } catch (NoSuchMethodException e) {
                throw new PrologNonSpecificError(this + " could not create instance of " + aClass + ", args="
                        + Arrays.asList(args) + " : " + e);
            } catch (InvocationTargetException e) {
                throw new PrologNonSpecificError(this + " could not create instance of " + aClass
                        + " constructor failed with: " + e.getTargetException());
            }
        }
    } catch (ClassNotFoundException e) {
        throw new InvalidTermException("Cannot instantiate term of class \"" + className + "\": " + e);
    }
}

From source file:com.heliosphere.athena.base.resource.bundle.ResourceBundleManager.java

/**
 * Returns the resource bundle string of a given enumerated value for the given enumeration class. This
 * method is generally used by enumeration classes using the {@code BundleEnum} annotation.
 * <hr>/*  w w  w.j  a v  a 2s  .co m*/
 * @param eClass Class of the enumeration.
 * @param e Enumerated value.
 * @param locale {@link Locale} to use for resource string retrieval.
 * @return Resource bundle string.
 */
@SuppressWarnings("nls")
public static final String getResourceForMethodName(@NonNull final Class<? extends Enum<?>> eClass,
        final Enum<?> e, final Locale locale) {
    String key = null;
    ResourceBundle bundle;
    String methodName = null;
    String className;

    int index = 1;
    boolean found = false;
    while (!found) {
        className = Thread.currentThread().getStackTrace()[index].getClassName();
        if (className.equals(eClass.getName())) {
            methodName = Thread.currentThread().getStackTrace()[index].getMethodName();
            found = true;
        } else {
            index++;
        }
    }

    if (found) {
        for (Method method : eClass.getMethods()) {
            BundleEnum annotation = method.getAnnotation(BundleEnum.class);
            if (annotation != null && method.getName().equals(methodName)) {
                bundle = ResourceBundle.getBundle(annotation.file(), locale);
                key = annotation.path() + "." + e.name();
                return bundle.getString(key);
            }
        }
    }

    throw new ResourceBundleException(BundleAthenaBase.ResourceBundleInvalidKey, null, key, null, locale, e);
}

From source file:com.heliosphere.demeter.base.resource.bundle.ResourceBundleManager.java

/**
 * Returns the resource bundle string of a given enumerated value for the given enumeration class. This
 * method is generally used by enumeration classes using the {@code BundleEnum} annotation.
 * <hr>//from  www  . j a va  2  s  .  c  o  m
 * @param eClass Class of the enumeration.
 * @param e Enumerated value.
 * @param locale {@link Locale} to use for resource string retrieval.
 * @return Resource bundle string.
 */
@SuppressWarnings("nls")
public static final String getResourceForMethodName(@NonNull final Class<? extends Enum<?>> eClass,
        final Enum<?> e, final Locale locale) {
    String key = null;
    ResourceBundle bundle;
    String methodName = null;
    String className;

    int index = 1;
    boolean found = false;
    while (!found) {
        className = Thread.currentThread().getStackTrace()[index].getClassName();
        if (className.equals(eClass.getName())) {
            methodName = Thread.currentThread().getStackTrace()[index].getMethodName();
            found = true;
        } else {
            index++;
        }
    }

    if (found) {
        for (Method method : eClass.getMethods()) {
            BundleEnum annotation = method.getAnnotation(BundleEnum.class);
            if (annotation != null && method.getName().equals(methodName)) {
                bundle = ResourceBundle.getBundle(annotation.file(), locale);
                key = annotation.path() + "." + e.name();
                return bundle.getString(key);
            }
        }
    }

    throw new ResourceBundleException(BundleDemeterBase.ResourceBundleInvalidKey, null, key, null, locale, e);
}

From source file:org.projectforge.excel.XlsContentProvider.java

@Override
public XlsContentProvider putFormat(final Enum<?> col, final String dataFormat) {
    putFormat(col.name(), dataFormat);
    return this;
}

From source file:org.projectforge.excel.XlsContentProvider.java

@Override
public XlsContentProvider putFormat(final Enum<?> col, final CellFormat cellFormat) {
    putFormat(col.name(), cellFormat);
    return this;
}

From source file:org.bimserver.shared.json.JsonConverter.java

public Object fromJson(SClass definedType, SClass genericType, Object object)
        throws ConvertException, IOException {
    try {//from w  w  w .j a  va 2 s . com
        if (object instanceof JsonObject) {
            JsonObject jsonObject = (JsonObject) object;
            if (jsonObject.has("__type")) {
                String type = jsonObject.get("__type").getAsString();
                SClass sClass = servicesMap.getType(type);
                SBase newObject = sClass.newInstance();
                for (SField field : newObject.getSClass().getAllFields()) {
                    if (jsonObject.has(field.getName())) {
                        newObject.sSet(field, fromJson(field.getType(), field.getGenericType(),
                                jsonObject.get(field.getName())));
                    }
                }
                return newObject;
            } else {
                if (jsonObject.entrySet().size() != 0) {
                    throw new ConvertException("Missing __type field in " + jsonObject.toString());
                } else {
                    return null;
                }
            }
        } else if (object instanceof JsonArray) {
            JsonArray array = (JsonArray) object;
            if (definedType.isList()) {
                List<Object> list = new ArrayList<Object>();
                for (int i = 0; i < array.size(); i++) {
                    list.add(fromJson(definedType, genericType, array.get(i)));
                }
                return list;
            } else if (definedType.isSet()) {
                Set<Object> set = new HashSet<Object>();
                for (int i = 0; i < array.size(); i++) {
                    set.add(fromJson(definedType, genericType, array.get(i)));
                }
                return set;
            }
        } else if (object instanceof JsonNull) {
            return null;
        } else if (definedType.isByteArray()) {
            if (object instanceof JsonPrimitive) {
                JsonPrimitive jsonPrimitive = (JsonPrimitive) object;
                return Base64.decodeBase64(jsonPrimitive.getAsString().getBytes(Charsets.UTF_8));
            }
        } else if (definedType.isDataHandler()) {
            if (object instanceof JsonPrimitive) {
                JsonPrimitive jsonPrimitive = (JsonPrimitive) object;
                byte[] data = Base64.decodeBase64(jsonPrimitive.getAsString().getBytes(Charsets.UTF_8));
                return new DataHandler(new ByteArrayDataSource(null, data));
            }
        } else if (definedType.isInteger()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsInt();
            }
        } else if (definedType.isLong()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsLong();
            }
        } else if (definedType.isEnum()) {
            JsonPrimitive primitive = (JsonPrimitive) object;
            for (Object enumConstantObject : definedType.getInstanceClass().getEnumConstants()) {
                Enum<?> enumConstant = (Enum<?>) enumConstantObject;
                if (enumConstant.name().equals(primitive.getAsString())) {
                    return enumConstant;
                }
            }
        } else if (definedType.isDate()) {
            if (object instanceof JsonPrimitive) {
                return new Date(((JsonPrimitive) object).getAsLong());
            }
        } else if (definedType.isString()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsString();
            } else if (object instanceof JsonNull) {
                return null;
            }
        } else if (definedType.isBoolean()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsBoolean();
            }
        } else if (definedType.isList()) {
            if (genericType.isLong()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsLong();
                }
            } else if (genericType.isInteger()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsInt();
                }
            } else if (genericType.isString()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsString();
                }
            } else if (genericType.isDouble()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsDouble();
                }
            }
        } else if (definedType.isSet()) {
            if (genericType.isLong()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsLong();
                }
            } else if (genericType.isInteger()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsInt();
                }
            } else if (genericType.isString()) {
                if (object instanceof JsonPrimitive) {
                    return ((JsonPrimitive) object).getAsString();
                }
            }
        } else if (definedType.isDouble()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsDouble();
            }
        } else if (definedType.isFloat()) {
            if (object instanceof JsonPrimitive) {
                return ((JsonPrimitive) object).getAsFloat();
            }
        } else if (definedType.isVoid()) {
            return null;
        }
    } catch (NumberFormatException e) {
        throw new ConvertException(e);
    }
    throw new UnsupportedOperationException(object.toString());
}