org.apache.commons.lang3.StringUtils.difference()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中org.apache.commons.lang3.StringUtils.difference()方法的一些代码示例,展示了StringUtils.difference()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.difference()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:difference

StringUtils.difference介绍

[英]Compares two Strings, and returns the portion where they differ. More precisely, return the remainder of the second String, starting from where it's different from the first. This means that the difference between "abc" and "ab" is the empty String and not "c".

For example, difference("i am a machine", "i am a robot") -> "robot".

StringUtils.difference(null, null) = null 
StringUtils.difference("", "") = "" 
StringUtils.difference("", "abc") = "abc" 
StringUtils.difference("abc", "") = "" 
StringUtils.difference("abc", "abc") = "" 
StringUtils.difference("abc", "ab") = "" 
StringUtils.difference("ab", "abxyz") = "xyz" 
StringUtils.difference("abcde", "abxyz") = "xyz" 
StringUtils.difference("abcde", "xyz") = "xyz"

[中]

代码示例

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testDifference_StringString() {
  assertNull(StringUtils.difference(null, null));
  assertEquals("", StringUtils.difference("", ""));
  assertEquals("abc", StringUtils.difference("", "abc"));
  assertEquals("", StringUtils.difference("abc", ""));
  assertEquals("i am a robot", StringUtils.difference(null, "i am a robot"));
  assertEquals("i am a machine", StringUtils.difference("i am a machine", null));
  assertEquals("robot", StringUtils.difference("i am a machine", "i am a robot"));
  assertEquals("", StringUtils.difference("abc", "abc"));
  assertEquals("you are a robot", StringUtils.difference("i am a robot", "you are a robot"));
}

代码示例来源:origin: com.atlassian.plugins.rest/atlassian-rest-common

public ContainerRequest filter(ContainerRequest request) {
  final String absoluteUri = request.getAbsolutePath().toString();
  final String extension = StringUtils.substringAfterLast(absoluteUri, DOT);
  if (shouldFilter("/" + StringUtils.difference(request.getBaseUri().toString(), absoluteUri), extension)) {
    request.getRequestHeaders().putSingle(HttpHeaders.ACCEPT, EXTENSION_TO_ACCEPT_HEADER.get(extension));
    final String absoluteUriWithoutExtension = StringUtils.substringBeforeLast(absoluteUri, DOT);
    request.setUris(request.getBaseUri(), getRequestUri(absoluteUriWithoutExtension, request.getQueryParameters()));
  }
  return request;
}

代码示例来源:origin: apache/servicecomb-java-chassis

scSchemaContent,
  localSchemaContent);
String diffStringLocal = StringUtils.difference(scSchemaContent, localSchemaContent);
if (diffStringLocal.equals("")) {
 LOGGER.warn("Some APIs are deleted in local schema which are present in service center schema \n");

代码示例来源:origin: gradle.plugin.com.we.intershop.gradleplugin/icm-code-generator

/**
 * Return package name from the root to the target Path
 * 
 * @param packageRoot
 *            root where it starts
 * @param packageFolder
 *            until the target
 * @return package name as String
 */
public static String getJavaPackageName(Path packageRoot, Path packageFolder) {
  String diff = StringUtils.difference(packageRoot.toString(), packageFolder.toString());
  // remove seperators at the start
  if (diff.startsWith(java.io.File.separator)) {
    diff = diff.substring(1, diff.length());
  }
  return diff.replaceAll(java.io.File.separator, ".");
}

代码示例来源:origin: au.com.dius/pact-jvm-consumer_2.11

protected void putArray(DslPart object) {
  for(String matcherName: object.matchers.getMatchingRules().keySet()) {
    matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName));
  }
  generators.addGenerators(object.generators);
  if (StringUtils.isNotEmpty(object.rootName)) {
   body.put(object.rootName, object.getBody());
  } else {
   body.put(StringUtils.difference(this.rootPath, object.rootPath), object.getBody());
  }
}

代码示例来源:origin: au.com.dius/pact-jvm-consumer

protected void putArray(DslPart object) {
  for(String matcherName: object.matchers.getMatchingRules().keySet()) {
    matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName));
  }
  generators.addGenerators(object.generators);
  if (StringUtils.isNotEmpty(object.rootName)) {
   body.put(object.rootName, object.getBody());
  } else {
   body.put(StringUtils.difference(this.rootPath, object.rootPath), object.getBody());
  }
}

