List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:com.ottogroup.bi.asap.resman.node.ProcessingNodeManager.java
/** * Updates or instantiates a pipeline on remote processing nodes * @param deploymentProfile/*w w w .j a v a2 s.c o m*/ * @return * @throws RequiredInputMissingException */ public PipelineDeploymentProfile updateOrInstantiatePipeline(final PipelineDeploymentProfile deploymentProfile) throws RequiredInputMissingException { /////////////////////////////////////////////////////// // validate input if (deploymentProfile == null) throw new RequiredInputMissingException("Missing required pipeline configuration"); // TODO validate even more // /////////////////////////////////////////////////////// for (final ProcessingNode pn : this.processingNodes.values()) { try { pn.updateOrInstantiatePipeline(deploymentProfile.getConfiguration()); deploymentProfile.addProcessingNode(StringUtils.lowerCase(StringUtils.trim(pn.getId()))); } catch (RemoteClientConnectionFailedException | IOException e) { logger.error("Failed to update or deploy pipeline '" + deploymentProfile.getId() + "' on processing node '" + pn.getId() + "'. Error: " + e.getMessage()); } } return deploymentProfile; }
From source file:com.ottogroup.bi.asap.operator.json.aggregator.JsonContentAggregatorResult.java
/** * Returns the aggregated value for a given field and value: (field='cs-host', value='www.otto.de', result: 5); * @param field/* w ww . j ava 2s . com*/ * @param fieldValue * @return */ public long getAggregatedValue(final String field, final String fieldValue) { String fieldKey = StringUtils.lowerCase(StringUtils.trim(field)); Map<String, Long> fieldAggregationValues = this.aggregatedValues.get(fieldKey); return (fieldAggregationValues != null ? fieldAggregationValues.get(fieldValue) : 0); }
From source file:com.ottogroup.bi.asap.pipeline.MicroPipeline.java
/** * Submits the provided {@link SourceExecutor} to the pipeline instance * @param source// w w w . j ava2s . c o m * @throws RequiredInputMissingException * @throws ComponentAlreadySubmittedException */ public void submitSourceExecutor(final SourceExecutor sourceExecutor) throws RequiredInputMissingException, ComponentAlreadySubmittedException { /////////////////////////////////////////////////////////////////// // validate input if (sourceExecutor == null) throw new RequiredInputMissingException("Missing required input for 'sourceExecutor'"); if (StringUtils.isBlank(sourceExecutor.getSourceId())) throw new RequiredInputMissingException("Missing required input for source identifier"); // /////////////////////////////////////////////////////////////////// // normalize identifier to lower case String sid = StringUtils.lowerCase(StringUtils.trim(sourceExecutor.getSourceId())); if (this.sourceExecutors.containsKey(sid)) throw new ComponentAlreadySubmittedException( "Component '" + sourceExecutor.getSourceId() + "' already submitted to pipeline '" + id + "'"); // add source executor to internal map and submit it to executor service this.sourceExecutors.put(sid, sourceExecutor); this.executorService.submit(sourceExecutor); if (logger.isDebugEnabled()) logger.debug("source executor submitted [pid=" + id + ", sid=" + sid + ", mb=source has no mailbox]"); }
From source file:com.ottogroup.bi.spqr.metrics.MetricsHandler.java
/** * {@link ScheduledReporter#stop() Stops} the referenced {@link ScheduledReporter} but keeps it referenced * @param id//from w w w.j a va 2 s .co m */ public void stopScheduledReporter(final String id) { String key = StringUtils.lowerCase(StringUtils.trim(id)); ScheduledReporter scheduledReporter = this.scheduledReporters.get(key); if (scheduledReporter != null) { scheduledReporter.stop(); } }
From source file:de.micromata.genome.db.jdbc.trace.StdSqlTracer.java
/** * Execute wrapped int.//from w ww . jav a 2 s. c om * * @param <T> the generic type * @param sqlTraced the sql traced * @param sql the sql * @param callable the callable * @return the t * @throws SQLException the SQL exception */ public <T> T executeWrappedInt(SqlTraced sqlTraced, String sql, CallableX<T, SQLException> callable) throws SQLException { TraceConnection connection = sqlTraced.getTraceConnection(); TraceConfig traceConfig = connection.getTraceConfig(); boolean statsEnabled = traceConfig.isEnableStats(); boolean logEnabled = traceConfig.isEnableLogging(); if (logEnabled == false && statsEnabled == false) { return callable.call(); } boolean inRec = connection.isInRecursion(); if (statsEnabled == false && inRec == true) { return callable.call(); } TraceSqlArguments sqlArguments = sqlTraced.getSqlArguments(); String realSql = sqlArguments.getSql(); LogCategory cat = traceConfig.getLogCategory(); if (sql != null) { sqlArguments.setSql(sql); } if (traceConfig.isTrimPreparedStatement() == true) { sqlArguments.setSql(StringUtils.trim(sqlArguments.getSql())); } if (logEnabled == true) { logEnabled = isFilteredForLogging(traceConfig, sqlArguments.getSql()); } // System.out.println("sqltrace: " + sqlArguments.toString()); if (logEnabled == false && statsEnabled == false) { return callable.call(); } // nur Stats if (inRec == true || logEnabled == false) { long start = System.currentTimeMillis(); try { return callable.call(); } finally { long end = System.currentTimeMillis(); LoggingServiceManager.get().getStatsDAO().addPerformance(traceConfig.getLogCategory(), realSql, end - start, 0); } } // Logging + optional Stats try { connection.lockRecursion(); if (logEnabled == true) { boolean loggingLogEnabled = GLog.isDebugEnabled(cat, realSql); if (loggingLogEnabled == true) { addToLog(cat, sqlArguments, connection, sqlTraced, traceConfig); } } long start = System.currentTimeMillis(); try { return callable.call(); } finally { if (statsEnabled == true) { long end = System.currentTimeMillis(); LoggingServiceManager.get().getStatsDAO().addPerformance(cat, realSql, end - start, 0); } } } finally { connection.releaseRecursion(); } }
From source file:gov.nih.nci.caintegrator.external.biodbnet.BioDbNetSearchImpl.java
/** * Extracts the gene information from a line of bioDbNet gene search results. * @param line a gene search result line * @return the parsed gene/*from ww w .j a va 2s.c o m*/ */ private GeneResults extractGene(String[] line) { Matcher descrptionMatcher = DESCRIPTION_PATTERN.matcher(line[GENE_INFO_INDEX]); Matcher taxonMatcher = TAXON_PATTERN.matcher(line[TAXON_INDEX]); GeneResults gene = new GeneResults(); gene.setSymbol(line[GENE_SYMBOL_INDEX]); if (NumberUtils.isNumber(line[GENE_ID_INDEX])) { gene.setGeneId(Long.valueOf(line[GENE_ID_INDEX])); } gene.setDescription(getValue(descrptionMatcher)); gene.setAliases(StringUtils.trim(StringUtils.replaceChars(line[GENE_SYNONYM_INDEX], ';', ','))); gene.setTaxon(getValue(taxonMatcher)); return gene; }
From source file:fi.foyt.fni.view.gamelibrary.GameLibraryEditPublicationBackingBean.java
public void addTag() { String tag = getAddExistingTag(); if ("_NEW_".equals(tag)) { tag = StringUtils.lowerCase(StringUtils.trim(getAddNewTag())); }/* w ww.j a v a 2s. c o m*/ if (StringUtils.isNotBlank(tag) && (!tags.contains(tag))) { tags.add(tag); } }
From source file:com.norconex.importer.handler.tagger.impl.TitleGeneratorTagger.java
private String getHeadingTitle(String text) { String firstLine = null;/* w w w. j a v a 2s . c o m*/ Matcher m = PATTERN_HEADING.matcher(text); if (m.find()) { firstLine = StringUtils.trim(m.group()); } if (StringUtils.isBlank(firstLine)) { return null; } // if more than one sentence, ignore if (StringUtils.split(firstLine, "?!.").length != 1) { return null; } // must match min/max lengths. if (firstLine.length() < detectHeadingMinLength || firstLine.length() > detectHeadingMaxLength) { return null; } return firstLine; }
From source file:com.alibaba.rocketmq.filtersrv.filter.DynaCode.java
public static String getClassName(String code) { String className = StringUtils.substringBefore(code, "{"); if (StringUtils.isBlank(className)) { return className; }/*from w ww . ja v a 2 s. co m*/ if (StringUtils.contains(code, " class ")) { className = StringUtils.substringAfter(className, " class "); if (StringUtils.contains(className, " extends ")) { className = StringUtils.substringBefore(className, " extends ").trim(); } else if (StringUtils.contains(className, " implements ")) { className = StringUtils.trim(StringUtils.substringBefore(className, " implements ")); } else { className = StringUtils.trim(className); } } else if (StringUtils.contains(code, " interface ")) { className = StringUtils.substringAfter(className, " interface "); if (StringUtils.contains(className, " extends ")) { className = StringUtils.substringBefore(className, " extends ").trim(); } else { className = StringUtils.trim(className); } } else if (StringUtils.contains(code, " enum ")) { className = StringUtils.trim(StringUtils.substringAfter(className, " enum ")); } else { return StringUtils.EMPTY; } return className; }
From source file:com.ottogroup.bi.spqr.metrics.MetricsReporterFactory.java
/** * Attaches a new reporter of specified {@link MetricReporterType type} to contained {@link MetricsHandler#getRegistry() registry} * @param metricsHandler//from w ww .ja v a 2 s.c o m * @param reporterConfig * @throws RequiredInputMissingException */ public static void attachReporters(final MetricsHandler metricsHandler, final List<MicroPipelineMetricsReporterConfiguration> reporterConfig) throws RequiredInputMissingException { if (reporterConfig == null || reporterConfig.isEmpty()) return; /////////////////////////////////////////////////////////////////// // validate input if (metricsHandler == null) throw new RequiredInputMissingException("Missing required metrics handler"); /////////////////////////////////////////////////////////////////// for (final MicroPipelineMetricsReporterConfiguration rc : reporterConfig) { if (rc.getType() == null) throw new RequiredInputMissingException( "Missing required type for metrics reporter configuration [id=" + rc.getId() + "]"); switch (rc.getType()) { case CONSOLE: { MetricsReporterFactory.attachConsoleReporter(metricsHandler, rc.getId(), rc.getPeriod()); break; } case CSV: { if (rc.getSettings() == null || rc.getSettings().isEmpty()) throw new RequiredInputMissingException( "Missing required settings for metrics reporter configuration [id=" + rc.getId() + "]"); MetricsReporterFactory.attachCSVReporter(metricsHandler, rc.getId(), rc.getPeriod(), rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_CSV_OUTPUT_FILE)); break; } case GRAPHITE: { if (rc.getSettings() == null || rc.getSettings().isEmpty()) throw new RequiredInputMissingException( "Missing required settings for metrics reporter configuration [id=" + rc.getId() + "]"); String p = rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_GRAPHITE_PORT); int port = -1; try { port = Integer.parseInt(StringUtils.trim(p)); } catch (Exception e) { throw new RequiredInputMissingException("Invalid input found for graphite port [id=" + rc.getId() + "]. Error: " + e.getMessage()); } MetricsReporterFactory.attachGraphiteReporter(metricsHandler, rc.getId(), rc.getPeriod(), rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_GRAPHITE_HOST), port); break; } case KAFKA: { MetricsReporterFactory.attachKafkaReporter(metricsHandler, rc.getId(), rc.getPeriod(), rc.getSettings() .get(MicroPipelineMetricsReporterConfiguration.SETTING_KAFKA_ZOOKEEPER_CONNECT), rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_KAFKA_BROKER_LIST), rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_KAFKA_CLIENT_ID), rc.getSettings().get(MicroPipelineMetricsReporterConfiguration.SETTING_KAFKA_TOPIC_ID)); break; } default: { throw new RequiredInputMissingException("Unknown metrics reporter type: " + rc.getType()); } } } }