List of usage examples for java.lang Enum toString
public String toString()
From source file:org.trustedanalytics.atk.event.EventTest.java
private EventData eventData(Enum message) { return new EventData(Severity.INFO, null, null, null, 0, message.toString()); }
From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.options.PlotToStringBuilder.java
public PlotToStringBuilder enumString(String name, Enum<?> value) { if (value == null) { return this; }/* w w w . j a v a 2 s. c o m*/ list.add(name + ":'" + esc(value.toString()) + "'"); return this; }
From source file:org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration.java
@Override public <O> O get(String key, Class<O> datatype) { if (!config.containsKey(key)) return null; if (datatype.isArray()) { Preconditions.checkArgument(datatype.getComponentType() == String.class, "Only string arrays are supported: %s", datatype); return (O) config.getStringArray(key); } else if (Number.class.isAssignableFrom(datatype)) { // A properties file configuration returns Strings even for numeric // values small enough to fit inside Integer (e.g. 5000). In-memory // configuration impls seem to be able to store and return actual // numeric types rather than String ///* w w w .ja va 2 s .c o m*/ // We try to handle either case here Object o = config.getProperty(key); if (datatype.isInstance(o)) { return (O) o; } else { return constructFromStringArgument(datatype, o.toString()); } } else if (datatype == String.class) { return (O) config.getString(key); } else if (datatype == Boolean.class) { return (O) new Boolean(config.getBoolean(key)); } else if (datatype.isEnum()) { Enum[] constants = (Enum[]) datatype.getEnumConstants(); Preconditions.checkState(null != constants && 0 < constants.length, "Zero-length or undefined enum"); String estr = config.getProperty(key).toString(); for (Enum ec : constants) if (ec.toString().equals(estr)) return (O) ec; throw new IllegalArgumentException("No match for string \"" + estr + "\" in enum " + datatype); } else if (datatype == Object.class) { return (O) config.getProperty(key); } else if (Duration.class.isAssignableFrom(datatype)) { // This is a conceptual leak; the config layer should ideally only handle standard library types Object o = config.getProperty(key); if (Duration.class.isInstance(o)) { return (O) o; } else { String[] comps = o.toString().split("\\s"); TemporalUnit unit = null; if (comps.length == 1) { //By default, times are in milli seconds unit = ChronoUnit.MILLIS; } else if (comps.length == 2) { unit = Durations.parse(comps[1]); } else { throw new IllegalArgumentException("Cannot parse time duration from: " + o.toString()); } return (O) Duration.of(Long.valueOf(comps[0]), unit); } // Lists are deliberately not supported. List's generic parameter // is subject to erasure and can't be checked at runtime. Someone // could create a ConfigOption<List<Number>>; we would instead return // a List<String> like we always do at runtime, and it wouldn't break // until the client tried to use the contents of the list. // // We could theoretically get around this by adding a type token to // every declaration of a List-typed ConfigOption, but it's just // not worth doing since we only actually use String[] anyway. // } else if (List.class.isAssignableFrom(datatype)) { // return (O) config.getProperty(key); } else throw new IllegalArgumentException("Unsupported data type: " + datatype); }
From source file:com.springer.omelet.data.PropertyMapping.java
/*** * Compares the Enum with loaded properties file and prevents Null in Run * time//from w ww . jav a2s . com * * @param key */ @SuppressWarnings("unused") private <E extends Enum<E>> void checkEnumMapping(E key) { String lineSeprator = System.getProperty("line.separator"); if (!classEnumCheck.contains(key.getClass().getName())) { Set<String> misMatchEnum = new HashSet<String>(); for (Enum<?> value : key.getClass().getEnumConstants()) { if (propertiesValue.get(value.toString()) == null) { misMatchEnum.add("Key with text=" + value.toString() + " in class=" + key.getClass().getName() + "" + " is not present in the loaded file"); } } if (!misMatchEnum.isEmpty()) { StringBuilder sb = new StringBuilder(); Iterator<String> mmI = misMatchEnum.iterator(); while (mmI.hasNext()) { sb.append(mmI.next()); sb.append(lineSeprator); } throw new FrameworkException(sb.toString()); } classEnumCheck.add(key.getClass().getName()); } }
From source file:net.bible.service.download.XiphosRepo.java
/** reverse engineer one .conf file property *///from ww w . j av a 2 s . c o m private String getConfEntry(Map<String, Object> props, Enum<ConfigEntryType> entryType) { return getConfEntry(entryType.toString(), props.get(entryType.toString())); }
From source file:org.ahp.commons.form.AhpAbstractForm.java
/** * //from w ww . j a va 2s. c o m * @param pNavigateActionssEnum * @return */ public boolean isNextPage(Enum<?> pNavigateActionsEnum) { String lNextPage = StringUtils.trimToEmpty(this.getNextPage()); if (lNextPage.equalsIgnoreCase(pNavigateActionsEnum.toString())) { return true; } return false; }
From source file:com.github.riking.dropcontrol.ItemStringInterpreter.java
@Override public byte interpret(String s) { for (Enum<?> e : values) { if (s.equalsIgnoreCase(e.toString())) { return (byte) e.ordinal(); }//from ww w.j a v a 2 s . c o m } return 0; }
From source file:edu.ksu.cis.santos.mdcf.dml.ast.AstNode.java
private void toString(final StringBuilder sb, final Object o) { if (o instanceof AstNode) { final AstNode n = (AstNode) o; final String name = n.getClass().getSimpleName(); sb.append(Character.toLowerCase(name.charAt(0))); sb.append(name.substring(1));/*from w w w . j a v a 2 s . c o m*/ sb.append('('); final Object[] children = n.children(); final int len = children.length; for (int i = 0; i < len; i++) { toString(sb, children[i]); if (i != (len - 1)) { sb.append(", "); } } sb.append(')'); } else if (o instanceof List) { final List<?> l = (List<?>) o; sb.append("list("); final int size = l.size(); for (int i = 0; i < size; i++) { toString(sb, l.get(i)); if (i != (size - 1)) { sb.append(", "); } } sb.append(')'); } else if (o instanceof Optional) { final Optional<?> opt = (Optional<?>) o; if (opt.isPresent()) { sb.append("some("); toString(sb, opt.get()); sb.append(')'); } else { sb.append("none()"); } } else if (o instanceof String) { final String s = (String) o; sb.append('"'); sb.append(StringEscapeUtils.escapeJava(s)); sb.append('"'); } else if (o instanceof Enum) { final Enum<?> e = (Enum<?>) o; sb.append(e.getClass().getSimpleName()); sb.append('.'); sb.append(e.toString()); } else { sb.append(o); } }
From source file:org.ahp.commons.form.AhpAbstractForm.java
/** * //from w w w . j a v a 2s. c o m * @param pSubmitActionsEnum * @return */ public boolean isSubmitAction(Enum<?> pSubmitActionsEnum) { String lSubmitAction = StringUtils.trimToEmpty(this.getSubmitAction()); if (lSubmitAction.equalsIgnoreCase(pSubmitActionsEnum.toString())) { return true; } return false; }
From source file:uk.ac.ebi.metabolomes.webservices.eutils.ESummaryXMLResponseParser.java
/** * Parses the whole ESummaryResult XML object, delivering a List of ESummaryResults. * //www . j a v a 2 s.c o m * @param in the input stream through which the response the response can be read. * @return multimap with the mappings from the XML. * @throws javax.xml.stream.XMLStreamException */ public List<T> parseESummaryResult(InputStream in) throws XMLStreamException { XMLInputFactory2 xmlif = (XMLInputFactory2) XMLInputFactory2.newInstance(); xmlif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE); xmlif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); xmlif.configureForSpeed(); XMLStreamReader2 xmlr = (XMLStreamReader2) xmlif.createXMLStreamReader(in); int event; List<T> results = new ArrayList<T>(); T currentResult = getNewESummaryResult(); while (xmlr.hasNext()) { event = xmlr.next(); switch1: switch (event) { case XMLEvent.START_DOCUMENT: break; case XMLEvent.START_ELEMENT: //LOGGER.info("Start Element: "+xmlr.getLocalName()); //LOGGER.info("Attributes: "+getAttributes(xmlr)); if (xmlr.getLocalName().equalsIgnoreCase("Item")) { boolean done = false; for (Enum keyword : currentResult.getScalarKeywords()) { if (hasAttributeNameWithValue(xmlr, keyword.toString())) { //LOGGER.info("Entering addScalarForKeyword: "+keyword.toString()+" for "+xmlr.getLocalName()); currentResult.addScalarForKeyword(keyword, getFollowingCharacters(xmlr)); break switch1; } } for (Enum keyword : currentResult.getListKeywords()) { if (hasAttributeNameWithValue(xmlr, keyword.toString())) { //LOGGER.info("Entering addListForKeyword: "+keyword.toString()+" for "+xmlr.getLocalName()); currentResult.addListForKeyword(keyword, parseList(xmlr)); break switch1; } } } if (xmlr.getLocalName().equalsIgnoreCase("Id")) { for (Enum keyword : currentResult.getScalarKeywords()) { if (keyword.toString().equalsIgnoreCase("Id")) { currentResult.addScalarForKeyword(keyword, getFollowingCharacters(xmlr)); break switch1; } } } /* if (xmlr.getLocalName().equalsIgnoreCase("Item") && hasAttributeNameWithValue(xmlr, "SID")) { currentResult.setId(getFollowingCharacters(xmlr)); } else if (xmlr.getLocalName().equalsIgnoreCase("Item") && hasAttributeNameWithValue(xmlr, "SourceNameList")) { currentResult.setSourceNames(parseList(xmlr)); } else if (xmlr.getLocalName().equalsIgnoreCase("Item") && hasAttributeNameWithValue(xmlr, "SourceID")) { currentResult.addSourceID(getFollowingCharacters(xmlr)); } else if (xmlr.getLocalName().equalsIgnoreCase("Item") && hasAttributeNameWithValue(xmlr, "DBUrl")) { currentResult.setDBUrl(getFollowingCharacters(xmlr)); } else if (xmlr.getLocalName().equalsIgnoreCase("Item") && hasAttributeNameWithValue(xmlr, "SynonymList")) { currentResult.setSynonyms(parseList(xmlr)); }*/ break; case XMLEvent.END_ELEMENT: //LOGGER.info("End Element: "+xmlr.getLocalName()); if (xmlr.getLocalName().equalsIgnoreCase("DocSum")) { currentResult.wrap(); results.add(currentResult); currentResult = getNewESummaryResult(); } break; } } xmlr.closeCompletely(); return results; }