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

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

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

StringUtils.splitByWholeSeparator介绍

[英]Splits the provided text into an array, separator string specified.

The separator(s) will not be included in the returned String array. Adjacent separators are treated as one separator.

A null input String returns null. A null separator splits on whitespace.

StringUtils.splitByWholeSeparator(null, *)               = null 
StringUtils.splitByWholeSeparator("", *)                 = [] 
StringUtils.splitByWholeSeparator("ab de fg", null)      = ["ab", "de", "fg"] 
StringUtils.splitByWholeSeparator("ab   de fg", null)    = ["ab", "de", "fg"] 
StringUtils.splitByWholeSeparator("ab:cd:ef", ":")       = ["ab", "cd", "ef"] 
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]

[中]将提供的文本拆分为数组,并指定分隔符字符串。
分隔符将不包括在返回的字符串数组中。相邻分离器被视为一个分离器。
空输入字符串返回空值。空分隔符在空白处拆分。

StringUtils.splitByWholeSeparator(null, *)               = null 
StringUtils.splitByWholeSeparator("", *)                 = [] 
StringUtils.splitByWholeSeparator("ab de fg", null)      = ["ab", "de", "fg"] 
StringUtils.splitByWholeSeparator("ab   de fg", null)    = ["ab", "de", "fg"] 
StringUtils.splitByWholeSeparator("ab:cd:ef", ":")       = ["ab", "cd", "ef"] 
StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]

代码示例

代码示例来源:origin: zendesk/maxwell

private static void executeSQLInputStream(Connection connection, InputStream schemaSQL, String schemaDatabaseName) throws SQLException, IOException {
  BufferedReader r = new BufferedReader(new InputStreamReader(schemaSQL));
  String sql = "", line;
  if ( schemaDatabaseName != null ) {
    connection.createStatement().execute("CREATE DATABASE IF NOT EXISTS `" + schemaDatabaseName + "`");
    if (!connection.getCatalog().equals(schemaDatabaseName))
      connection.setCatalog(schemaDatabaseName);
  }
  while ((line = r.readLine()) != null) {
    sql += line + "\n";
  }
  for (String statement : StringUtils.splitByWholeSeparator(sql, "\n\n")) {
    if (statement.length() == 0)
      continue;
    connection.createStatement().execute(statement);
  }
}

代码示例来源:origin: gocd/gocd

Modification modificationFromDescription(String output, ConsoleResult result) throws P4OutputParseException {
  String[] parts = StringUtils.splitByWholeSeparator(output, SEPARATOR);
  Pattern pattern = Pattern.compile(DESCRIBE_OUTPUT_PATTERN, Pattern.MULTILINE);
  Matcher matcher = pattern.matcher(parts[0]);
  if (matcher.find()) {
    Modification modification = new Modification();
    parseFistline(modification, matcher.group(1), result);
    parseComment(matcher, modification);
    parseAffectedFiles(parts, modification);
    return modification;
  }
  throw new P4OutputParseException("Could not parse P4 description: " + output);
}

代码示例来源:origin: gocd/gocd

public void removeAssociations(String key, Element element) {
  if (element.getObjectValue() instanceof KeyList) {
    synchronized (key.intern()) {
      for (String subkey : (KeyList) element.getObjectValue()) {
        remove(compositeKey(key, subkey));
      }
    }
  } else if (key.contains(SUB_KEY_DELIMITER)) {
    String[] parts = StringUtils.splitByWholeSeparator(key, SUB_KEY_DELIMITER);
    String parentKey = parts[0];
    String childKey = parts[1];
    synchronized (parentKey.intern()) {
      Element parent = ehCache.get(parentKey);
      if (parent == null) {
        return;
      }
      KeyList subKeys = (KeyList) parent.getObjectValue();
      subKeys.remove(childKey);
    }
  }
}

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

