List of usage examples for java.util Objects toString
public static String toString(Object o, String nullDefault)
From source file:info.bunji.mongodb.synces.SyncOperation.java
/** **********************************// w ww . ja v a 2s . co m * @param op operartion type * @param destDbName * @param collection target collection * @param doc sync document * @param ts oplog timestamp ********************************** */ public SyncOperation(Operation op, String destDbName, String collection, Document doc, Object ts) { this.op = op; this.destDbName = destDbName; this.collection = collection; this.doc = doc; //this.id = doc != null ? doc.remove("_id").toString() : null; this.id = Objects.toString(doc.remove("_id"), null); if (this.id == null) { op = Operation.UNKNOWN; } this.ts = (BsonTimestamp) ts; }
From source file:com.norconex.collector.core.filter.impl.RegexMetadataFilter.java
@Override public boolean acceptMetadata(String reference, Properties metadata) { if (StringUtils.isBlank(regex)) { return getOnMatch() == OnMatch.INCLUDE; }//from w ww .ja v a2s . c o m Collection<String> values = metadata.getStrings(field); for (Object value : values) { String strVal = Objects.toString(value, StringUtils.EMPTY); if (pattern.matcher(strVal).matches()) { return getOnMatch() == OnMatch.INCLUDE; } } return getOnMatch() == OnMatch.EXCLUDE; }
From source file:org.flowable.content.engine.impl.AbstractNativeQuery.java
public Object execute(CommandContext commandContext) { if (resultType == ResultType.LIST) { return executeList(commandContext, getParameterMap(), 0, Integer.MAX_VALUE); } else if (resultType == ResultType.LIST_PAGE) { Map<String, Object> parameterMap = getParameterMap(); parameterMap.put("resultType", "LIST_PAGE"); parameterMap.put("firstResult", firstResult); parameterMap.put("maxResults", maxResults); if (StringUtils.isNotBlank(Objects.toString(parameterMap.get("orderBy"), ""))) { parameterMap.put("orderByColumns", "RES." + parameterMap.get("orderBy")); } else {//from www. j a v a 2 s. com parameterMap.put("orderByColumns", "RES.ID_ asc"); } int firstRow = firstResult + 1; parameterMap.put("firstRow", firstRow); int lastRow = 0; if (maxResults == Integer.MAX_VALUE) { lastRow = maxResults; } else { lastRow = firstResult + maxResults + 1; } parameterMap.put("lastRow", lastRow); return executeList(commandContext, parameterMap, firstResult, maxResults); } else if (resultType == ResultType.SINGLE_RESULT) { return executeSingleResult(commandContext); } else { return executeCount(commandContext, getParameterMap()); } }
From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.options.PlotToStringBuilder.java
public PlotToStringBuilder enumArray(String name, Enum<?>[] array) { if (array == null || array.length == 0) { return this; }/* ww w . j av a 2 s. c om*/ StringBuilder b = new StringBuilder("["); for (Enum<?> en : array) { if (b.length() > 2) { b.append(", "); } b.append("'"); b.append(esc(Objects.toString(en, null))); b.append("'"); } b.append("]"); list.add(name + ":" + b.toString()); return this; }
From source file:alluxio.cli.validation.ClusterConfConsistencyValidationTask.java
@Override public TaskResult validate(Map<String, String> optionMap) throws InterruptedException { Set<String> masters = new HashSet<>(Utils.readNodeList("masters")); Set<String> workers = new HashSet<>(Utils.readNodeList("workers")); Set<String> nodes = Sets.union(masters, workers); Map<String, Properties> allProperties = new HashMap<>(); Set<String> propertyNames = new HashSet<>(); if (masters.isEmpty()) { System.err.println("No master nodes specified in conf/masters file"); return TaskResult.SKIPPED; }/*from w w w. j a v a2 s . c om*/ if (workers.isEmpty()) { System.err.println("No worker nodes specified in conf/workers file"); return TaskResult.SKIPPED; } TaskResult result = TaskResult.OK; for (String node : nodes) { Properties props = getNodeConf(node); if (props == null) { result = TaskResult.FAILED; continue; } allProperties.put(node, props); propertyNames.addAll(props.stringPropertyNames()); } for (String propertyName : propertyNames) { PropertyKey propertyKey = PropertyKey.fromString(propertyName); PropertyKey.ConsistencyCheckLevel level = propertyKey.getConsistencyLevel(); if (level == PropertyKey.ConsistencyCheckLevel.IGNORE) { continue; } PropertyKey.Scope scope = propertyKey.getScope(); Set<String> targetNodes = ImmutableSet.of(); if (scope.contains(PropertyKey.Scope.MASTER)) { targetNodes = masters; } if (scope.contains(PropertyKey.Scope.WORKER)) { targetNodes = Sets.union(targetNodes, workers); } if (targetNodes.size() < 2) { continue; } String baseNode = null; String baseValue = null; boolean isConsistent = true; String errLabel; TaskResult errLevel; switch (level) { case ENFORCE: errLabel = "Error"; errLevel = TaskResult.FAILED; break; case WARN: errLabel = "Warning"; errLevel = TaskResult.WARNING; break; default: System.err.format("Error: Consistency check level \"%s\" for property \"%s\" is invalid.%n", level.name(), propertyName); result = TaskResult.FAILED; continue; } for (String remoteNode : targetNodes) { if (baseNode == null) { baseNode = remoteNode; Properties baselineProps = allProperties.get(baseNode); baseValue = baselineProps.getProperty(propertyName); continue; } String remoteValue = allProperties.get(remoteNode).getProperty(propertyName); if (!StringUtils.equals(remoteValue, baseValue)) { System.err.format("%s: Property \"%s\" is inconsistent between node %s and %s.%n", errLabel, propertyName, baseNode, remoteNode); System.err.format(" %s: %s%n %s: %s%n", baseNode, Objects.toString(baseValue, "not set"), remoteNode, Objects.toString(remoteValue, "not set")); isConsistent = false; } } if (!isConsistent) { result = result == TaskResult.FAILED ? TaskResult.FAILED : errLevel; } } return result; }
From source file:org.openhab.binding.myq.internal.MyqBinding.java
/** * Called by the SCR when the configuration of a binding has been changed * through the ConfigAdmin service.//from w w w . j a v a2 s.c o m * * @param configuration * Updated configuration properties */ public void modified(final Map<String, Object> configuration) { String refreshIntervalString = Objects.toString(configuration.get("refresh"), null); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } String quickrefreshIntervalString = Objects.toString(configuration.get("quickrefresh"), null); if (StringUtils.isNotBlank(quickrefreshIntervalString)) { rapidRefresh = Integer.parseInt(quickrefreshIntervalString); } // update the internal configuration accordingly String usernameString = Objects.toString(configuration.get("username"), null); String passwordString = Objects.toString(configuration.get("password"), null); String appId = Objects.toString(configuration.get("appId"), null); if (StringUtils.isBlank(appId)) { appId = MyqData.DEFAULT_APP_ID; } int timeout = MyqData.DEFAUALT_TIMEOUT; String timeoutString = Objects.toString(configuration.get("timeout"), null); if (StringUtils.isNotBlank(timeoutString)) { timeout = Integer.parseInt(timeoutString); } String craftmanString = Objects.toString(configuration.get("craftman"), null); if (StringUtils.isNotBlank(craftmanString)) { useCraftman = Boolean.parseBoolean(craftmanString); } // reinitialize connection object if username and password is changed if (StringUtils.isNotBlank(usernameString) && StringUtils.isNotBlank(passwordString)) { myqOnlineData = new MyqData(usernameString, passwordString, appId, timeout, useCraftman); invalidCredentials = false; schedulePoll(refreshInterval); } }
From source file:onl.area51.httpd.action.Request.java
default String getString(String n) { return Objects.toString(getAttribute(n), null); }
From source file:eu.itesla_project.online.tools.PrintOnlineWorkflowWcaResultsTool.java
@Override public void run(CommandLine line) throws Exception { OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); String workflowId = line.getOptionValue("workflow"); OnlineWorkflowWcaResults wfWcaResults = onlinedb.getWcaResults(workflowId); if (wfWcaResults != null) { if (!wfWcaResults.getContingencies().isEmpty()) { Table table = new Table(7, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); String[] headers = new String[7]; int i = 0; table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Contingency"; table.addCell("Cluster 1", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Cluster 1"; table.addCell("Cluster 2", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Cluster 2"; table.addCell("Cluster 3", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Cluster 3"; table.addCell("Cluster 4", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Cluster 4"; table.addCell("Undefined", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Undefined"; table.addCell("Cause", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Cause"; cvsWriter.writeRecord(headers); for (String contingencyId : wfWcaResults.getContingencies()) { String[] values = new String[7]; i = 0;/*from w w w. java 2s .c o m*/ table.addCell(contingencyId); values[i++] = contingencyId; int[] clusterIndexes = new int[] { 1, 2, 3, 4, -1 }; for (int k = 0; k < clusterIndexes.length; k++) { if (clusterIndexes[k] == wfWcaResults.getClusterIndex(contingencyId)) { table.addCell("X", new CellStyle(CellStyle.HorizontalAlign.center)); values[i++] = "X"; } else { table.addCell("-", new CellStyle(CellStyle.HorizontalAlign.center)); values[i++] = "-"; } } table.addCell(Objects.toString(wfWcaResults.getCauses(contingencyId), " "), new CellStyle(CellStyle.HorizontalAlign.center)); values[i++] = Objects.toString(wfWcaResults.getCauses(contingencyId), " "); cvsWriter.writeRecord(values); } cvsWriter.flush(); if (line.hasOption("csv")) System.out.println(content.toString()); else System.out.println(table.render()); cvsWriter.close(); } else System.out.println("\nNo results of security rules applications for this workflow"); } else System.out.println("No results for this workflow"); onlinedb.close(); }
From source file:com.norconex.commons.lang.xml.EnhancedXMLStreamWriter.java
private void writeElementObject(String localName, Object value) throws XMLStreamException { String strValue = Objects.toString(value, null); if (StringUtils.isNotBlank(strValue)) { writer.writeStartElement(localName); writer.writeCharacters(strValue); writer.writeEndElement();/*from www .j a v a 2 s.co m*/ } else if (writeBlanks) { writer.writeEmptyElement(localName); } }
From source file:de.unigoettingen.sub.search.opac.ConfigOpac.java
/** * get doctype from title.//from w w w. j a v a 2s .c om */ public static ConfigOpacDoctype getDoctypeByName(String inTitle) throws FileNotFoundException { int countCatalogues = getConfig().getMaxIndex(DOCTYPES_TYPE); for (int i = 0; i <= countCatalogues; i++) { String title = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@title]"); if (title.equals(inTitle)) { /* Sprachen erfassen */ HashMap<String, String> labels = new HashMap<>(); int countLabels = getConfig().getMaxIndex(DOCTYPES_TYPE + "(" + i + ").label"); for (int j = 0; j <= countLabels; j++) { String language = getConfig() .getString(DOCTYPES_TYPE + "(" + i + ").label(" + j + ")[@language]"); String value = getConfig().getString(DOCTYPES_TYPE + "(" + i + ").label(" + j + ")"); labels.put(language, value); } String inRulesetType = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@rulesetType]"); String inTifHeaderType = getConfig().getString(DOCTYPES_TYPE + "(" + i + ")[@tifHeaderType]"); boolean periodical = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isPeriodical]"); boolean multiVolume = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isMultiVolume]"); boolean newspaper; try { newspaper = getConfig().getBoolean(DOCTYPES_TYPE + "(" + i + ")[@isNewspaper]"); } catch (NoSuchElementException noParameterIsNewspaper) { newspaper = false; } List<Object> configs = getConfig().getList(DOCTYPES_TYPE + "(" + i + ").mapping"); List<String> mappings = configs.stream().map(object -> Objects.toString(object, null)) .collect(Collectors.toList()); return new ConfigOpacDoctype(inTitle, inRulesetType, inTifHeaderType, periodical, multiVolume, newspaper, labels, mappings); } } return null; }