List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast
public static String substringBeforeLast(final String str, final String separator)
Gets the substring before the last occurrence of a separator.
From source file:org.opennms.tools.jmxconfiggenerator.graphs.SnmpGraphConfigGenerator.java
public static void generateGraphs(String serviceName, String inputFile, String outFile) throws IOException { JmxDatacollectionConfig inputConfig = JAXB.unmarshal(new File(inputFile), JmxDatacollectionConfig.class); for (JmxCollection jmxCollection : inputConfig.getJmxCollection()) { logger.debug("jmxCollection: '{}'", jmxCollection.getName()); Mbeans mbeans = jmxCollection.getMbeans(); int i = 0; for (Mbean mBean : mbeans.getMbean()) { logger.debug("\t" + "mBean: '{}'", mBean.getObjectname()); String reportName = "jsr160" + "." + serviceName + "." + "combo" + i; graphList = graphList + reportName + ", \\" + "\n"; i++;/*from w w w. j a va 2 s .c o m*/ graphBodies = graphBodies + "\n" + generateGraphCombo(jmxCollection, mBean, reportName); for (Attrib attrib : mBean.getAttrib()) { logger.debug("\t\t" + "attrib: '{}'", attrib.getAlias()); graphList = graphList + "jsr160" + "." + serviceName + "." + StringUtils.substring(attrib.getAlias(), 0, 19) + ", \\" + "\n"; graphBodies = graphBodies + "\n" + generateGraph(jmxCollection, mBean, attrib); } } } graphList = StringUtils.substringBeforeLast(graphList, ", \\\n") + "\n"; output = graphList + "\n" + graphBodies; output = StringUtils.substringBeforeLast(output, " \\" + "\n") + "\n"; FileUtils.writeStringToFile(new File(outFile), output, "UTF-8"); }
From source file:org.opennms.tools.jmxconfiggenerator.graphs.SnmpGraphConfigGenerator.java
private static String generateGraphCombo(JmxCollection jmxCollection, Mbean mBean, String reportName) { String report = ""; // report.jvm.mempool.oldgen.name=JVM Memory Pool: OldGen Space report = report.concat("report." + reportName + ".name=" + reportName + "\n"); List<String> attribNameList = new ArrayList<String>(); String columnsNames = ""; for (Attrib attrib : mBean.getAttrib()) { String attribAliasShort = StringUtils.substring(attrib.getAlias(), 0, 19); attribNameList.add(attribAliasShort); columnsNames = columnsNames.concat(attribAliasShort + ", "); }// ww w . j av a 2 s .c o m columnsNames = StringUtils.substringBeforeLast(columnsNames, ", "); // report.jvm.mempool.oldgen.columns=OGenUsage.used, OGenUsage.max report = report.concat("report." + reportName + ".columns=" + columnsNames + "\n"); // report.jvm.mempool.oldgen.type=interfaceSnmp report = report.concat("report." + reportName + ".type=interfaceSnmp" + "\n"); // report.jvm.mempool.oldgen.command=--title="JVM Memory Pool: Old Gen Space" \ report = report .concat("report." + reportName + ".command=--title=\"" + mBean.getName() + "\"" + " \\" + "\n"); // --vertical-label="COUNT Hits" \ report = report.concat(" --vertical-label=\"COUNT\" " + "\\" + "\n"); int i = 0; for (Attrib attrib : mBean.getAttrib()) { i++; String attribAliasShort = StringUtils.substring(attrib.getAlias(), 0, 19); // DEF:used={rrd1}:OGenUsage.used:AVERAGE \ // DEF:max={rrd2}:OGenUsage.max:AVERAGE \ report = report.concat( " DEF:" + attribAliasShort + "={rrd" + i + "}:" + attribAliasShort + ":AVERAGE" + " \\" + "\n"); } i = 0; for (Attrib attrib : mBean.getAttrib()) { i++; String attribAliasShort = StringUtils.substring(attrib.getAlias(), 0, 19); // LINE2:used#73d216:"Bytes Used" \ report = report.concat(" LINE2:" + attribAliasShort + "#" + getNextColor() + ":\"" + attribAliasShort + "\"" + " \\" + "\n"); // GPRINT:used:AVERAGE:" Avg \\: %5.2lf %s " \ report = report .concat(" GPRINT:" + attribAliasShort + ":AVERAGE:\" Avg \\\\: %8.2lf %s\"" + " \\" + "\n"); // GPRINT:used:MIN:" Min \\: %5.2lf %s " \ report = report.concat(" GPRINT:" + attribAliasShort + ":MIN:\" Min \\\\: %8.2lf %s\"" + " \\" + "\n"); // GPRINT:used:MAX:" Max \\: %5.2lf %s " \ report = report.concat(" GPRINT:" + attribAliasShort + ":MAX:\" Max \\\\: %8.2lf %s\"" + " \\" + "\n"); } colorIndex = 0; report = StringUtils.substringBeforeLast(report, "\" \\\n") + "\\\\n\" \\\n"; // LINE2:max#ff0000:"Bytes Allocated" \ // GPRINT:max:AVERAGE:"Avg \\: %5.2lf %s " \ // GPRINT:max:MIN:"Min \\: %5.2lf %s " \ // GPRINT:max:MAX:"Max \\: %5.2lf %s\\n" return report; }
From source file:org.pad.pgsql.loadmovies.LoadFiles.java
/** * Load movies from csv file and save them in DB. * * @throws Exception/*from w ww . ja v a 2 s .c o m*/ */ private static void loadMoviesAndLinks() throws Exception { MovieDao movieDao = new MovieDao(DS); Map<Integer, Integer[]> moviesLinks = new HashMap<>(); //Loads all links informations in memory to enrich afterwards movies CSVParser parser = new CSVParser(new FileReader("C:\\PRIVE\\SRC\\ml-20m\\links.csv"), CSVFormat.EXCEL.withHeader()); for (CSVRecord link : parser) { Integer movieId = Integer.parseInt(link.get("movieId")); if (keepId(movieId)) { System.out.println("Parsing line " + link.toString()); Integer[] otherIds = new Integer[2]; otherIds[0] = Integer.parseInt(link.get("imdbId")); if (StringUtils.isNoneEmpty(link.get("tmdbId"))) { otherIds[1] = Integer.parseInt(link.get("tmdbId")); } moviesLinks.put(movieId, otherIds); } } //Read movie file final Reader reader = new FileReader("C:\\PRIVE\\SRC\\ml-20m\\movies.csv"); parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader()); for (CSVRecord record : parser) { //build a movie object from record Integer movieId = Integer.parseInt(record.get("movieId")); if (keepId(movieId)) { String title = record.get("title"); String genres = record.get("genres"); //Splitting title to extract the date String movieDate = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(title, "("), ")"); String movieName = null; if (StringUtils.isNumeric(movieDate)) { movieName = StringUtils.substringBeforeLast(title, "("); } else { movieName = title; movieDate = null; } System.out.println(movieName + " - " + movieDate); Movie movieToAdd = new Movie(movieId, movieName, movieDate); //Enrich movie with links Integer[] additionalIds = moviesLinks.get(movieId); if (additionalIds != null) { movieToAdd.setImdbId(additionalIds[0]); movieToAdd.setTmdbId(additionalIds[1]); } //Save in database movieDao.save(movieToAdd); } } }
From source file:org.pepstock.jem.gwt.server.services.CertificatesManager.java
/** * Returns a collection of certificates, by a filter (a set of key-values). * /*w w w . j a va 2s .co m*/ * @param filterParm string which contains a set of key-values * @return a collection of certificates, matching the filter * @throws ServiceMessageException * @throws Exception if any exception occurs */ public Collection<CertificateEntry> getCertificates(String filterParm) throws ServiceMessageException { // checks if the user is authorized to read aliases of certificate // if not, this method throws an exception String filter = filterParm; checkAuthorization(new StringPermission(Permissions.CERTIFICATES_READ)); if ("*".equals(filter)) { filter = ""; } else if (filter.endsWith("*")) { filter = StringUtils.substringBeforeLast(filter, "*"); } DistributedTaskExecutor<Collection<CertificateEntry>> task = new DistributedTaskExecutor<Collection<CertificateEntry>>( new GetCertificates(filter), getMember()); return task.getResult(); }
From source file:org.pepstock.jem.node.persistence.CheckingMapManager.java
/** * Loads all pre jobs saved, by a list of keys. * /* w w w . j av a 2 s . c o m*/ * @see com.hazelcast.core.MapLoader#loadAll(java.util.Collection) * @param collaction of keys to load * @return maps with all jobs */ @Override public Map<Long, PreJob> loadAll(Collection<Long> collection) { // check if I have the database manager, otherwise log error and // exception if (dbManager == null) { LogAppl.getInstance().emit(NodeMessage.JEMC044E); throw new MapStoreException(NodeMessage.JEMC044E); } // use collections of keys in strign format, to create SQL // for IN statement, put ' and , on right position StringBuilder sb = new StringBuilder(); for (Long jobid : collection) { sb.append("'").append(jobid).append("'").append(", "); } String inStmt = StringUtils.substringBeforeLast(sb.toString(), ","); // formats SQL to get all jobs by keys String sqlString = MessageFormat.format(sql.getGetAllStatement(), inStmt); Map<Long, PreJob> prejobs = null; try { // load job instance from table prejobs = dbManager.getAllItems(sqlString); LogAppl.getInstance().emit(NodeMessage.JEMC048I, String.valueOf(prejobs.size()), Queues.JCL_CHECKING_QUEUE); } catch (SQLException e) { LogAppl.getInstance().emit(NodeMessage.JEMC043E, e); throw new MapStoreException(NodeMessage.JEMC043E, e); } return prejobs; }
From source file:org.pepstock.jem.util.filters.predicates.JemFilterPredicate.java
/** * Checks name of object with the filter value * @param tokenValue filter of resource// w w w .ja va 2 s . c om * @param name name of instance to be checked * @return true if matches */ protected boolean checkName(String tokenValue, String name) { // is able to manage for label the * wildcard // matches ALWAYS if has got the star only if ("*".equalsIgnoreCase(tokenValue)) { return true; } else { String newTokenValue = tokenValue; // checks if ends with wildcard if (tokenValue.endsWith("*")) { // if yes, remove the stars newTokenValue = StringUtils.substringBeforeLast(tokenValue, "*"); } // checks if contains the string return StringUtils.containsIgnoreCase(name, newTokenValue); } }
From source file:org.pepstock.jem.util.filters.predicates.JobPredicate.java
/** * Checks the filter name//from w ww. ja v a 2s . c o m * @param tokenValue filter passed * @param job job instance * @return true if matches */ private boolean checkName(String tokenValue, Job job) { // is able to manage for job name the * wildcard // matches ALWAYS if has got the star only if ("*".equalsIgnoreCase(tokenValue)) { return true; } else { // checks if ends with wildcard if (tokenValue.endsWith("*")) { // if yes, remove the stars String newTokenValue = StringUtils.substringBeforeLast(tokenValue, "*"); // and compares if the value is in the job name return StringUtils.containsIgnoreCase(job.getName(), newTokenValue); } else { // testif a job id has been inserted MessageFormat jobIdFormat = new MessageFormat(Factory.JOBID_FORMAT); // checks if is by job id try { // try to parse the job id jobIdFormat.parse(tokenValue); // checks if the ID is the same return StringUtils.containsIgnoreCase(job.getId(), tokenValue); } catch (ParseException e) { // ignore LogAppl.getInstance().ignore(e.getMessage(), e); // if here means that is not a JOB ID // then it uses the job name return StringUtils.containsIgnoreCase(job.getName(), tokenValue); } } } }
From source file:org.phenotips.ontology.internal.solr.DefaultSolrOntologyServiceInitializer.java
/** * Get the URL where the Solr server can be reached, without any core name. * * @return an URL as a String/* w w w .j a v a2s .com*/ */ protected String getSolrLocation() { String wikiSolrUrl = this.configuration.getProperty("solr.remote.url", String.class); if (StringUtils.isBlank(wikiSolrUrl)) { return "http://localhost:8080/solr/"; } return StringUtils.substringBeforeLast(StringUtils.removeEnd(wikiSolrUrl, URL_PATH_SEPARATOR), URL_PATH_SEPARATOR) + URL_PATH_SEPARATOR; }
From source file:org.sakaiproject.rubrics.logic.impl.RubricsServiceImpl.java
private Map<String, Map<String, String>> extractCriterionDataFromParams(HashMap<String, String> params) { Map<String, Map<String, String>> criterionDataMap = new HashMap(); for (Map.Entry<String, String> param : params.entrySet()) { String possibleCriterionId = StringUtils.substringAfterLast(param.getKey(), "-"); String criterionDataLabel = StringUtils.substringBeforeLast(param.getKey(), "-"); if (StringUtils.isNumeric(possibleCriterionId)) { if (!criterionDataMap.containsKey(possibleCriterionId)) { criterionDataMap.put(possibleCriterionId, new HashMap()); }//from w w w. j a v a2s . c o m criterionDataMap.get(possibleCriterionId).put(criterionDataLabel, param.getValue()); } } return criterionDataMap; }
From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java
private Map<String, Map<String, String>> extractCriterionDataFromParams(Map<String, String> params) { Map<String, Map<String, String>> criterionDataMap = new HashMap<>(); for (Map.Entry<String, String> param : params.entrySet()) { String possibleCriterionId = StringUtils.substringAfterLast(param.getKey(), "-"); String criterionDataLabel = StringUtils.substringBeforeLast(param.getKey(), "-"); if (StringUtils.isNumeric(possibleCriterionId)) { if (!criterionDataMap.containsKey(possibleCriterionId)) { criterionDataMap.put(possibleCriterionId, new HashMap<>()); }/* w ww .j a v a 2 s. c o m*/ criterionDataMap.get(possibleCriterionId).put(criterionDataLabel, param.getValue()); } } return criterionDataMap; }