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:it.unimi.di.big.mg4j.document.PropertyBasedDocumentFactory.java

/** A utility method checking whether the downcased name of an {@link Enum} is equal to a given string.
 * //from  w  ww . ja  va  2  s.  co m
 *  <p>This class uses an {@link Enum} ({@link MetadataKeys}) to store valid property keys. We follow
 *  both the uppercase naming convention for enums and the lowercase naming convention for properties,
 *  and this method encapsulates the method calls that necessary to correctly handle key parsing. 
 * 
 * @param enumKey a key expressed as an {@link Enum}.
 * @param key a key expressed as a string.
 * @return true if <code>key</code> is equal to the downcased {@linkplain Enum#name() name} of <code>enumKey</code>.
 */
public static boolean sameKey(final Enum<?> enumKey, final String key) {
    return key.equals(enumKey.name().toLowerCase());
}

From source file:com.medallia.spider.api.DynamicInputImpl.java

private static Object parseSingleValue(Class<?> rt, String v, AnnotatedElement anno,
        Map<Class<?>, InputArgParser<?>> inputArgParsers) {
    if (rt.isEnum()) {
        String vlow = v.toLowerCase();
        for (Enum e : rt.asSubclass(Enum.class).getEnumConstants()) {
            if (e.name().toLowerCase().equals(vlow))
                return e;
        }//from ww w.j  a  v a2  s  .  c om
        throw new AssertionError("Enum constant not found: " + v);
    } else if (rt == Integer.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Integer.valueOf(v) : null;
    } else if (rt == Integer.TYPE) {
        // primitive int must have a value
        return Integer.valueOf(v);
    } else if (rt == Long.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Long.valueOf(v) : null;
    } else if (rt == Long.TYPE) {
        // primitive long must have a value
        return Long.valueOf(v);
    } else if (rt == Double.class) {
        // map blank strings to null
        return Strings.hasContent(v) ? Double.valueOf(v) : null;
    } else if (rt == Double.TYPE) {
        // primitive double must have a value
        return Double.valueOf(v);
    } else if (rt == String.class) {
        return v;
    } else if (rt.isArray()) {
        Input.List ann = anno.getAnnotation(Input.List.class);
        if (ann == null)
            throw new AssertionError("Array type but no annotation (see " + Input.class + "): " + anno);
        String separator = ann.separator();
        String[] strVals = v.split(separator, -1);
        Class<?> arrayType = rt.getComponentType();
        Object a = Array.newInstance(arrayType, strVals.length);
        for (int i = 0; i < strVals.length; i++) {
            Array.set(a, i, parseSingleValue(arrayType, strVals[i], anno, inputArgParsers));
        }
        return a;
    } else if (inputArgParsers != null) {
        InputArgParser<?> argParser = inputArgParsers.get(rt);
        if (argParser != null) {
            return argParser.parse(v);
        }
    }
    throw new AssertionError("Unknown return type " + rt + " (val: " + v + ")");
}

From source file:com.streamsets.datacollector.definition.StageDefinitionExtractor.java

private static void addGroupsToList(Class<?> klass, Set<String> set) {
    ConfigGroups groups = klass.getAnnotation(ConfigGroups.class);
    if (groups != null) {
        Class<? extends Enum> groupKlass = (Class<? extends Enum>) groups.value();
        for (Enum e : groupKlass.getEnumConstants()) {
            set.add(e.name());
        }//from   w ww . j  ava 2s .c o m
    }
}

From source file:com.citytechinc.cq.component.touchuidialog.util.TouchUIDialogUtil.java

protected static final com.citytechinc.cq.component.touchuidialog.widget.selection.options.Option buildSelectionOptionForEnum(
        Enum<?> optionEnum, ClassPool classPool, String fieldName)
        throws SecurityException, NoSuchFieldException, NotFoundException, ClassNotFoundException {

    String text = optionEnum.name();
    String value = optionEnum.name();

    CtClass annotatedEnumClass = classPool.getCtClass(optionEnum.getDeclaringClass().getName());
    CtMember annotatedEnumField = annotatedEnumClass.getField(optionEnum.name());
    com.citytechinc.cq.component.annotations.Option optionAnnotation = (com.citytechinc.cq.component.annotations.Option) annotatedEnumField
            .getAnnotation(com.citytechinc.cq.component.annotations.Option.class);

    OptionParameters parameters = new OptionParameters();
    if (optionAnnotation != null) {
        if (StringUtils.isNotEmpty(optionAnnotation.text())) {
            text = optionAnnotation.text();
        }/*from w  ww  . j  a  v a  2  s . c o  m*/
        if (StringUtils.isNotEmpty(optionAnnotation.value())) {
            value = optionAnnotation.value();
        }
        parameters.setSelected(optionAnnotation.selected());
    }
    parameters.setFieldName(fieldName);
    parameters.setText(text);
    parameters.setValue(value);
    return new com.citytechinc.cq.component.touchuidialog.widget.selection.options.Option(parameters);

}

From source file:nebula.plugin.metrics.dispatcher.AbstractMetricsDispatcher.java

