List of usage examples for java.lang Enum name
String name
To view the source code for java.lang Enum name.
Click Source Link
From source file:org.batoo.jpa.jdbc.AbstractColumn.java
/** * {@inheritDoc}/*from w w w . ja va 2 s .c om*/ * */ @Override public Object convertValue(Connection connection, final Object value) { if (value == null) { return null; } if (this.temporalType != null) { switch (this.temporalType) { case DATE: if (value instanceof java.sql.Date) { return value; } if (value instanceof Date) { return new java.sql.Date(((Date) value).getTime()); } return new java.sql.Date(((Calendar) value).getTimeInMillis()); case TIME: if (value instanceof java.sql.Time) { return value; } if (value instanceof Date) { return new java.sql.Time(((Date) value).getTime()); } return new java.sql.Time(((Calendar) value).getTimeInMillis()); case TIMESTAMP: if (value instanceof java.sql.Timestamp) { return value; } if (value instanceof Date) { return new java.sql.Timestamp(((Date) value).getTime()); } return new java.sql.Timestamp(((Calendar) value).getTimeInMillis()); } } if (this.numberType != null) { return ReflectHelper.convertNumber((Number) value, this.numberType); } if (this.enumType != null) { final Enum<?> enumValue = (Enum<?>) value; if (this.enumType == EnumType.ORDINAL) { return enumValue.ordinal(); } return enumValue.name(); } if (this.lob) { try { if (this.javaType == String.class) { return new SerialClob(((String) value).toCharArray()); } else if (this.javaType == char[].class) { return new SerialClob((char[]) value); } else if (this.javaType == byte[].class) { return new SerialBlob((byte[]) value); } else { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(os); try { oos.writeObject(value); } finally { oos.close(); } return new SerialBlob(os.toByteArray()); } } catch (final Exception e) { throw new PersistenceException("Cannot set parameter", e); } } else { return value; } }
From source file:org.gbif.common.search.builder.SearchResponseBuilder.java
/** * Gets the facet value of Enum type parameter. * If the Enum is either a Country or a Language, its iso2Letter code it's used. *//*from w w w .jav a 2 s . c o m*/ private String getFacetEnumValue(P facetParam, String value) { // the expected enum type for the value if it is an enum - otherwise null final Enum<?>[] enumValues = ((Class<? extends Enum<?>>) facetParam.type()).getEnumConstants(); // if we find integers these are ordinals, translate back to enum names final Integer intValue = Ints.tryParse(value); if (intValue != null) { final Enum<?> enumValue = enumValues[intValue]; if (Country.class.equals(facetParam.type())) { return ((Country) enumValue).getIso2LetterCode(); } else if (Language.class.equals(facetParam.type())) { return ((Language) enumValue).getIso2LetterCode(); } else { return enumValue.name(); } } else { if (Country.class.equals(facetParam.type())) { return Country.fromIsoCode(value).getIso2LetterCode(); } else if (Language.class.equals(facetParam.type())) { return Language.fromIsoCode(value).getIso2LetterCode(); } else { return VocabularyUtils.lookupEnum(value, ((Class<? extends Enum<?>>) facetParam.type())).name(); } } }
From source file:org.finra.herd.swaggergen.RestControllerProcessor.java
/** * Converts the given Java parameter type into a Swagger param type and sets it into the given Swagger param. * * @param parameterSource the parameter source. * @param swaggerParam the Swagger parameter. *///from w w w . j a va 2 s.co m private void setParameterType(ParameterSource<JavaClassSource> parameterSource, SerializableParameter swaggerParam) throws MojoExecutionException { try { String typeName = parameterSource.getType().getQualifiedName(); if (String.class.getName().equals(typeName)) { swaggerParam.setType("string"); } else if (Integer.class.getName().equals(typeName) || Long.class.getName().equals(typeName)) { swaggerParam.setType("integer"); } else if (Boolean.class.getName().equals(typeName)) { swaggerParam.setType("boolean"); } else { // See if the type is an enum. Enum<?>[] enumValues = (Enum<?>[]) Class.forName(parameterSource.getType().getQualifiedName()) .getEnumConstants(); if (enumValues != null) { swaggerParam.setType("string"); swaggerParam.setEnum(new ArrayList<>()); for (Enum<?> enumEntry : enumValues) { swaggerParam.getEnum().add(enumEntry.name()); } } else { // Assume "string" for all other types since everything is ultimately a string. swaggerParam.setType("string"); } } log.debug("Parameter \"" + parameterSource.getName() + "\" is a type \"" + swaggerParam.getType() + "\"."); } catch (ClassNotFoundException e) { throw new MojoExecutionException("Unable to instantiate class \"" + parameterSource.getType().getQualifiedName() + "\". Reason: " + e.getMessage(), e); } }
From source file:org.structr.core.graph.IndexNodeCommand.java
private void indexProperty(final AbstractNode node, final PropertyKey key) { for (Enum index : (NodeIndex[]) arguments.get("indices")) { Set<PropertyKey> properties = EntityContext.getSearchableProperties(node.getClass(), index.name()); if ((properties != null) && properties.contains(key)) { indexProperty(node, key, index.name()); }/*from www . jav a 2s .c o m*/ } }
From source file:org.structr.core.graph.IndexNodeCommand.java
private void addProperty(final AbstractNode node, final PropertyKey key) { for (Enum index : (NodeIndex[]) arguments.get("indices")) { Set<PropertyKey> properties = EntityContext.getSearchableProperties(node.getClass(), index.name()); if ((properties != null) && properties.contains(key)) { addProperty(node, key, index.name()); }/*from w w w .j av a 2 s .co m*/ } }
From source file:org.structr.core.graph.IndexNodeCommand.java
private void removeProperty(final AbstractNode node, final PropertyKey key) { for (Enum index : (NodeIndex[]) arguments.get("indices")) { Set<PropertyKey> properties = EntityContext.getSearchableProperties(node.getClass(), index.name()); if ((properties != null) && properties.contains(key)) { removeProperty(node, key, index.name()); }//from w w w . j a v a 2 s. c om } }
From source file:us.ihmc.idl.serializers.extra.JacksonInterchangeSerializer.java
public void write_type_c(String name, Enum<?> val) { if (val == null) { node.putNull(name);/* w ww. j a v a2 s .com*/ } else { node.put(name, val.name()); } }
From source file:icom.jpa.bdk.dao.EmailMessageDAO.java
private void updateNewOrOldObjectState(ManagedIdentifiableProxy obj, DAOContext context) { MessageUpdater messageUpdater = (MessageUpdater) context.getUpdater(); Persistent pojoUnifiedMessage = obj.getPojoIdentifiable(); /*/* ww w . j a v a 2 s. com*/ if (isChanged(obj, UnifiedMessageInfo.Attributes.subject.name())) { String subject = (String) getAttributeValue(pojoUnifiedMessage, UnifiedMessageInfo.Attributes.subject.name()); messageUpdater.setName(subject); } */ if (messageUpdater instanceof EmailMessageUpdater) { EmailMessageUpdater emailMessageUpdater = (EmailMessageUpdater) messageUpdater; if (isChanged(obj, UnifiedMessageInfo.Attributes.flags.name())) { EnumSet<MessageFlag> bdkMessageFlags = EnumSet.noneOf(MessageFlag.class); EnumSet<? extends Enum<?>> pojoFlags = getEnumSet(pojoUnifiedMessage, UnifiedMessageInfo.Attributes.flags.name()); if (pojoFlags != null) { for (Enum<?> pojoFlag : pojoFlags) { String pojoFlagName = pojoFlag.name(); String bdkFlagName = pojoToBdkFlagNameMap.get(pojoFlagName); bdkMessageFlags.add(MessageFlag.valueOf(bdkFlagName)); } } emailMessageUpdater.getFlags().addAll(bdkMessageFlags); } // emailMessageUpdater.getContentTrimmer() TODO } else if (messageUpdater instanceof EmailDraftUpdater) { EmailDraftUpdater emailDraftUpdater = (EmailDraftUpdater) messageUpdater; emailDraftUpdater.setType(EmailMessageType.EMAIL); if (isChanged(obj, UnifiedMessageInfo.Attributes.flags.name())) { EnumSet<MessageFlag> bdkMessageFlags = EnumSet.noneOf(MessageFlag.class); EnumSet<? extends Enum<?>> pojoFlags = getEnumSet(pojoUnifiedMessage, UnifiedMessageInfo.Attributes.flags.name()); if (pojoFlags != null) { for (Enum<?> pojoFlag : pojoFlags) { String pojoFlagName = pojoFlag.name(); String bdkFlagName = pojoToBdkFlagNameMap.get(pojoFlagName); bdkMessageFlags.add(MessageFlag.valueOf(bdkFlagName)); } emailDraftUpdater.getFlags().addAll(bdkMessageFlags); } } if (isChanged(obj, UnifiedMessageInfo.Attributes.channel.name())) { String pojoChannelName = EmailMessageDAO.getEnumName(pojoUnifiedMessage, UnifiedMessageInfo.Attributes.channel.name()); if (pojoChannelName != null) { String bdkChannelName = EmailMessageDAO.pojoToBdkChannelTypeNameMap.get(pojoChannelName); emailDraftUpdater.setType(EmailMessageType.valueOf(bdkChannelName)); } else { emailDraftUpdater.setType(EmailMessageType.EMAIL); } } EmailMessageContentUpdater emailMessageContentUpdater = emailDraftUpdater.getContentUpdater(); DAOContext childContext = new DAOContext(emailMessageContentUpdater); updateEmailMessageContentState(obj, childContext); } }
From source file:org.rhq.enterprise.gui.legacy.taglib.ConstantsTag.java
public int doEndTag() throws JspException { try {// ww w . j a v a2 s .c o m JspWriter out = pageContext.getOut(); if (className == null) { className = pageContext.getServletContext().getInitParameter(constantsClassNameParam); } if (validate(out)) { // we're misconfigured. getting this far // is a matter of what our failure mode is; // if we haven't thrown an Error, carry on log.debug("constants tag misconfigured"); return EVAL_PAGE; } Map<String, String> fieldMap; if (constants.containsKey(className)) { // we cache the result of the constant's class // reflection field walk as a map fieldMap = (Map<String, String>) constants.get(className); } else { fieldMap = new HashMap<String, String>(); Class typeClass = Class.forName(className); if (typeClass.isEnum()) { for (Object enumConstantObj : typeClass.getEnumConstants()) { Enum enumConstant = (Enum) enumConstantObj; // Set name *and* value to enum name (e.g. name of ResourceCategory.PLATFORM = "PLATFORM") // NOTE: We do not set the value to enumConstant.ordinal(), because there is no way to // convert the ordinal value back to an Enum (i.e. no Enum.valueOf(int ordinal) method). fieldMap.put(enumConstant.name(), enumConstant.name()); } } else { Object instance = typeClass.newInstance(); Field[] fields = typeClass.getFields(); for (Field field : fields) { // string comparisons of class names should be cheaper // than reflective Class comparisons, the asumption here // is that most constants are Strings, ints and booleans // but a minimal effort is made to accomadate all types // and represent them as String's for our tag's output String fieldType = field.getType().getName(); String strVal; if (fieldType.equals("java.lang.String")) { strVal = (String) field.get(instance); } else if (fieldType.equals("int")) { strVal = Integer.toString(field.getInt(instance)); } else if (fieldType.equals("boolean")) { strVal = Boolean.toString(field.getBoolean(instance)); } else if (fieldType.equals("char")) { strVal = Character.toString(field.getChar(instance)); } else if (fieldType.equals("double")) { strVal = Double.toString(field.getDouble(instance)); } else if (fieldType.equals("float")) { strVal = Float.toString(field.getFloat(instance)); } else if (fieldType.equals("long")) { strVal = Long.toString(field.getLong(instance)); } else if (fieldType.equals("short")) { strVal = Short.toString(field.getShort(instance)); } else if (fieldType.equals("byte")) { strVal = Byte.toString(field.getByte(instance)); } else { strVal = field.get(instance).toString(); } fieldMap.put(field.getName(), strVal); } } // cache the result constants.put(className, fieldMap); } if ((symbol != null) && !fieldMap.containsKey(symbol)) { // tell the developer that he's being a dummy and what // might be done to remedy the situation // TODO: what happens if the constants change? // do we need to throw a JspException, here? - mtk String err1 = symbol + " was not found in " + className + "\n"; String err2 = err1 + "use <constants:diag classname=\"" + className + "\"/>\n" + "to figure out what you're looking for"; log.error(err2); die(out, err1); } if (varSpecified) { doSet(fieldMap); } else { doOutput(fieldMap, out); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug("doEndTag() failed: ", e); throw new JspException("Could not access constants tag", e); } return EVAL_PAGE; }
From source file:org.structr.core.graph.IndexNodeCommand.java
private void indexNode(final AbstractNode node) { try {/*from w ww . ja v a 2 s. c o m*/ String uuid = node.getProperty(AbstractNode.uuid); // Don't touch non-structr node if (uuid == null) { return; } for (Enum index : (NodeIndex[]) arguments.get("indices")) { Set<PropertyKey> properties = EntityContext.getSearchableProperties(node.getClass(), index.name()); for (PropertyKey key : properties) { indexProperty(node, key, index.name()); } } Node dbNode = node.getNode(); if ((dbNode.hasProperty(Location.latitude.dbName())) && (dbNode.hasProperty(Location.longitude.dbName()))) { LayerNodeIndex layerIndex = (LayerNodeIndex) indices.get(NodeIndex.layer.name()); try { synchronized (layerIndex) { layerIndex.add(dbNode, "", ""); } // If an exception is thrown here, the index was deleted // and has to be recreated. } catch (NotFoundException nfe) { logger.log(Level.SEVERE, "Could not add node to layer index because the db could not find the node", nfe); } catch (Throwable t) { logger.log(Level.SEVERE, "Could add node to layer index", t); // final Map<String, String> config = new HashMap<String, String>(); // // config.put(LayerNodeIndex.LAT_PROPERTY_KEY, Location.Key.latitude.name()); // config.put(LayerNodeIndex.LON_PROPERTY_KEY, Location.Key.longitude.name()); // config.put(SpatialIndexProvider.GEOMETRY_TYPE, LayerNodeIndex.POINT_PARAMETER); // // layerIndex = new LayerNodeIndex("layerIndex", graphDb, config); // logger.log(Level.WARNING, "Created layer node index due to exception", e); // // indices.put(NodeIndex.layer.name(), layerIndex); // // // try again // layerIndex.add(dbNode, "", ""); } } } catch (Throwable t) { t.printStackTrace(); logger.log(Level.WARNING, "Unable to index node {0}: {1}", new Object[] { node.getNode().getId(), t.getMessage() }); } }