代码示例来源:origin: au.com.dius/pact-jvm-consumer_2.11

protected void putObject(DslPart object) {
  for (String matcherName: object.matchers.getMatchingRules().keySet()) {
    matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName));
  }
  generators.addGenerators(object.generators);
  String elementBase = StringUtils.difference(this.rootPath, object.rootPath);
  if (StringUtils.isNotEmpty(object.rootName)) {
   body.put(object.rootName, object.getBody());
  } else {
   String name = StringUtils.strip(elementBase, ".");
   Pattern p = Pattern.compile("\\['(.+)'\\]");
   Matcher matcher = p.matcher(name);
   if (matcher.matches()) {
    body.put(matcher.group(1), object.getBody());
   } else {
    body.put(name, object.getBody());
   }
  }
}

代码示例来源:origin: io.wcm.qa/io.wcm.qa.galenium.galenium

protected File getImageFile(String imagePath) throws IOException {
 String sampledImagesDirectory = getActualImagesDirectory();
 String path;
 if (StringUtils.isNotBlank(sampledImagesDirectory)) {
  String canonical1 = new File(getExpectedImagesDirectory()).getCanonicalPath();
  String canonical2 = new File(imagePath).getCanonicalPath();
  String difference = StringUtils.difference(canonical1, canonical2);
  trace("image path construction image dir: " + canonical1);
  trace("image path construction image path: " + canonical2);
  trace("image path construction difference: " + difference);
  path = sampledImagesDirectory + File.separator + difference;
 }
 else {
  path = imagePath;
 }
 File imageFile = new File(path);
 File parentFile = imageFile.getParentFile();
 if (!parentFile.isDirectory()) {
  debug("creating directory: " + parentFile.getPath());
  FileUtils.forceMkdir(parentFile);
 }
 return imageFile;
}

代码示例来源:origin: au.com.dius/pact-jvm-consumer

protected void putObject(DslPart object) {
  for (String matcherName: object.matchers.getMatchingRules().keySet()) {
    matchers.setRules(matcherName, object.matchers.getMatchingRules().get(matcherName));
  }
  generators.addGenerators(object.generators);
  String elementBase = StringUtils.difference(this.rootPath, object.rootPath);
  if (StringUtils.isNotEmpty(object.rootName)) {
   body.put(object.rootName, object.getBody());
  } else {
   String name = StringUtils.strip(elementBase, ".");
   Pattern p = Pattern.compile("\\['(.+)'\\]");
   Matcher matcher = p.matcher(name);
   if (matcher.matches()) {
    body.put(matcher.group(1), object.getBody());
   } else {
    body.put(name, object.getBody());
   }
  }
}

代码示例来源:origin: org.xworker/xworker_core

public static String difference(ActionContext actionContext){
  Thing self = actionContext.getObject("self");
  String str1  = (String) self.doAction("getStr1", actionContext);
  String str2  = (String) self.doAction("getStr2", actionContext);
  return StringUtils.difference(str1, str2);
}

代码示例来源:origin: io.wcm.qa/io.wcm.qa.galenium.galenium

try {
 getLogger().debug("Persisting " + SAMPLED_TEXTS.size() + " text samples.");
 String difference = StringUtils.difference(GaleniumConfiguration.getGalenSpecPath(), FILE_NAME_EXPECTED_TEXTS);
 File file = new File(FILE_NAME_ROOT_DIR_SAVE_SAMPLED_TEXTS, difference);
 file.getParentFile().mkdirs();

代码示例来源:origin: org.apache.servicecomb/service-registry

scSchemaContent,
  localSchemaContent);
String diffStringLocal = StringUtils.difference(scSchemaContent, localSchemaContent);
if (diffStringLocal.equals("")) {
 LOGGER.warn("Some APIs are deleted in local schema which are present in service center schema \n");

代码示例来源:origin: phoenixnap/springmvc-raml-plugin

if (segment.startsWith("{") && segment.endsWith("}")) {
  String peek = splitUrl[index - 1].toLowerCase();
  name = "By" + StringUtils.capitalize(difference(peek, segment.substring(1, segment.length() - 1)));
} else {
  String[] split = segment.split("[{}]");

代码示例来源:origin: Refactoring-Bot/Refactoring-Bot

String translatedPath = StringUtils.difference(gitConfig.getRepoFolder(), sonarIssuePath);

相关文章

微信公众号

最新文章

更多

StringUtils类方法