本文整理了Java中org.apache.commons.lang3.StringUtils.removeEnd()
方法的一些代码示例,展示了StringUtils.removeEnd()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.removeEnd()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:removeEnd
[英]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. An empty ("") source string will return the empty string. A null search string will return the source string.
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) =
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
[中]仅当子字符串位于源字符串的末尾时才删除该子字符串,否则返回源字符串。
空源字符串将返回空值。空(“”)源字符串将返回空字符串。空搜索字符串将返回源字符串。
StringUtils.removeEnd(null, *) = null
StringUtils.removeEnd("", *) = ""
StringUtils.removeEnd(*, null) =
StringUtils.removeEnd("www.domain.com", ".com.") = "www.domain.com"
StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeEnd("abc", "") = "abc"
代码示例来源:origin: org.apache.commons/commons-lang3
return removeEnd(str,separator);
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Repeat a String {@code repeat} times to form a
* new String, with a String separator injected each time. </p>
*
* <pre>
* StringUtils.repeat(null, null, 2) = null
* StringUtils.repeat(null, "x", 2) = null
* StringUtils.repeat("", null, 0) = ""
* StringUtils.repeat("", "", 2) = ""
* StringUtils.repeat("", "x", 3) = "xxx"
* StringUtils.repeat("?", ", ", 3) = "?, ?, ?"
* </pre>
*
* @param str the String to repeat, may be null
* @param separator the String to inject, may be null
* @param repeat number of times to repeat str, negative treated as zero
* @return a new String consisting of the original String repeated,
* {@code null} if null String input
* @since 2.5
*/
public static String repeat(final String str, final String separator, final int repeat) {
if(str == null || separator == null) {
return repeat(str, repeat);
}
// given that repeat(String, int) is quite optimized, better to rely on it than try and splice this into it
final String result = repeat(str + separator, repeat);
return removeEnd(result, separator);
}
代码示例来源:origin: apache/incubator-gobblin
public String getFullUri(String resourcePath) {
return StringUtils.removeEnd(getServiceBaseUrl(), "/") + StringUtils.removeEnd(resourcePath, "/");
}
代码示例来源:origin: gocd/gocd
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;
}
代码示例来源:origin: Netflix/conductor
String nsKey(String... nsValues) {
String rootNamespace = config.getProperty("workflow.namespace.prefix", null);
StringBuilder namespacedKey = new StringBuilder();
if (StringUtils.isNotBlank(rootNamespace)) {
namespacedKey.append(rootNamespace).append(NAMESPACE_SEP);
}
String stack = config.getStack();
if (StringUtils.isNotBlank(stack)) {
namespacedKey.append(stack).append(NAMESPACE_SEP);
}
if (StringUtils.isNotBlank(domain)) {
namespacedKey.append(domain).append(NAMESPACE_SEP);
}
for (int i = 0; i < nsValues.length; i++) {
namespacedKey.append(nsValues[i]).append(NAMESPACE_SEP);
}
return StringUtils.removeEnd(namespacedKey.toString(), NAMESPACE_SEP);
}
代码示例来源:origin: apache/incubator-gobblin
/***
* Extract token value from source entity, where token value is represented by a token in the source entity.
*
* Eg.
* Source Entity : prod_tableName_avro
* Source Template: prod_$LOGICAL_TABLE_avro
* Token : $LOGICAL_TABLE
* Extracted Value: tableName
*
* @param sourceEntity Source entity (typically a table or database name).
* @param sourceTemplate Source template representing the source entity.
* @param token Token representing the value to extract from the source entity using the template.
* @return Extracted token value from the source entity.
*/
@VisibleForTesting
protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) {
Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank");
Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank");
Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token));
String extractedValue = sourceEntity;
List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate));
extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0));
extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1));
return extractedValue;
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
public static String getNodeName(String filePath, GenerationConfig config) {
try {
String fileName = FilenameUtils.getName(URLDecoder.decode(filePath, "UTF-8"));
String[] extensions = config.getFileExtensions() == null ? new String[] {} : config.getFileExtensions();
boolean extensionRemoved = false;
for (int i = 0; i < extensions.length; i++) {
String extension = extensions[i];
if (extension.length() == 0) {
continue;
}
if (!extension.startsWith(".")) {
extension = "." + extension;
}
if (fileName.endsWith(extension)) {
fileName = removeEnd(fileName, extension);
extensionRemoved = true;
break;
}
}
if (!extensionRemoved) {
fileName = FilenameUtils.getBaseName(fileName);
}
return fileName;
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(String.format("Unable to generate node name from URL: %s", filePath), e);
}
}
代码示例来源:origin: apache/incubator-gobblin
public static String readQueryFromFile(String directory, String filename)
throws IOException {
InputStream is = ConversionHiveTestUtils.class.getClassLoader()
.getResourceAsStream(StringUtils.removeEnd(directory, Path.SEPARATOR) + Path.SEPARATOR + filename);
return IOUtils.toString(is, "UTF-8");
}
代码示例来源:origin: apache/incubator-gobblin
public static Schema readSchemaFromJsonFile(String directory, String filename)
throws IOException {
return new Schema.Parser()
.parse(ConversionHiveTestUtils.class.getClassLoader()
.getResourceAsStream(StringUtils.removeEnd(directory, Path.SEPARATOR) + Path.SEPARATOR + filename));
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testRemoveEnd() {
// StringUtils.removeEnd("", *) = ""
assertNull(StringUtils.removeEnd(null, null));
assertNull(StringUtils.removeEnd(null, ""));
assertNull(StringUtils.removeEnd(null, "a"));
// StringUtils.removeEnd(*, null) = *
assertEquals(StringUtils.removeEnd("", null), "");
assertEquals(StringUtils.removeEnd("", ""), "");
assertEquals(StringUtils.removeEnd("", "a"), "");
// All others:
assertEquals(StringUtils.removeEnd("www.domain.com.", ".com"), "www.domain.com.");
assertEquals(StringUtils.removeEnd("www.domain.com", ".com"), "www.domain");
assertEquals(StringUtils.removeEnd("www.domain", ".com"), "www.domain");
assertEquals(StringUtils.removeEnd("domain.com", ""), "domain.com");
assertEquals(StringUtils.removeEnd("domain.com", null), "domain.com");
}
代码示例来源:origin: rest-assured/rest-assured
final String logString = StringUtils.removeEnd(builder.toString(), SystemUtils.LINE_SEPARATOR);
stream.println(logString);
return logString;
代码示例来源:origin: spring-projects/spring-roo
/**
* Returns the given file system path minus its last element
*
* @param fileIdentifier
* @return
* @since 1.2.0
*/
public static String backOneDirectory(String fileIdentifier) {
fileIdentifier = StringUtils.removeEnd(fileIdentifier, File.separator);
fileIdentifier = fileIdentifier.substring(0, fileIdentifier.lastIndexOf(File.separator));
return StringUtils.removeEnd(fileIdentifier, File.separator);
}
代码示例来源:origin: spring-projects/spring-roo
private String convertToFullyQualifiedPackageName(final Pom module, final String text) {
final String normalisedText = StringUtils.removeEnd(text, ".").toLowerCase();
if (normalisedText.startsWith(TOP_LEVEL_PACKAGE_SYMBOL)) {
return replaceTopLevelPackageSymbol(module, normalisedText);
}
return normalisedText;
}
代码示例来源:origin: mulesoft/mule
/**
* Copies a given app archive with a given target name to the apps folder for deployment
*
* @throws URISyntaxException
*/
private void addAppArchive(URL url, String targetFile) throws IOException, URISyntaxException {
// copy is not atomic, copy to a temp file and rename instead (rename is atomic)
final String tempFileName = (targetFile == null ? new File(url.toURI()) : new File(targetFile)).getPath() + ".part";
final File tempFile = new File(appsDir, tempFileName);
copyURLToFile(url, tempFile);
boolean renamed = tempFile.renameTo(new File(removeEnd(tempFile.getAbsolutePath(), ".part")));
if (!renamed) {
throw new IllegalStateException("Unable to add application archive");
}
}
代码示例来源:origin: kongchen/swagger-maven-plugin
/**
*
* @param clazz Controller class
* @param resourceName resource Name
* @param resourceKey key containing the controller package, class controller class name, and controller-level @RequestMapping#value
* @param description description of the contrroller
*/
public SpringResource(Class<?> clazz, String resourceName, String resourceKey, String description) {
this.controllerClass = clazz;
this.resourceName = resourceName;
this.resourceKey = resourceKey;
this.description = description;
methods = new ArrayList<Method>();
String[] controllerRequestMappingValues = SpringUtils.getControllerResquestMapping(controllerClass);
this.controllerMapping = StringUtils.removeEnd(controllerRequestMappingValues[0], "/");
}
代码示例来源:origin: spring-projects/spring-roo
private String getParentPath(final JavaType javaType) {
final String relativePath = javaType.getRelativeFileName();
for (final String typePath : discoverTypes()) {
if (typePath.endsWith(relativePath)) {
return StringUtils.removeEnd(typePath, relativePath);
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-roo
private String resolveRelativePath(String relativeTo, final String relativePath) {
relativeTo = StringUtils.removeEnd(relativeTo, File.separator);
while (new File(relativeTo).isFile()) {
relativeTo = relativeTo.substring(0, relativeTo.lastIndexOf(File.separator));
代码示例来源:origin: spring-projects/spring-roo
public Pom getModuleForFileIdentifier(final String fileIdentifier) {
updatePomCache();
String startingPoint = FileUtils.getFirstDirectory(fileIdentifier);
String pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME;
File pom = new File(pomPath);
while (!pom.exists()) {
if (startingPoint.equals(SEPARATOR)) {
break;
}
startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR);
if (startingPoint.lastIndexOf(SEPARATOR) < 0) {
break;
}
startingPoint = startingPoint.substring(0, startingPoint.lastIndexOf(SEPARATOR));
startingPoint = StringUtils.removeEnd(startingPoint, SEPARATOR);
pomPath = FileUtils.ensureTrailingSeparator(startingPoint) + DEFAULT_POM_NAME;
pom = new File(pomPath);
}
return getPomFromPath(pomPath);
}
代码示例来源:origin: spring-projects/spring-roo
@Override
public List<String> getApplicationProfiles(String moduleName) {
List<String> profiles = new ArrayList<String>();
final String applicationConfigFilename =
StringUtils.removeEnd(getSpringConfigLocation(moduleName),
DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION);
// Find application config files
for (final FileDetails applicationConfig : fileManager
.findMatchingAntPath(applicationConfigFilename + "*"
+ DEFAULT_APPLICATION_CONFIG_FILE_EXTENSION)) {
final String applicationConfigPath = applicationConfig.getCanonicalPath();
if (!fileManager.exists(applicationConfigPath)) {
continue;
}
// Extract profile
String profile =
StringUtils.substringBetween(applicationConfigPath, applicationConfigFilename,
".properties");
profiles.add(StringUtils.removeStart(profile, "-"));
}
return profiles;
}
代码示例来源:origin: mulesoft/mule
protected void addArchive(File outputDir, URI uri, String targetFile) throws Exception {
ReentrantLock lock = deploymentService.getLock();
lock.lock();
try {
// copy is not atomic, copy to a temp file and rename instead (rename is atomic)
final String tempFileName = (targetFile == null ? new File(uri) : new File(targetFile)).getName() + ".part";
final File tempFile = new File(outputDir, tempFileName);
copyFile(new File(uri), tempFile);
final File destFile = new File(removeEnd(tempFile.getAbsolutePath(), ".part"));
File deployFolder = new File(destFile.getAbsolutePath().replace(JAR_FILE_SUFFIX, ""));
if (deployFolder.exists()) {
// Delete META-INF folder so maven file do not get duplicated during redeployment testing.
deleteDirectory(new File(deployFolder, Paths.get("META-INF", "maven").toString()));
}
tempFile.renameTo(destFile);
assertThat("File does not exists: " + destFile.getAbsolutePath(), destFile.exists(), is(true));
} finally {
lock.unlock();
}
}
内容来源于网络,如有侵权,请联系作者删除!