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:aode.lx.persistence.SearchFilter.java
/** * searchParamskey?LIKES_name// ww w. j a v a 2 s .c om */ public static Map<String, SearchFilter> parse(HttpServletRequest request) { Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_"); Map<String, SearchFilter> filters = Maps.newHashMap(); for (Entry<String, Object> entry : searchParams.entrySet()) { // String key = entry.getKey(); Object value = entry.getValue(); if (StringUtils.isBlank((String) value)) { continue; } // operatorfiledAttribute String[] names = StringUtils.split(key, "_"); if (names.length != 2 && names.length != 3) { // throw new IllegalArgumentException(key + // " is not a valid search filter name"); logger.warn(key + " is not a valid search filter name"); continue; } Class<?> propertyClass = null; if (names.length == 3) { try { propertyClass = Enum.valueOf(PropertyType.class, names[2]).getValue(); logger.debug(key + ":" + propertyClass.getName()); if (propertyClass != null) { if (propertyClass.getName().equals("java.util.Date")) { String str = value.toString(); if (str.length() == 10) { if (names[0].equals("GT") || names[0].equals("GTE")) { str += " 00:00:00"; } else if (names[0].equals("LT") || names[0].equals("LTE")) { str += " 23:59:59"; } } value = dateTimeFormat.parseObject(str); } else { //value = ConvertUtils.convert(value, propertyClass); } } } catch (RuntimeException e) { logger.warn(key + " PropertyType is not a valid type!", e); } catch (ParseException e) { logger.warn(key + " PropertyType is not a valid type!", e); } } String filedName = names[1]; Operator operator = Operator.valueOf(names[0]); // searchFilter SearchFilter filter = new SearchFilter(filedName, operator, value); filters.put(key, filter); } return filters; }
From source file:org.openmrs.module.clinicalsummary.db.hibernate.type.StringEnumType.java
public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (StringUtils.isEmpty(value)) value = getDefaultValue();//from w ww . j av a 2 s . c o m String name = StringEnumReflector.getNameFromValue(enumClass, value); return rs.wasNull() ? null : Enum.valueOf(enumClass, name); }
From source file:org.openmrs.module.amrsreports.db.hibernate.type.MohStringEnumType.java
public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (StringUtils.isEmpty(value)) value = getDefaultValue();//from w w w. ja va 2 s.co m String name = MohStringEnumReflector.getNameFromValue(enumClass, value); return rs.wasNull() ? null : Enum.valueOf(enumClass, name); }
From source file:org.openmrs.util.HibernateEnumType.java
@Override public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { String name = rs.getString(names[0]); Object result = null;/* w w w . jav a 2 s . c o m*/ if (!rs.wasNull() && !StringUtils.isBlank(name)) { result = Enum.valueOf(clazz, name); } return result; }
From source file:org.rhq.enterprise.gui.admin.role.NewAction.java
/** * Create the role with the attributes specified in the given <code>RoleForm</code>. *//* w ww .j a va2 s . c om*/ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Log log = LogFactory.getLog(NewAction.class.getName()); RoleForm newForm = (RoleForm) form; ActionForward forward = checkSubmit(request, mapping, form, true); if (forward != null) { return forward; } Role role = new Role(newForm.getName()); role.setDescription(newForm.getDescription()); role.setFsystem(false); List<String> newPermissionStrings = newForm.getPermissionsStrings(); for (String permString : newPermissionStrings) { Permission p = Enum.valueOf(Permission.class, permString); role.addPermission(p); } log.trace("creating role [" + role.getName() + "] with attributes " + newForm); try { RoleManagerLocal roleManager = LookupUtil.getRoleManager(); role = roleManager.createRole(RequestUtils.getSubject(request), role); } catch (Exception ex) { log.debug("role creation failed:", ex); RequestUtils.setError(request, Constants.ERR_ROLE_CREATION); return returnFailure(request, mapping); } log.trace("new role id: [" + role.getId() + "]"); RequestUtils.setConfirmation(request, "admin.role.confirm.Create", role.getName()); return returnNew(request, mapping, Constants.ROLE_PARAM, role.getId()); }
From source file:io.wcm.devops.conga.plugins.aem.handlebars.helper.AbstractFilter.java
/** * Gets and removes type and casts it to enum. * @param map Map/*w w w. j a v a2s. c o m*/ * @param enumType Type class * @return Type value - never null */ protected final <T extends Enum<T>> T getFilterType(Map<String, Object> map, Class<T> enumType) { String typeValue = getValue(map, "type"); if (typeValue == null) { throw new IllegalArgumentException("Type expression missing."); } return Enum.valueOf(enumType, StringUtils.upperCase(typeValue)); }
From source file:fll.xml.XMLUtils.java
/** * Get the winner criteria for a particular element. *///from ww w. j a v a2 s . c o m public static WinnerType getWinnerCriteria(final Element element) { if (element.hasAttribute("winner")) { final String str = element.getAttribute("winner"); final String sortStr; if (!str.isEmpty()) { sortStr = str.toUpperCase(); } else { sortStr = "HIGH"; } return Enum.valueOf(WinnerType.class, sortStr); } else { return WinnerType.HIGH; } }
From source file:io.fns.calculator.service.LoanService.java
/** * Convenience method for creating a {@link Loan} * // ww w . j a v a 2s .co m * @param debtor * the payee and/or the loan originator * @param amount * the total loan amount * @param interest * the annual percentage interest rate (APR) * @param years * the term of the loan in (whole number) years * @param compounded * <p> * describes the manner in which the interest is compounded * </p> * <p> * Options are:<br/> * <ul> * <li>MONTHLY</li> * <li>QUARTERLY</li> * <li>SEMIANNUALLY</li> * <li>ANNUALLY</li> * </ul> * </p> * @return a {@link Loan} that encapsulates all the parameters for input to * a {@link LoanResult} */ private Loan createLoan(String debtor, BigDecimal amount, double interest, int years, String compounded) { Loan loan = new Loan(debtor, amount, interest, years, Enum.valueOf(Compounded.class, compounded)); log.info("Loan created: " + loan.toString()); return loan; }
From source file:org.openmrs.module.addresshierarchy.util.HibernateEnumType.java
@SuppressWarnings("unchecked") public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws HibernateException, SQLException { String name = resultSet.getString(names[0]); Object result = null;/*from w w w . java2 s . co m*/ if (!resultSet.wasNull() && !StringUtils.isBlank(name)) { result = Enum.valueOf(clazz, name); } return result; }
From source file:com.opengamma.web.AbstractWebResource.java
/** * Builds the sort order.//from w w w .jav a2s .c o m * <p> * This method is lenient, returning the default in case of error. * * @param <T> the sort order type * @param order the sort order, null or empty returns default * @param defaultOrder the default order, not null * @return the sort order, not null */ protected <T extends Enum<T>> T buildSortOrder(String order, T defaultOrder) { if (StringUtils.isEmpty(order)) { return defaultOrder; } order = order.toUpperCase(Locale.ENGLISH); if (order.endsWith(" ASC")) { order = StringUtils.replace(order, " ASC", "_ASC"); } else if (order.endsWith(" DESC")) { order = StringUtils.replace(order, " DESC", "_DESC"); } else if (order.endsWith("_ASC") == false && order.endsWith("_DESC") == false) { order = order + "_ASC"; } try { Class<T> cls = defaultOrder.getDeclaringClass(); return Enum.valueOf(cls, order); } catch (IllegalArgumentException ex) { return defaultOrder; } }