@Test
public void testSplitByWholeString_StringStringBooleanInt() {
  assertArrayEquals(null, StringUtils.splitByWholeSeparator(null, ".", 3));
  assertEquals(0, StringUtils.splitByWholeSeparator("", ".", 3).length);
  final String stringToSplitOnNulls = "ab   de fg";
  final String[] splitOnNullExpectedResults = {"ab", "de fg"};
  //String[] splitOnNullExpectedResults = { "ab", "de" } ;
  final String[] splitOnNullResults = StringUtils.splitByWholeSeparator(stringToSplitOnNulls, null, 2);
  assertEquals(splitOnNullExpectedResults.length, splitOnNullResults.length);
  for (int i = 0; i < splitOnNullExpectedResults.length; i += 1) {
    assertEquals(splitOnNullExpectedResults[i], splitOnNullResults[i]);
  }
  final String stringToSplitOnCharactersAndString = "abstemiouslyaeiouyabstemiouslyaeiouyabstemiously";
  final String[] splitOnStringExpectedResults = {"abstemiously", "abstemiouslyaeiouyabstemiously"};
  //String[] splitOnStringExpectedResults = { "abstemiously", "abstemiously" } ;
  final String[] splitOnStringResults = StringUtils.splitByWholeSeparator(stringToSplitOnCharactersAndString, "aeiouy", 2);
  assertEquals(splitOnStringExpectedResults.length, splitOnStringResults.length);
  for (int i = 0; i < splitOnStringExpectedResults.length; i++) {
    assertEquals(splitOnStringExpectedResults[i], splitOnStringResults[i]);
  }
}

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

@Test
public void testSplitByWholeString_StringStringBoolean() {
  assertArrayEquals(null, StringUtils.splitByWholeSeparator(null, "."));
  assertEquals(0, StringUtils.splitByWholeSeparator("", ".").length);
  final String stringToSplitOnNulls = "ab   de fg";
  final String[] splitOnNullExpectedResults = {"ab", "de", "fg"};
  final String[] splitOnNullResults = StringUtils.splitByWholeSeparator(stringToSplitOnNulls, null);
  assertEquals(splitOnNullExpectedResults.length, splitOnNullResults.length);
  for (int i = 0; i < splitOnNullExpectedResults.length; i += 1) {
    assertEquals(splitOnNullExpectedResults[i], splitOnNullResults[i]);
  }
  final String stringToSplitOnCharactersAndString = "abstemiouslyaeiouyabstemiously";
  final String[] splitOnStringExpectedResults = {"abstemiously", "abstemiously"};
  final String[] splitOnStringResults = StringUtils.splitByWholeSeparator(stringToSplitOnCharactersAndString, "aeiouy");
  assertEquals(splitOnStringExpectedResults.length, splitOnStringResults.length);
  for (int i = 0; i < splitOnStringExpectedResults.length; i += 1) {
    assertEquals(splitOnStringExpectedResults[i], splitOnStringResults[i]);
  }
  final String[] splitWithMultipleSeparatorExpectedResults = {"ab", "cd", "ef"};
  final String[] splitWithMultipleSeparator = StringUtils.splitByWholeSeparator("ab:cd::ef", ":");
  assertEquals(splitWithMultipleSeparatorExpectedResults.length, splitWithMultipleSeparator.length);
  for (int i = 0; i < splitWithMultipleSeparatorExpectedResults.length; i++) {
    assertEquals(splitWithMultipleSeparatorExpectedResults[i], splitWithMultipleSeparator[i]);
  }
}

代码示例来源:origin: sanluan/PublicCMS

private Integer[] getCategoryIds(Boolean containChild, Integer categoryId, Integer[] categoryIds) {
  if (CommonUtils.empty(categoryId)) {
    return categoryIds;
  } else if (null != containChild && containChild) {
    CmsCategory category = categoryDao.getEntity(categoryId);
    if (null != category && CommonUtils.notEmpty(category.getChildIds())) {
      String[] categoryStringIds = ArrayUtils.add(
          StringUtils.splitByWholeSeparator(category.getChildIds(), CommonConstants.COMMA_DELIMITED),
          String.valueOf(categoryId));
      categoryIds = new Integer[categoryStringIds.length + 1];
      for (int i = 0; i < categoryStringIds.length; i++) {
        categoryIds[i] = Integer.parseInt(categoryStringIds[i]);
      }
      categoryIds[categoryStringIds.length] = categoryId;
    }
  } else {
    categoryIds = new Integer[] { categoryId };
  }
  return categoryIds;
}

