List of usage examples for java.lang Enum valueOf
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
From source file:com.abssh.util.PropertyFilter.java
/** * @param filterName//from w w w. jav a 2 s. co m * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ @SuppressWarnings("unchecked") public PropertyFilter(final String filterName, final Object value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); propertyNames = propertyNameStr.split(PropertyFilter.OR_SEPARATOR); Assert.isTrue(propertyNames.length > 0, "filter??" + filterName + ",??."); // entity property. if (value != null && (value.getClass().isArray() || Collection.class.isInstance(value) || value.toString().split(",").length > 1)) { // IN ? Object[] vObjects = null; if (value.getClass().isArray()) { vObjects = (Object[]) value; } else if (Collection.class.isInstance(value)) { vObjects = ((Collection) value).toArray(); } else { vObjects = value.toString().split(","); } this.propertyValue = new Object[vObjects.length]; for (int i = 0; i < vObjects.length; i++) { propertyValue[i] = ReflectionUtils.convertValue(vObjects[i], propertyType); } } else { Object tObject = ReflectionUtils.convertValue(value, propertyType); if (tObject != null && matchType == MatchType.LE && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 Date leDate = (Date) tObject; Calendar c = GregorianCalendar.getInstance(); c.setTime(leDate); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LEN && propertyType.getName().equals("java.util.Date")) { // LED ??tObject2010-08-13 00:00:00 // ?2010-08-13 23:59:59 // Date leDate = (Date) tObject; // Calendar c = GregorianCalendar.getInstance(); // c.setTime(leDate); // tObject = c.getTime(); } else if (tObject != null && matchType == MatchType.LIKE) { tObject = ((String) tObject).replace("%", "\\%").replace("_", "\\_"); } this.propertyValue = new Object[] { tObject }; } }
From source file:com.joyveb.dbpimpl.cass.prepare.option.DefaultOption.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public boolean isCoerceable(Object value) { if (value == null || type == null) { return true; }//from www. j av a 2s . c o m // check map if (Map.class.isAssignableFrom(type)) { return Map.class.isAssignableFrom(value.getClass()); } // check collection if (Collection.class.isAssignableFrom(type)) { return Collection.class.isAssignableFrom(value.getClass()); } // check enum if (type.isEnum()) { try { String name = value instanceof Enum ? name = ((Enum) value).name() : value.toString(); Enum.valueOf((Class<? extends Enum>) type, name); return true; } catch (NullPointerException x) { return false; } catch (IllegalArgumentException x) { return false; } } // check class via String constructor try { Constructor<?> ctor = type.getConstructor(String.class); if (!ctor.isAccessible()) { ctor.setAccessible(true); } ctor.newInstance(value.toString()); return true; } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (IllegalArgumentException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } catch (SecurityException e) { } return false; }
From source file:org.rhq.enterprise.gui.ha.ListPartitionEventsUIBean.java
public PartitionEventType getPartitionEventType() { String typeName = getTypeFilter(); if (typeName != null) { return Enum.valueOf(PartitionEventType.class, typeName); }/*ww w . j ava 2 s . c om*/ return null; }
From source file:be.fedict.eid.pkira.portal.util.TypeMapper.java
public ContractType map(ContractTypeWS contractTypeWS) { if (contractTypeWS == null) return null; return Enum.valueOf(ContractType.class, contractTypeWS.name()); }
From source file:com.netflix.dynomitemanager.sidecore.AbstractConfigSource.java
@Override public <T extends Enum<T>> T get(final String key, final T defaultValue) { final String value = get(key); if (value != null) { try {/*from w w w . ja va 2 s.c o m*/ return Enum.valueOf(defaultValue.getDeclaringClass(), value); } catch (Exception e) { // ignore and return default. } } return defaultValue; }
From source file:fll.xml.XMLUtils.java
/** * Get the score type for a particular element. *//*from ww w .j ava 2 s . com*/ public static ScoreType getScoreType(final Element element) { if (element.hasAttribute("scoreType")) { final String str = element.getAttribute("scoreType"); final String sortStr; if (!str.isEmpty()) { sortStr = str.toUpperCase(); } else { sortStr = "INTEGER"; } return Enum.valueOf(ScoreType.class, sortStr); } else { return ScoreType.INTEGER; } }
From source file:org.rasea.core.configuration.ConfigurationLoader.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private Object getEnumProperty(final Object pojo, final Field field, final Object fieldValue) throws ConfigurationException { try {/* w w w. ja v a 2 s . co m*/ final Class enumClass = Class.forName(field.getType().getCanonicalName()); Object value = Enum.valueOf(enumClass, fieldValue.toString().toUpperCase()); if (value == null) { value = Enum.valueOf(enumClass, fieldValue.toString().toLowerCase()); } return value; } catch (final Exception cause) { final String message = "Failed to load enum property: " + pojo.getClass().getName() + "." + field.getName(); throw new ConfigurationException(message, cause); } }
From source file:org.nuxeo.ecm.mobile.ApplicationRedirectServiceImpl.java
@Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { ExtensionPoint ep = Enum.valueOf(ExtensionPoint.class, extensionPoint); switch (ep) { case applicationDefinition: registerApplication((ApplicationDefinitionDescriptor) contribution, contributor.getName().getName()); break;//w w w .j a va 2 s . c o m case requestHandlers: registerRequestHandler((RequestHandlerDescriptor) contribution, contributor.getName().getName()); break; default: throw new RuntimeException("error in exception handling configuration"); } }
From source file:com.handpay.ibenefit.framework.util.PropertyFilter.java
/** * // ww w .j a v a 2 s .co m * @param defalutObjectName default object name * @param filterName property name * @param value the value of the property */ public PropertyFilter(final String defalutObjectName, final String filterName, final String value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); this.filterName = filterName; matchType = Enum.valueOf(MatchType.class, matchTypeCode); propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); propertyName = StringUtils.substringAfter(filterName, "_"); if (propertyName.indexOf(".") != -1) { String[] array = propertyName.split("\\."); objectName = array[0]; propertyName = array[1]; } else { objectName = defalutObjectName; } propertyValueString = value; try { this.propertyValue = ReflectUtils.convertStringToObject(value, propertyType); //Handle Date type if (propertyTypeCode.equals("D")) { //Set to the begin of the date or end of the date if (matchType == MatchType.GE || matchType == MatchType.GT) { this.propertyValue = DateUtils.getBeginOfTheDate((Date) this.propertyValue); } else if (matchType == MatchType.LE || matchType == MatchType.LT) { this.propertyValue = DateUtils.getEndOfTheDate((Date) this.propertyValue); } } if (matchType == PropertyFilter.MatchType.IC || matchType == PropertyFilter.MatchType.NC) { String[] values = value.split(","); propertyValues = new ArrayList(values.length); for (String v : values) { propertyValues.add(ReflectUtils.convertStringToObject(v, propertyType)); } } } catch (Exception e) { } }
From source file:freedots.web.MusicXML2BrailleServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String uri = req.getParameter("uri"); if (uri != null && uri.length() > 0) { URL url = new URL(uri); String extension = "xml"; BrailleEncoding brailleEncoding = BrailleEncoding.UnicodeBraille; int width = 40, height = 25; String ext = uri.substring(uri.length() - 3); if (ext.compareTo("mxl") == 0) { extension = ext;//from w ww .j a v a 2s. c o m } String encodingParam = req.getParameter("encoding"); if (encodingParam != null && !encodingParam.isEmpty()) { try { brailleEncoding = Enum.valueOf(BrailleEncoding.class, encodingParam); } catch (IllegalArgumentException e) { LOG.info("Unknown encoding " + encodingParam + ", falling back to default"); } } String widthParam = req.getParameter("width"); if (widthParam != null && !widthParam.isEmpty()) { try { final int value = Integer.parseInt(widthParam); if (value >= MIN_COLUMNS_PER_LINE && value <= MAX_COLUMNS_PER_LINE) width = value; } catch (NumberFormatException e) { } } String heightParam = req.getParameter("height"); if (heightParam != null && !heightParam.isEmpty()) { try { final int value = Integer.parseInt(heightParam); if (value >= MIN_LINES_PER_PAGE && value <= MAX_LINES_PER_PAGE) height = value; } catch (NumberFormatException e) { } } Score score = parseMusicXML(url.openStream(), extension); if (score != null) writeResult(score, width, height, Method.SectionBySection, brailleEncoding, resp); else resp.sendError(500); } else { LOG.info("Bad URI error"); resp.sendError(500); } }