/**
 * Register Jackson module that maps enums as lowercase. Per http://stackoverflow.com/a/24173645.
 *///from   www. jav a2  s . com
@SuppressWarnings("rawtypes")
private static void registerEnumModule(ObjectMapper mapper) {
    SimpleModule module = new SimpleModule();
    module.setDeserializerModifier(new BeanDeserializerModifier() {
        @Override
        public JsonDeserializer<Enum> modifyEnumDeserializer(DeserializationConfig config, final JavaType type,
                BeanDescription beanDesc, final JsonDeserializer<?> deserializer) {
            return new JsonDeserializer<Enum>() {
                @Override
                public Enum deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
                    @SuppressWarnings("unchecked")
                    Class<? extends Enum> rawClass = (Class<Enum<?>>) type.getRawClass();
                    return Enum.valueOf(rawClass, jp.getValueAsString().toUpperCase());
                }
            };
        }
    });
    module.addSerializer(Enum.class, new StdSerializer<Enum>(Enum.class) {
        @Override
        public void serialize(Enum value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.name().toLowerCase());
        }
    });
    mapper.registerModule(module);
}

From source file:com.github.dozermapper.protobuf.util.ProtoUtils.java

/**
 * Unwrap {@link Descriptors.EnumValueDescriptor} or a {@link Collection} to a raw {@link Enum}
 * If the value is neither {@link Descriptors.EnumValueDescriptor} or a {@link Collection}, the value is returned.
 *
 * @param value         {@link Descriptors.EnumValueDescriptor} or a {@link Collection}
 * @param beanContainer {@link BeanContainer} instance
 * @return {@link Enum} if value is {@link Descriptors.EnumValueDescriptor}, else a {@link Collection} of {@link Enum}
 *///from   ww w  .j a v a2 s  .c  o m
@SuppressWarnings("unchecked")
public static Object unwrapEnums(Object value, BeanContainer beanContainer) {
    if (value instanceof Descriptors.EnumValueDescriptor) {
        Descriptors.EnumValueDescriptor descriptor = (Descriptors.EnumValueDescriptor) value;
        Class<? extends Enum> enumClass = getEnumClassByEnumDescriptor(descriptor.getType(), beanContainer);

        for (Enum enumValue : enumClass.getEnumConstants()) {
            if (((Descriptors.EnumValueDescriptor) value).getName().equals(enumValue.name())) {
                return enumValue;
            }
        }

        return null;
    }

    if (value instanceof Collection) {
        Collection valueCollection = (Collection) value;
        List modifiedList = new ArrayList(valueCollection.size());

        for (Object element : valueCollection) {
            modifiedList.add(unwrapEnums(element, beanContainer));
        }

        return modifiedList;
    }

    return value;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.common.vbb.impl.util.VisualVariableHelper.java

private static EClassifier getEEnum(EPackage vvEPackage, Class<? extends Enum<?>> enumClass) {
    if (vvEPackage.getEClassifier(enumClass.getSimpleName()) == null) {
        EEnum result = EcoreFactory.eINSTANCE.createEEnum();
        result.setName(enumClass.getSimpleName());
        result.setInstanceClass(enumClass);
        for (Enum<?> enumValue : enumClass.getEnumConstants()) {
            EEnumLiteral lit = EcoreFactory.eINSTANCE.createEEnumLiteral();
            lit.setValue(enumValue.ordinal());
            lit.setName(enumValue.name());
            result.getELiterals().add(lit);
        }/*www .j  a v a 2s.  c  o m*/
        vvEPackage.getEClassifiers().add(result);
    }
    return vvEPackage.getEClassifier(enumClass.getSimpleName());
}

From source file:fr.zcraft.zlib.components.rawtext.RawTextPart.java

static private JSONObject actionToJSON(Enum action, Object value) {
    JSONObject obj = new JSONObject();
    obj.put("action", action.name().toLowerCase());
    obj.put("value", value);
    return obj;//from  w ww .jav a  2s.c o m
}

From source file:org.apache.axis2.jaxws.utility.XMLRootElementUtil.java

/**
 * @param clazz/*  www  .j  a  v  a2  s . c om*/
 * @return namespace of root element qname or null if this is object does not represent a root element
 */
public static String getEnumValue(Enum myEnum) {
    Field f;
    String value;
    try {
        f = myEnum.getClass().getField(myEnum.name());

        f.setAccessible(true);

        XmlEnumValue xev = (XmlEnumValue) getAnnotation(f, XmlEnumValue.class);
        if (xev == null) {
            value = f.getName();
        } else {
            value = xev.value();
        }
    } catch (SecurityException e) {
        value = null;
    } catch (NoSuchFieldException e) {
        value = null;
    }

    return value;
}

From source file:org.waarp.common.json.JsonHandler.java

/**
 * /*from   w w  w  .  j  ava  2s. c o m*/
 * @param node
 * @param field
 * @param value
 */
public final static void setValue(ObjectNode node, Enum<?> field, int value) {
    node.put(field.name(), value);
}