List of usage examples for java.lang Enum toString
public String toString()
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Sets the statement have a value as the first argument. * * <pre>/*ww w .j a v a2 s .c o m*/ * statement "value1" * statement "value2" * </pre> * * @param name * the statement {@link Enum} name. * * @param haveName * set to {@code true} if the statement have a value as the first * argument. * * @see #value(String) * @see #valueAsList(String) */ public void setAllowMultiValue(Enum<?> name, boolean haveName) { setAllowMultiValue(name.toString(), haveName); }
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Adds allowed statement keys with multi-values. * * <pre>// w w w .j a v a2 s. c o m * statement key: "value1" * statement key: "value2" * </pre> * * @param name * the statement {@link Enum} name. * * @param keys * the array with allowed {@link Enum} keys. * * @see #mapValue(String, String) */ public void addAllowedMultiKeys(Enum<?> name, Enum<?>... keys) { addAllowedMultiKeys(name.toString(), convert(keys)); }
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Returns the statement multi-value with the specified name. * <p>/*from w ww.j a v a2 s .c om*/ * * The following statements returns [URI("/foo.txt"), URI("/bar.txt")]: * * <pre> * statement key: "file:///foo.txt" * statement key: "file:///bar.txt" * </pre> * * @param name * the {@link Enum} name. * * @param key * the {@link Enum} key. * * @return the {@link List} of {@link URI} resources or {@code null}. */ public List<URI> mapMultiValueAsURI(Enum<?> name, Enum<?> key) { return mapMultiValueAsURI(name.toString(), key.toString()); }
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Returns the statement values with the specified name. * <p>/*from w w w. ja v a2s . co m*/ * * The following statement returns {@code ["value1", "value2"]} * * <pre> * statement key: "value1, value2" * </pre> * * @param name * the {@link Enum} name. * * @param key * the {@link Enum} key. * * @return the {@link List} values. */ public List<String> mapValueAsStringList(Enum<?> name, Enum<?> key) { return mapValueAsStringList(name.toString(), key.toString()); }
From source file:com.anrisoftware.sscontrol.core.groovy.statementsmap.StatementsMap.java
/** * Adds allowed statement keys.//from w w w. j a va2 s. com * * <pre> * statement key: "value1" * statement key: "value2" * </pre> * * @param name * the statement {@link Enum} name. * * @param isMulti * set to {@code true} for multi-values. * * @param keys * the array with allowed {@link Enum} keys. * * @see #mapValue(String, String) */ public void addAllowedKeys(Enum<?> name, boolean isMulti, Enum<?>... keys) { addAllowedKeys(name.toString(), isMulti, convert(keys)); }
From source file:org.gvnix.web.datatables.util.QuerydslUtils.java
/** * Return where clause expression for non-String * {@code entityPath.fieldName} by transforming it to text before check its * value./*from w w w .j a v a 2s .com*/ * <p/> * Expr: * {@code entityPath.fieldName.as(String.class) like ('%' + searchStr + '%')} * <p/> * Like operation is case insensitive. * * @param entityPath Full path to entity and associations. For example: * {@code Pet} , {@code Pet.owner} * @param fieldName Property name in the given entity path. For example: * {@code weight} in {@code Pet} entity, {@code age} in * {@code Pet.owner} entity. * @param searchStr the value to find, may be null * @param enumClass Enumeration type. Needed to enumeration values * @return BooleanExpression */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T> BooleanExpression createEnumExpression(PathBuilder<T> entityPath, String fieldName, String searchStr, Class<? extends Enum> enumClass) { if (StringUtils.isEmpty(searchStr)) { return null; } // Filter string to search than cannot be a identifier if (!StringUtils.isAlphanumeric(StringUtils.lowerCase(searchStr))) { return null; } // TODO i18n of enum name // normalize search string searchStr = StringUtils.trim(searchStr).toLowerCase(); // locate enums matching by name Set matching = new HashSet(); Enum<?> enumValue; String enumStr; for (Field enumField : enumClass.getDeclaredFields()) { if (enumField.isEnumConstant()) { enumStr = enumField.getName(); enumValue = Enum.valueOf(enumClass, enumStr); // Check enum name contains string to search if (enumStr.toLowerCase().contains(searchStr)) { // Add to matching enum matching.add(enumValue); continue; } // Check using toString enumStr = enumValue.toString(); if (enumStr.toLowerCase().contains(searchStr)) { // Add to matching enum matching.add(enumValue); } } } if (matching.isEmpty()) { return null; } // create a enum in matching condition BooleanExpression expression = entityPath.get(fieldName).in(matching); return expression; }
From source file:org.LexGrid.LexBIG.caCore.web.util.LexEVSHTTPUtils.java
/** * Generates an Element for a given result object. * * @param result - specifies the populated EVS domain object * @param recordNum - specifies the record number in the result set * * @return the element//w ww . j a v a 2s . c o m * * @throws Exception the exception */ private Element getElement(Object result, String recordNum) throws Exception { Class resultClass = result.getClass(); String className = resultClass.getName(); Element classElement = new Element("class").setAttribute("name", className).setAttribute("recordNumber", recordNum); try { while (resultClass != null) { Field[] fields = resultClass.getDeclaredFields(); for (int f = 0; f < fields.length; f++) { if (fields[f].getName().equalsIgnoreCase("serialVersionUID")) { continue; } fields[f].setAccessible(true); // String fieldClassName = fields[f].getType().getName(); String fieldName = fields[f].getName().substring(0, 1).toUpperCase() + fields[f].getName().substring(1); String fieldType = fields[f].getType().getName(); Element fieldElement = new Element("field").setAttribute("name", fieldName); Object value = null; if (fields[f].get(result) == null) { fieldElement.setText(""); //fieldElement.setText(" - "); //continue; } else if (fields[f].get(result) instanceof Enum) { Enum res = (Enum) fields[f].get(result); fieldElement.setText(res.toString()); } else if (fieldType.indexOf(".LexGrid.") > 0) { if (!Hibernate.isInitialized(fields[f].get(result))) { String criteriaBean = result.getClass().getName(); Map<String, Object> criteriaValueMap = this .getAllNonNullPrimitiveFieldsNamesAndValues(result); String criteriaValue = buildCriteriaString(criteriaValueMap); String link = servletName + "?query=" + fieldType + SystemConstant.AMPERSAND + criteriaBean + criteriaValue + SystemConstant.AMPERSAND + "roleName=" + fieldName; fieldElement.setAttribute("type", "lazyLoad", namespace) .setAttribute("href", link, namespace).setText("Get " + fieldName); } else if (fields[f].get(result) != null) { value = fields[f].get(result); fieldElement.setAttribute("type", "association"); fieldElement.addContent(getElement(value, "1")); } else { value = Class.forName(fieldType).newInstance(); fieldElement.setAttribute("type", "association"); fieldElement.addContent(getElement(value, "1")); } } else if (fieldType.indexOf("Collection") > 0 || fieldType.endsWith("HashSet") || fieldType.endsWith("ArrayList") || fieldType.endsWith("List") || fieldType.indexOf("Vector") > 0) { int counter = 1; String strValue = new String(); Collection col = ((Collection) fields[f].get(result)); //if the field is lazy-loaded - don't try to load it, just add the URL boolean isInit = Hibernate.isInitialized(col); if (!isInit) { String criteriaBean = result.getClass().getName(); String listType = getParamatarizedListType(fields[f]); Map<String, Object> criteriaValueMap = this .getAllNonNullPrimitiveFieldsNamesAndValues(result); String criteriaValue = buildCriteriaString(criteriaValueMap); String link = servletName + "?query=" + listType + SystemConstant.AMPERSAND + criteriaBean + criteriaValue + SystemConstant.AMPERSAND + "roleName=" + fieldName + this.getCodingSchemeNameAndVersionURLString(); fieldElement.setAttribute("type", "lazyLoad", namespace) .setAttribute("href", link, namespace).setText("Get " + fieldName); //fieldElement.setText(link); } else { for (Iterator it = col.iterator(); it.hasNext();) { value = it.next(); if (value != null) { if (value.getClass().getName().indexOf(".LexGrid.") > 0) { Element childElement = getElement(value, String.valueOf(counter)); fieldElement.setAttribute("type", "association"); fieldElement.addContent(childElement); counter++; } else { strValue += String.valueOf(value) + "; "; } } } } if (strValue.length() > 0) { fieldElement.setText(strValue); } } else { String strValue = " - "; if (fields[f].get(result) != null) { value = fields[f].get(result); } if (value != null) { if (fieldType.equalsIgnoreCase("java.util.Date")) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); strValue = sdf.format((Date) value); } else { strValue = String.valueOf(value); } } fieldElement.setText(strValue); } classElement.addContent(fieldElement); } resultClass = resultClass.getSuperclass(); } } catch (Exception ex) { ex.printStackTrace(); classElement.addContent(new Element("Exception", ex.getMessage())); } return classElement; }
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Takes a String (e.g. a user-entered one) and parses it into an object of the specified class * /*from ww w . j ava2s . c om*/ * @param string * @param clazz * @return Object of type <code>clazz</code> with the data from <code>string</code> */ @SuppressWarnings("unchecked") public static Object parse(String string, Class clazz) { try { // If there's a valueOf(String) method, just use that (will cover at // least String, Integer, Double, Boolean) Method valueOfMethod = null; try { valueOfMethod = clazz.getMethod("valueOf", String.class); } catch (NoSuchMethodException ex) { } if (valueOfMethod != null) { return valueOfMethod.invoke(null, string); } else if (clazz.isEnum()) { // Special-case for enum types List<Enum> constants = Arrays.asList((Enum[]) clazz.getEnumConstants()); for (Enum e : constants) { if (e.toString().equals(string)) { return e; } } throw new IllegalArgumentException(string + " is not a legal value of enum class " + clazz); } else if (String.class.equals(clazz)) { return string; } else if (Location.class.equals(clazz)) { try { Integer.parseInt(string); LocationEditor ed = new LocationEditor(); ed.setAsText(string); return ed.getValue(); } catch (NumberFormatException ex) { return Context.getLocationService().getLocation(string); } } else if (Concept.class.equals(clazz)) { ConceptEditor ed = new ConceptEditor(); ed.setAsText(string); return ed.getValue(); } else if (Program.class.equals(clazz)) { ProgramEditor ed = new ProgramEditor(); ed.setAsText(string); return ed.getValue(); } else if (ProgramWorkflowState.class.equals(clazz)) { ProgramWorkflowStateEditor ed = new ProgramWorkflowStateEditor(); ed.setAsText(string); return ed.getValue(); } else if (EncounterType.class.equals(clazz)) { EncounterTypeEditor ed = new EncounterTypeEditor(); ed.setAsText(string); return ed.getValue(); } else if (Form.class.equals(clazz)) { FormEditor ed = new FormEditor(); ed.setAsText(string); return ed.getValue(); } else if (Drug.class.equals(clazz)) { DrugEditor ed = new DrugEditor(); ed.setAsText(string); return ed.getValue(); } else if (PersonAttributeType.class.equals(clazz)) { PersonAttributeTypeEditor ed = new PersonAttributeTypeEditor(); ed.setAsText(string); return ed.getValue(); } else if (Cohort.class.equals(clazz)) { CohortEditor ed = new CohortEditor(); ed.setAsText(string); return ed.getValue(); } else if (Date.class.equals(clazz)) { // TODO: this uses the date format from the current session, // which could cause problems if the user changes it after // searching. CustomDateEditor ed = new CustomDateEditor(Context.getDateFormat(), true, 10); ed.setAsText(string); return ed.getValue(); } else if (Object.class.equals(clazz)) { // TODO: Decide whether this is a hack. Currently setting Object // arguments with a String return string; } else { throw new IllegalArgumentException("Don't know how to handle class: " + clazz); } } catch (Exception ex) { log.error("error converting \"" + string + "\" to " + clazz, ex); throw new IllegalArgumentException(ex); } }
From source file:org.cruxframework.crux.tools.schema.DefaultSchemaGenerator.java
/** * /* w w w . ja va2 s . c om*/ * @param out */ @SuppressWarnings("unchecked") private void generateTypesForEnumerations(PrintStream out) { for (String enumType : enumTypes.keySet()) { out.println("<xs:simpleType name=\"" + enumType + "\">"); out.println("<xs:restriction base=\"xs:string\">"); Class<? extends Enum<?>> enumClass = (Class<? extends Enum<?>>) enumTypes.get(enumType); Enum<?>[] enumConstants = enumClass.getEnumConstants(); for (Enum<?> enumConstant : enumConstants) { out.println("<xs:enumeration value=\"" + enumConstant.toString() + "\" />"); } out.println("</xs:restriction>"); out.println("</xs:simpleType>"); } enumTypes.clear(); }