Java Code Examples for org.apache.commons.lang3.StringUtils#removeEnd()
The following examples show how to use
org.apache.commons.lang3.StringUtils#removeEnd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Config.java From symbol-sdk-java with Apache License 2.0 | 6 votes |
private static List<Account> loadNemesisAccountsFromBootstrap(NetworkType networkType) { String bootstrapFolder = System.getenv("CATAPULT_SERVICE_BOOTSTRAP"); if (StringUtils.isBlank(bootstrapFolder)) { bootstrapFolder = "../../catapult-service-bootstrap"; } File generatedAddressesOption = new File( StringUtils.removeEnd(bootstrapFolder, "/") + "/build/generated-addresses/addresses.yaml"); if (!generatedAddressesOption.exists()) { throw new IllegalArgumentException("File " + generatedAddressesOption.getAbsolutePath() + " doesn't exist"); } if (generatedAddressesOption.isDirectory()) { throw new IllegalArgumentException( "File " + generatedAddressesOption.getAbsolutePath() + " is a directory!"); } return loadNemesisAccountsFromBootstrap(networkType, generatedAddressesOption); }
Example 2
Source File: FormatHelper.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Format a grade using the locale * * @param grade - string representation of a grade * @param locale * @return */ private static String formatGradeForLocale(final String grade, final Locale locale) { if (StringUtils.isBlank(grade)) { return ""; } String s; try { final DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(locale); final Double d = df.parse(grade).doubleValue(); df.setMinimumFractionDigits(0); df.setGroupingUsed(false); s = df.format(d); } catch (final NumberFormatException | ParseException e) { log.warn("Bad format, returning original string: {}", grade); s = grade; } return StringUtils.removeEnd(s, ".0"); }
Example 3
Source File: HaloUtils.java From halo with GNU General Public License v3.0 | 6 votes |
/** * Composites partial url to full http url. * * @param partUrls partial urls must not be empty * @return full url */ public static String compositeHttpUrl(@NonNull String... partUrls) { Assert.notEmpty(partUrls, "Partial url must not be blank"); StringBuilder builder = new StringBuilder(); for (int i = 0; i < partUrls.length; i++) { String partUrl = partUrls[i]; if (StringUtils.isBlank(partUrl)) { continue; } partUrl = StringUtils.removeStart(partUrl, URL_SEPARATOR); partUrl = StringUtils.removeEnd(partUrl, URL_SEPARATOR); if (i != 0) { builder.append(URL_SEPARATOR); } builder.append(partUrl); } return builder.toString(); }
Example 4
Source File: LogicUtils.java From carina with Apache License 2.0 | 6 votes |
public static boolean isURLEqual(String url1, String url2) { url1 = StringUtils.replace(url1, "https://", "http://"); url2 = StringUtils.replace(url2, "https://", "http://"); url1 = StringUtils.removeEnd(url1, "/"); url2 = StringUtils.removeEnd(url2, "/"); url1 = url1.contains("?") ? url1.substring(0, url1.indexOf("?")) : url1; url2 = url2.contains("?") ? url2.substring(0, url2.indexOf("?")) : url2; if (url1.contains(SpecialKeywords.IGNORE) || url2.contains(SpecialKeywords.IGNORE)) { String[] urlAr1 = url1.split("/"); String[] urlAr2 = url2.split("/"); return compareWithIgnore(urlAr1, urlAr2); } return url1.equals(url2); }
Example 5
Source File: AbstractPhpCodegen.java From openapi-generator with Apache License 2.0 | 6 votes |
public String toSrcPath(String packageName, String basePath) { packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. if (basePath != null && basePath.length() > 0) { basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separator; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. } // Trim prefix file separators from package path String packagePath = StringUtils.removeStart( // Replace period, backslash, forward slash with file separator in package name packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/")), File.separator ); // Trim trailing file separators from the overall path return StringUtils.removeEnd(basePath + packagePath, File.separator); }
Example 6
Source File: HttpSyncDataService.java From soul with Apache License 2.0 | 6 votes |
private void fetchGroupConfig(final ConfigGroupEnum... groups) throws SoulException { StringBuilder params = new StringBuilder(); for (ConfigGroupEnum groupKey : groups) { params.append("groupKeys").append("=").append(groupKey.name()).append("&"); } SoulException ex = null; for (String server : serverList) { String url = server + "/configs/fetch?" + StringUtils.removeEnd(params.toString(), "&"); log.info("request configs: [{}]", url); String json = this.httpClient.getForObject(url, String.class); log.info("get latest configs: [{}]", json); updateCacheWithJson(json); return; } if (ex != null) { throw ex; } }
Example 7
Source File: IgnoredFiles.java From gocd with Apache License 2.0 | 6 votes |
private String processedPattern() { if (this.processedPattern == null) { String[] parts = FilenameUtils.separatorsToUnix(pattern).split("/"); StringBuilder sb = new StringBuilder(); for (String part : parts) { part = escape(part); if ("**".equals(part)) { sb.append(part.replace("**", "([^/]*/)*")); } else if (part.contains("*")) { sb.append(part.replace("*", "[^/]*")); sb.append("/"); } else { sb.append(part); sb.append("/"); } } this.processedPattern = StringUtils.removeEnd(sb.toString(), "/"); } return this.processedPattern; }
Example 8
Source File: PartitionTree.java From sqlg with MIT License | 5 votes |
private String inExpression() { if (this.fromToIn != null && this.parentPartitionTree.partitionType.isList()) { String tmp = this.fromToIn.substring("FOR VALUES IN (".length()); String fromTo[] = tmp.split(" TO "); String in = fromTo[0]; in = StringUtils.removeStart(in, "("); in = StringUtils.removeEnd(in, ")"); return in; } else { return null; } }
Example 9
Source File: HaloUtils.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Ensures the string contain suffix. * * @param string string must not be blank * @param suffix suffix must not be blank * @return string contain suffix specified */ @NonNull public static String ensureSuffix(@NonNull String string, @NonNull String suffix) { Assert.hasText(string, "String must not be blank"); Assert.hasText(suffix, "Suffix must not be blank"); return StringUtils.removeEnd(string, suffix) + suffix; }
Example 10
Source File: DubboRouteScanner.java From bird-java with MIT License | 5 votes |
/** * 处理path,连续的/去重,确保以/开始 * * @param path path * @return /path */ private String formatPath(String path) { if (StringUtils.isBlank(path)) return path; path = path.replaceAll("[/]+", "/"); path = StringUtils.removeEnd(path, "/"); return path.startsWith("/") ? path : "/" + path; }
Example 11
Source File: DSBean.java From carina with Apache License 2.0 | 5 votes |
public String argsToString(List<String> args, Object[] params, Map<String, Integer> mapper) { if (args.size() == 0) { return ""; } StringBuilder sb = new StringBuilder(); for (String arg : args) { Integer index = mapper.get(arg); if (index != null) { sb.append(String.format("%s=%s; ", arg, params[index].toString())); } } return StringUtils.removeEnd(sb.toString(), "; "); }
Example 12
Source File: YarnLockParser.java From synopsys-detect with Apache License 2.0 | 5 votes |
public List<YarnLockEntryId> parseMultipleEntryLine(String line) { List<YarnLockEntryId> ids = new ArrayList<>(); String[] entries = line.split(","); for (String entryRaw : entries) { String entryNoColon = StringUtils.removeEnd(entryRaw.trim(), ":"); String entryNoColonOrQuotes = removeWrappingQuotes(entryNoColon); YarnLockEntryId entry = parseSingleEntry(entryNoColonOrQuotes); ids.add(entry); } return ids; }
Example 13
Source File: GitUrlParser.java From synopsys-detect with Apache License 2.0 | 5 votes |
public String getRepoName(final String remoteUrlString) throws MalformedURLException { final String[] pieces = remoteUrlString.split("[/:]"); if (pieces.length >= 2) { final String organization = pieces[pieces.length - 2]; final String repo = pieces[pieces.length - 1]; final String name = String.format("%s/%s", organization, repo); return StringUtils.removeEnd(StringUtils.removeStart(name, "/"), ".git"); } else { throw new MalformedURLException("Failed to extract repository name from url. Not logging url for security."); } }
Example 14
Source File: TrpTextRegionType.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
public String getRegionTextFromLines() { String textAll = ""; for (TextLineType l : getTextLine()) { TrpTextLineType trp_l = (TrpTextLineType) l; textAll += trp_l.getUnicodeText()+System.lineSeparator(); } textAll = StringUtils.removeEnd(textAll, System.lineSeparator()); return textAll; }
Example 15
Source File: ComLogonServiceImpl.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
private String getPasswordResetLink(String linkPattern, String username, String token) { try { String baseUrl = configService.getValue(ConfigValue.SystemUrl); String link = linkPattern.replace("{token}", URLEncoder.encode(token, "UTF-8")) .replace("{username}", URLEncoder.encode(username, "UTF-8")); if (StringUtils.startsWithIgnoreCase(link, "http://") || StringUtils.startsWithIgnoreCase(link, "https://")) { return link; } else { return StringUtils.removeEnd(baseUrl, "/") + "/" + StringUtils.removeStart(link, "/"); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
Example 16
Source File: CacheHelper.java From yawp with MIT License | 5 votes |
private static String hash(String string) { byte[] shaArray = DigestUtils.sha(string); byte[] encodedArray = Base64.getEncoder().encode(shaArray); String returnValue = new String(encodedArray); returnValue = StringUtils.removeEnd(returnValue, "\r\n"); return returnValue.replaceAll("=", "").replaceAll("/", "-").replaceAll("\\+", "\\_"); }
Example 17
Source File: NullLocal.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public NullLocal(final String parent, final String name) { super(StringUtils.removeEnd(parent, File.separator), name); }
Example 18
Source File: SolrCommandRunner.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Experimental method for trying out the loading of complex_annotation doc type * * @param opts * @throws Exception */ @CLIMethod("--solr-load-complex-annotations") public void experimentalLoadComplexAnnotationSolr(Opts opts) throws Exception { // Check to see if the global url has been set. String url = sortOutSolrURL(globalSolrURL); // Only proceed if our environment was well-defined. if( legoCatalogs == null || legoFiles == null || legoCatalogs.isEmpty() || legoFiles.isEmpty() ){ LOG.warn("Lego environment not well defined--skipping."); }else{ // Ready the environment for every pass. ParserWrapper pw = new ParserWrapper(); // Add all of the catalogs. for( File legoCatalog : legoCatalogs ){ pw.addIRIMapper(new CatalogXmlIRIMapper(legoCatalog)); } OWLOntologyManager manager = pw.getManager(); OWLReasonerFactory reasonerFactory = new ElkReasonerFactory(); // Actual loading--iterate over our list and load individually. for( File legoFile : legoFiles ){ String fname = legoFile.getName(); OWLReasoner currentReasoner = null; OWLOntology ontology = null; // TODO: Temp cover for missing group labels and IDs. //String agID = legoFile.getCanonicalPath(); String agLabel = StringUtils.removeEnd(fname, ".owl"); String agID = new String(agLabel); try { ontology = pw.parseOWL(IRI.create(legoFile)); currentReasoner = reasonerFactory.createReasoner(ontology); // Some sanity checks--some of the genereated ones are problematic. boolean consistent = currentReasoner.isConsistent(); if( consistent == false ){ LOG.info("Skip since inconsistent: " + fname); continue; } Set<OWLClass> unsatisfiable = currentReasoner.getUnsatisfiableClasses().getEntitiesMinusBottom(); // TODO - make configurable to allow fail fast if (unsatisfiable.isEmpty() == false) { LOG.info("Skip since unsatisfiable: " + fname); continue; } Set<OWLNamedIndividual> individuals = ontology.getIndividualsInSignature(); Set<OWLAnnotation> modelAnnotations = ontology.getAnnotations(); OWLGraphWrapper currentGraph = new OWLGraphWrapper(ontology); try { LOG.info("Trying complex annotation load of: " + fname); ComplexAnnotationSolrDocumentLoader loader = new ComplexAnnotationSolrDocumentLoader(url, currentGraph, currentReasoner, individuals, modelAnnotations, agID, agLabel, fname); loader.load(); } catch (SolrServerException e) { LOG.info("Complex annotation load of " + fname + " at " + url + " failed!"); e.printStackTrace(); System.exit(1); } } finally { // Cleanup reasoner and ontology. if (currentReasoner != null) { currentReasoner.dispose(); } if (ontology != null) { manager.removeOntology(ontology); } } } } }
Example 19
Source File: PayPalManager.java From alf.io with GNU General Public License v3.0 | 4 votes |
private String createCheckoutRequest(PaymentSpecification spec) throws Exception { TicketReservation reservation = ticketReservationRepository.findReservationById(spec.getReservationId()); String eventName = spec.getEvent().getShortName(); String baseUrl = StringUtils.removeEnd(configurationManager.getFor(ConfigurationKeys.BASE_URL, ConfigurationLevel.event(spec.getEvent())).getRequiredValue(), "/"); String bookUrl = baseUrl+"/event/" + eventName + "/reservation/" + spec.getReservationId() + "/payment/paypal/" + URL_PLACEHOLDER; String hmac = computeHMAC(spec.getCustomerName(), spec.getEmail(), spec.getBillingAddress(), spec.getEvent()); UriComponentsBuilder bookUrlBuilder = UriComponentsBuilder.fromUriString(bookUrl) .queryParam("hmac", hmac); String finalUrl = bookUrlBuilder.toUriString(); ApplicationContext applicationContext = new ApplicationContext() .landingPage("BILLING") .cancelUrl(finalUrl.replace(URL_PLACEHOLDER, "cancel")) .returnUrl(finalUrl.replace(URL_PLACEHOLDER, "confirm")) .userAction("CONTINUE") .shippingPreference("NO_SHIPPING"); OrderRequest orderRequest = new OrderRequest() .applicationContext(applicationContext) .checkoutPaymentIntent("CAPTURE") .purchaseUnits(List.of(new PurchaseUnitRequest().amountWithBreakdown(new AmountWithBreakdown().currencyCode(spec.getCurrencyCode()).value(spec.getOrderSummary().getTotalPrice())))); OrdersCreateRequest request = new OrdersCreateRequest().requestBody(orderRequest); request.header("prefer","return=representation"); request.header("PayPal-Request-Id", reservation.getId()); HttpResponse<Order> response = getClient(spec.getEvent()).execute(request); if(HttpUtils.statusCodeIsSuccessful(response.statusCode())) { Order order = response.result(); var status = order.status(); if("APPROVED".equals(status) || "COMPLETED".equals(status)) { if("APPROVED".equals(status)) { saveToken(reservation.getId(), spec.getEvent(), new PayPalToken(order.payer().payerId(), order.id(), hmac)); } return "/event/"+spec.getEvent().getShortName()+"/reservation/"+spec.getReservationId(); } else if("CREATED".equals(status)) { //add 15 minutes of validity in case the paypal flow is slow ticketReservationRepository.updateValidity(spec.getReservationId(), DateUtils.addMinutes(reservation.getValidity(), 15)); return order.links().stream().filter(l -> l.rel().equals("approve")).map(LinkDescription::href).findFirst().orElseThrow(); } } throw new IllegalStateException(); }
Example 20
Source File: ApiGatewaySdkApiImporter.java From aws-apigateway-importer with Apache License 2.0 | 4 votes |
private String trimSlashes(String path) { return StringUtils.removeEnd(StringUtils.removeStart(path, "/"), "/"); }