List of usage examples for org.apache.commons.lang3 StringUtils removeEnd
public static String removeEnd(final String str, final String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
A null source string will return null .
From source file:org.phenotips.entities.internal.AbstractPrimaryEntityManager.java
@Override public Iterator<E> getAll() { try {//ww w. j av a 2 s.c o m Query q = this.qm .createQuery("select doc.fullName from Document as doc, doc.object(" + this.localSerializer.serialize(getEntityXClassReference()) + ") as entity where doc.name not in (:template1, :template2) order by doc.name asc", Query.XWQL) .bindValue("template1", this.getEntityXClassReference().getName() + "Template") .bindValue("template2", StringUtils.removeEnd(this.getEntityXClassReference().getName(), "Class") + "Template"); List<String> docNames = q.execute(); return new LazyPrimaryEntityIterator<>(docNames, this); } catch (QueryException ex) { this.logger.warn("Failed to query all entities of type [{}]: {}", getEntityXClassReference(), ex.getMessage()); } return Collections.emptyIterator(); }
From source file:org.phenotips.entities.internal.AbstractPrimaryEntityManager.java
/** * Gets a prefix for all {@code #create() generated} documents. This implementation computes it from the uppercase * letters of the XClass name, excluding {@code Class}, e.g. for {@code PhenoTips.DiseaseStudyClass} the prefix will * be {@code DS}.//from w w w . j ava2 s. c o m * * @return a short string */ protected String getIdPrefix() { String name = getEntityXClassReference().getName(); name = StringUtils.removeEnd(name, "Class"); return name.replaceAll("\\p{Lower}++", ""); }
From source file:org.phenotips.ontology.internal.GeneNomenclature.java
private StringBuilder processQueryPart(StringBuilder query, Map.Entry<String, ?> field, boolean includeOperator) { if (Collection.class.isInstance(field.getValue()) && ((Collection<?>) field.getValue()).isEmpty()) { return query; }// w w w. j av a 2 s . co m if (Map.class.isInstance(field.getValue())) { if (QUERY_OPERATORS.containsKey(field.getKey())) { @SuppressWarnings("unchecked") Map.Entry<String, Map<String, ?>> subquery = (Map.Entry<String, Map<String, ?>>) field; return processSubquery(query, subquery); } else { this.logger.warn("Invalid subquery operator: {}", field.getKey()); return query; } } query.append(' '); if (includeOperator) { query.append(QUERY_OPERATORS.get(DEFAULT_OPERATOR)); } query.append(ClientUtils.escapeQueryChars(field.getKey())); query.append(":("); if (Collection.class.isInstance(field.getValue())) { for (Object value : (Collection<?>) field.getValue()) { String svalue = String.valueOf(value); if (svalue.endsWith(WILDCARD)) { svalue = ClientUtils.escapeQueryChars(StringUtils.removeEnd(svalue, WILDCARD)) + WILDCARD; } else { svalue = ClientUtils.escapeQueryChars(svalue); } query.append(svalue); query.append(' '); } } else { String svalue = String.valueOf(field.getValue()); if (svalue.endsWith(WILDCARD)) { svalue = ClientUtils.escapeQueryChars(StringUtils.removeEnd(svalue, WILDCARD)) + WILDCARD; } else { svalue = ClientUtils.escapeQueryChars(svalue); } query.append(svalue); } query.append(')'); return query; }
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. jav a 2 s . c o m*/ */ 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.phenotips.variantstore.input.exomiser6.tsv.Exomiser6TSVManager.java
@Override public List<String> getAllIndividuals() { final List<String> list = new ArrayList<>(); try {//from ww w . jav a 2s . co m Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String filename = file.getFileName().toString(); String id = StringUtils.removeEnd(filename, suffix); list.add(id); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { logger.error("Error getting all individuals", e); } return list; }
From source file:org.phenotips.variantstore.input.vcf.VCFManager.java
@Override public List<String> getAllIndividuals() { final List<String> list = new ArrayList<>(); try {// w ww . java 2 s .c o m Files.walkFileTree(this.path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.CONTINUE; } String id = file.getFileName().toString(); id = StringUtils.removeEnd(id, suffix); list.add(id); return FileVisitResult.CONTINUE; } }); } catch (IOException e) { logger.error("Error getting all individuals"); } return list; }
From source file:org.phenotips.vocabulary.internal.RemoteGeneNomenclature.java
private StringBuilder processQueryPart(StringBuilder query, Map.Entry<String, ?> field, boolean includeOperator) { if (Collection.class.isInstance(field.getValue()) && ((Collection<?>) field.getValue()).isEmpty()) { return query; }// www .j a v a 2s . com if (Map.class.isInstance(field.getValue())) { if (QUERY_OPERATORS.containsKey(field.getKey())) { @SuppressWarnings("unchecked") Map.Entry<String, Map<String, ?>> subquery = (Map.Entry<String, Map<String, ?>>) field; return processSubquery(query, subquery); } else { this.logger.warn("Invalid subquery operator: {}", field.getKey()); return query; } } query.append(' '); if (includeOperator) { query.append(QUERY_OPERATORS.get(DEFAULT_OPERATOR)); } query.append(ClientUtils.escapeQueryChars(field.getKey())); query.append(":("); if (Collection.class.isInstance(field.getValue())) { for (Object value : (Collection<?>) field.getValue()) { String svalue = String.valueOf(value); if (svalue.endsWith(WILDCARD)) { svalue = ClientUtils.escapeQueryChars(StringUtils.removeEnd(svalue, WILDCARD)) + WILDCARD; } else { svalue = ClientUtils.escapeQueryChars(svalue); } query.append(svalue); query.append(' '); } } else { String svalue = String.valueOf(field.getValue()); if (svalue.endsWith(WILDCARD)) { svalue = ClientUtils.escapeQueryChars(StringUtils.removeEnd(svalue, WILDCARD)) + WILDCARD; } else { svalue = ClientUtils.escapeQueryChars(svalue); } query.append(svalue); } query.append(')'); return query; }
From source file:org.pircbotx.hooks.ListenerAdapterTest.java
/** * Makes sure adapter uses all events/* w w w . j a v a 2s . c o m*/ * * @throws Exception */ @Test(dataProviderClass = TestUtils.class, dataProvider = "eventAllDataProvider", description = "Verify ListenerAdapter has methods for all events") public void eventImplementTest(Class eventClass) throws NoSuchMethodException { //Just try to load it. If the method doesn't exist then it throws a NoSuchMethodException String eventName = eventClass.getSimpleName(); assertTrue(StringUtils.endsWith(eventName, "Event"), "Unknown event class " + eventClass); String methodName = "on" + StringUtils.removeEnd(StringUtils.capitalize(eventName), "Event"); ListenerAdapter.class.getDeclaredMethod(methodName, eventClass); }
From source file:org.pircbotx.hooks.ListenerAdapterTest.java
@Test(dependsOnMethods = "eventImplementTest", dataProviderClass = TestUtils.class, dataProvider = "eventAllDataProvider", description = "Verify all methods in ListenerAdapter throw an exception") public void throwsExceptionTest(Class eventClass) throws NoSuchMethodException { String methodName = "on" + StringUtils.removeEnd(StringUtils.capitalize(eventClass.getSimpleName()), "Event"); Method eventMethod = ListenerAdapter.class.getDeclaredMethod(methodName, eventClass); Class<?>[] exceptions = eventMethod.getExceptionTypes(); assertEquals(exceptions.length, 1,//from w w w .ja v a 2 s . co m "Method " + eventMethod + " in ListenerManager doesn't throw an exception or thows too many"); assertEquals(exceptions[0], Exception.class, "Method " + eventMethod + " in ListenerManager doesn't throw the right exception"); }
From source file:org.polymap.p4.process.ProcessProgressMonitor.java
protected void update(boolean throttle) { if (throttle && updated.elapsedTime() < 1000) { return;// w w w. j ava 2s. co m } updated.start(); display.asyncExec(() -> { if (msg != null && !msg.isDisposed()) { String s = Joiner.on(" ").skipNulls().join(StringUtils.removeEnd(taskName, "..."), " ...", subTaskName); if (total != UNKNOWN) { double percent = 100d / total * worked; s += " (" + (int) percent + "%)"; } msg.setText(s); } }); }