代码示例来源:origin: sanluan/PublicCMS

private Integer[] getCategoryIds(Boolean containChild, Integer categoryId, Integer[] categoryIds) {
  if (CommonUtils.empty(categoryId)) {
    return categoryIds;
  } else if (null != containChild && containChild) {
    CmsCategory category = categoryDao.getEntity(categoryId);
    if (null != category && CommonUtils.notEmpty(category.getChildIds())) {
      String[] categoryStringIds = ArrayUtils.add(
          StringUtils.splitByWholeSeparator(category.getChildIds(), CommonConstants.COMMA_DELIMITED),
          String.valueOf(categoryId));
      categoryIds = new Integer[categoryStringIds.length + 1];
      for (int i = 0; i < categoryStringIds.length; i++) {
        categoryIds[i] = Integer.parseInt(categoryStringIds[i]);
      }
      categoryIds[categoryStringIds.length] = categoryId;
    }
  } else {
    categoryIds = new Integer[] { categoryId };
  }
  return categoryIds;
}

代码示例来源:origin: sanluan/PublicCMS

@SuppressWarnings("unchecked")
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
  String text = getString(0, arguments);
  Integer pageIndex = getInteger(1, arguments);
  if (CommonUtils.notEmpty(text)) {
    String pageBreakTag = null;
    if (-1 < text.indexOf(CommonConstants.getCkeditorPageBreakTag())) {
      pageBreakTag = CommonConstants.getCkeditorPageBreakTag();
    } else if(-1 < text.indexOf(CommonConstants.getKindEditorPageBreakTag())){
      pageBreakTag = CommonConstants.getKindEditorPageBreakTag();
    } else {
      pageBreakTag = CommonConstants.getUeditorPageBreakTag();
    }
    String[] texts = StringUtils.splitByWholeSeparator(text, pageBreakTag);
    PageHandler page = new PageHandler(pageIndex, 1, texts.length, null);
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("page", page);
    resultMap.put("text", texts[page.getPageIndex() - 1]);
    return resultMap;
  }
  return null;
}

代码示例来源:origin: sanluan/PublicCMS

@SuppressWarnings("unchecked")
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
  String text = getString(0, arguments);
  Integer pageIndex = getInteger(1, arguments);
  if (CommonUtils.notEmpty(text)) {
    String pageBreakTag = null;
    if (-1 < text.indexOf(CommonConstants.getCkeditorPageBreakTag())) {
      pageBreakTag = CommonConstants.getCkeditorPageBreakTag();
    } else if(-1 < text.indexOf(CommonConstants.getKindEditorPageBreakTag())){
      pageBreakTag = CommonConstants.getKindEditorPageBreakTag();
    } else {
      pageBreakTag = CommonConstants.getUeditorPageBreakTag();
    }
    String[] texts = StringUtils.splitByWholeSeparator(text, pageBreakTag);
    PageHandler page = new PageHandler(pageIndex, 1, texts.length, null);
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("page", page);
    resultMap.put("text", texts[page.getPageIndex() - 1]);
    return resultMap;
  }
  return null;
}

代码示例来源:origin: sanluan/PublicCMS

pageBreakTag = CommonConstants.getUeditorPageBreakTag();
String[] texts = StringUtils.splitByWholeSeparator(attribute.getText(), pageBreakTag);
if (createMultiContentPage) {
  for (int i = 1; i < texts.length; i++) {

代码示例来源:origin: sanluan/PublicCMS

pageBreakTag = CommonConstants.getUeditorPageBreakTag();
String[] texts = StringUtils.splitByWholeSeparator(attribute.getText(), pageBreakTag);
if (createMultiContentPage) {
  for (int i = 1; i < texts.length; i++) {

代码示例来源:origin: wenbo2018/fox

/**
   * 分割固定格式的字符串
   */
  public static String[] split(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
  }
}

代码示例来源:origin: vakinge/oneplatform

public String getRouteName() {
  if(routeName == null){
    routeName = StringUtils.splitByWholeSeparator(identifier, "-")[0];
  }
  return routeName;
}
public void setRouteName(String routeName) {

代码示例来源:origin: jhpoelen/eol-globi-data

static Map<String, String> parseDynamicProperties(String s) {
  Map<String, String> properties = new HashMap<>();
  String[] parts = StringUtils.splitByWholeSeparator(s, ";");
  for (String part : parts) {
    String[] propertyValue = StringUtils.splitByWholeSeparator(part, ":", 2);
    if (propertyValue.length == 2) {
      properties.put(StringUtils.trim(propertyValue[0]), StringUtils.trim(propertyValue[1]));
    }
  }
  return properties;
}

代码示例来源:origin: jhpoelen/eol-globi-data

private void addDelimitedList(List<String> externalIds, String path) {
    String[] pathElements = StringUtils.splitByWholeSeparator(path, CharsetConstant.SEPARATOR);
    if (pathElements != null) {
      externalIds.addAll(Arrays.asList(pathElements));
    }
  }
}

代码示例来源:origin: BriData/DBus

public static void main(String[] args) {
    String value = "bbb123aaa456aaccc";
    String value2 = "bbb123aaa2456aaccc";
    System.out.println(Arrays.asList(value.split("\\d{3}")));
    System.out.println(Arrays.asList(value2.split("23")));
    System.out.println(Arrays.asList(StringUtils.splitByWholeSeparator(value2, "23")));
  }
}

代码示例来源:origin: OpenAttestation/OpenAttestation

public static List<X509Certificate> decodePemCertificates(String text) throws CertificateException {
  String[] pems = StringUtils.splitByWholeSeparator(text, END_CERTIFICATE);
  ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>(pems.length);
  for(String pem : pems) {
    if( pem.trim().isEmpty() ) { continue; }
    certs.add(decodePemCertificate(pem));
  }
  return certs;
}

代码示例来源:origin: Jimmy-Shi/bean-query

private PropertySelector createPropertySelector(String propertyString) {
 String[] propertyTokens = StringUtils.splitByWholeSeparator(propertyString, " as ", 2);
 final PropertySelector propertySelector;
 String propertySelectorPropertyName = propertyTokens[0].trim();
 if (propertyTokens.length == 2) {
  String propertySelectorAlias = propertyTokens[1].trim();
  propertySelector = new PropertySelector(propertySelectorPropertyName, propertySelectorAlias);
 } else {
  propertySelector = new PropertySelector(propertySelectorPropertyName);
 }
 return propertySelector;
}

代码示例来源:origin: vakinge/jeesuite-libs

public List<String> getGroups(){
  if(asyncEventBus != null){
    List<String> groups = new ArrayList<>();
    Set<String> jobKeys = JobContext.getContext().getAllJobs().keySet();
    for (String jobKey : jobKeys) {
      groups.add(StringUtils.splitByWholeSeparator(jobKey, ":")[0]);
    }
    return groups;
  }
  String path = ZkJobRegistry.ROOT.substring(0,ZkJobRegistry.ROOT.length() - 1);
  return zkClient.getChildren(path);
}

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

public static String[] splitByWholeSeparator(ActionContext actionContext){
  Thing self = actionContext.getObject("self");
  String str  = (String) self.doAction("getStr", actionContext);
  String separator  = (String) self.doAction("getSeparator", actionContext);
  Integer max  = (Integer) self.doAction("getMax", actionContext);
  return StringUtils.splitByWholeSeparator(str, separator, max);
}

相关文章

StringUtils类方法