本文整理了Java中org.apache.commons.lang3.StringUtils.splitByWholeSeparatorPreserveAllTokens()
方法的一些代码示例,展示了StringUtils.splitByWholeSeparatorPreserveAllTokens()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.splitByWholeSeparatorPreserveAllTokens()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:splitByWholeSeparatorPreserveAllTokens
[英]Splits the provided text into an array, separator string specified.
The separator is not included in the returned String array. Adjacent separators are treated as separators for empty tokens. For more control over the split use the StrTokenizer class.
A null input String returns null. A null separator splits on whitespace.
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
[中]将提供的文本拆分为数组,并指定分隔符字符串。
返回的字符串数组中不包括分隔符。相邻的分隔符被视为空令牌的分隔符。要获得对拆分的更多控制,请使用StrTokenizer类。
空输入字符串返回空值。空分隔符在空白处拆分。
StringUtils.splitByWholeSeparatorPreserveAllTokens(null, *) = null
StringUtils.splitByWholeSeparatorPreserveAllTokens("", *) = []
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null) = ["ab", "", "", "de", "fg"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab:cd:ef", ":") = ["ab", "cd", "ef"]
StringUtils.splitByWholeSeparatorPreserveAllTokens("ab-!-cd-!-ef", "-!-") = ["ab", "cd", "ef"]
代码示例来源:origin: apache/nifi
/**
* Tokenizes the specified proxy chain.
*
* @param rawProxyChain raw chain
* @return tokenized proxy chain
*/
public static List<String> tokenizeProxiedEntitiesChain(String rawProxyChain) {
final List<String> proxyChain = new ArrayList<>();
if (!StringUtils.isEmpty(rawProxyChain)) {
// Split the String on the >< token
List<String> elements = Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(rawProxyChain, "><"));
// Unsanitize each DN and collect back
elements = elements.stream().map(ProxiedEntitiesUtils::unsanitizeDn).collect(Collectors.toList());
// Remove the leading < from the first element
elements.set(0, elements.get(0).replaceFirst(LT, ""));
// Remove the trailing > from the last element
int last = elements.size() - 1;
String lastElement = elements.get(last);
if (lastElement.endsWith(GT)) {
elements.set(last, lastElement.substring(0, lastElement.length() - 1));
}
proxyChain.addAll(elements);
}
return proxyChain;
}
代码示例来源:origin: zendesk/maxwell
enumValues = StringUtils.splitByWholeSeparatorPreserveAllTokens(columnEnumValues, ",");
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSplitByWholeSeparatorPreserveAllTokens_StringString() {
assertArrayEquals(null, StringUtils.splitByWholeSeparatorPreserveAllTokens(null, "."));
assertEquals(0, StringUtils.splitByWholeSeparatorPreserveAllTokens("", ".").length);
// test whitespace
String input = "ab de fg";
String[] expected = new String[]{"ab", "", "", "de", "fg"};
String[] actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, null);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
assertEquals(expected[i], actual[i]);
}
// test delimiter singlechar
input = "1::2:::3::::4";
expected = new String[]{"1", "", "2", "", "", "3", "", "", "", "4"};
actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, ":");
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
assertEquals(expected[i], actual[i]);
}
// test delimiter multichar
input = "1::2:::3::::4";
expected = new String[]{"1", "2", ":3", "", "4"};
actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, "::");
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
assertEquals(expected[i], actual[i]);
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSplitByWholeSeparatorPreserveAllTokens_StringStringInt() {
assertArrayEquals(null, StringUtils.splitByWholeSeparatorPreserveAllTokens(null, ".", -1));
assertEquals(0, StringUtils.splitByWholeSeparatorPreserveAllTokens("", ".", -1).length);
String[] expected = new String[]{"ab", "", "", "de", "fg"};
String[] actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, null, -1);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
expected = new String[]{"1", "", "2", "", "", "3", "", "", "", "4"};
actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, ":", -1);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
expected = new String[]{"1", "2", ":3", "", "4"};
actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, "::", -1);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
expected = new String[]{"1", "", "2", ":3:4"};
actual = StringUtils.splitByWholeSeparatorPreserveAllTokens(input, ":", 4);
assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i += 1) {
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
@Bean
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
Map<String, Filter> filters = shiroFilterFactoryBean.getFilters();//获取filters
filters.put("user", new CustomUserFilter());
// 设置 securityManager
shiroFilterFactoryBean.setSecurityManager(securityManager);
// 登录的 url
shiroFilterFactoryBean.setLoginUrl(febsProperties.getShiro().getLoginUrl());
// 登录成功后跳转的 url
shiroFilterFactoryBean.setSuccessUrl(febsProperties.getShiro().getSuccessUrl());
// 未授权 url
shiroFilterFactoryBean.setUnauthorizedUrl(febsProperties.getShiro().getUnauthorizedUrl());
LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();
// 设置免认证 url
String[] anonUrls = StringUtils.splitByWholeSeparatorPreserveAllTokens(febsProperties.getShiro().getAnonUrl(), ",");
for (String url : anonUrls) {
filterChainDefinitionMap.put(url, "anon");
}
// 配置退出过滤器,其中具体的退出代码 Shiro已经替我们实现了
filterChainDefinitionMap.put(febsProperties.getShiro().getLogoutUrl(), "logout");
// 除上以外所有 url都必须认证通过才可以访问,未通过认证自动访问 LoginUrl
filterChainDefinitionMap.put("/**", "user");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
代码示例来源:origin: jhpoelen/eol-globi-data
public static String[] splitPipes(String aline) {
return StringUtils.splitByWholeSeparatorPreserveAllTokens(aline, CharsetConstant.SEPARATOR_CHAR);
}
}
代码示例来源:origin: jhpoelen/eol-globi-data
public static String[] splitTSV(String aline) {
return StringUtils.splitByWholeSeparatorPreserveAllTokens(aline, "\t");
}
public static String[] splitPipes(String aline) {
代码示例来源:origin: CloudSlang/cs-actions
/**
* Splits the stringArray by the delimiter into an array of strings without ignoring the escaped delimiters
*
* @param stringArray the string to be split
* @param delimiter the delimiter by which to split the stringArray
* @return an array of Strings
*/
@NotNull
public static String[] toArrayWithEscaped(@Nullable final String stringArray, @NotNull final String delimiter) {
if (StringUtils.isEmpty(stringArray)) {
return new String[0];
}
return StringUtils.splitByWholeSeparatorPreserveAllTokens(stringArray, delimiter);
}
代码示例来源:origin: io.cloudslang.content/cs-commons
/**
* Splits the stringArray by the delimiter into an array of strings without ignoring the escaped delimiters
*
* @param stringArray the string to be split
* @param delimiter the delimiter by which to split the stringArray
* @return an array of Strings
*/
@NotNull
public static String[] toArrayWithEscaped(@Nullable final String stringArray, @NotNull final String delimiter) {
if (StringUtils.isEmpty(stringArray)) {
return new String[0];
}
return StringUtils.splitByWholeSeparatorPreserveAllTokens(stringArray, delimiter);
}
代码示例来源:origin: au.gov.amsa.risky/ais
/**
* Returns the items from the comma delimited NMEA line. The last item
* always contains a * followed by a checksum. If * is not present
* {@link IndexOutOfBoundsException} will be thrown.
*
* @param line
* @return
*/
private static String[] getNmeaItems(String line) {
String[] items = StringUtils.splitByWholeSeparatorPreserveAllTokens(line,
PARAMETER_DELIMITER);
// remove the checksum from the end
String last = items[items.length - 1];
if (last.contains("*"))
items[items.length - 1] = last.substring(0, last.lastIndexOf('*'));
return items;
}
代码示例来源:origin: ribasco/async-gamequery-lib
/**
* <p>A Simply utility method for parsing Content-Type which contains parameters</p>
*
* @param contentType A {@link String} containing the Content-Type
*
* @return The parsed content-type {@link String} excluding the parameters
*/
private String parseContentType(String contentType) {
if (!StringUtils.isEmpty(contentType) && contentType.contains(";")) {
String[] types = StringUtils.splitByWholeSeparatorPreserveAllTokens(contentType, ";", 2);
if (types != null && types.length > 1)
return types[0].trim();
}
return contentType;
}
代码示例来源:origin: virjar/vscrawler
@Override
protected String[] split(String str, String separatorChars, int max, boolean preserveAllTokens) {
if (preserveAllTokens) {
return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separatorChars, max);
} else {
return StringUtils.splitByWholeSeparator(str, separatorChars, max);
}
}
代码示例来源:origin: io.wcm/io.wcm.handler.richtext
private List<Content> processPlainText(String text) {
if (StringUtils.isBlank(text)) {
return ImmutableList.of();
}
List<Content> content = new ArrayList<>();
String[] lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(text, "\n");
for (int i = 0; i < lines.length; i++) {
if (i > 0) {
content.add(new Element("br"));
}
content.add(new Text(lines[i]));
}
return ImmutableList.copyOf(content);
}
代码示例来源:origin: longkerdandy/mithqtt
/**
* Validate the topic name, add EMPTY and END, return as a List of levels
* No wildcard allowed!
*
* @param topicName Topic Name
* @return List of levels
*/
public static List<String> sanitizeTopicName(String topicName) {
if (StringUtils.isEmpty(topicName)) throw new IllegalArgumentException("Empty topic name");
if (topicName.contains("+")) throw new IllegalArgumentException("Topic name contains wildcard");
if (topicName.contains("#")) throw new IllegalArgumentException("Topic name contains wildcard");
List<String> levels = new ArrayList<>();
if (topicName.startsWith("/")) topicName = EMPTY + topicName;
if (topicName.endsWith("/")) topicName = topicName + EMPTY;
String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicName, "/");
for (String token : tokens) {
levels.add(StringUtils.isNotEmpty(token) ? token : EMPTY);
}
if (!topicName.endsWith(END)) levels.add(END);
return levels;
}
代码示例来源:origin: co.cask.wrangler/wrangler-core
private static void loadPatterns(String patternFileName, List<Map<Pattern, String>> patternParsers) throws IOException {
InputStream stream = DateTimePattern.class.getClassLoader().getResourceAsStream(patternFileName);
try {
List<String> lines = IOUtils.readLines(stream, "UTF-8");
Map<Pattern, String> currentGroupMap = new LinkedHashMap<Pattern, String>();
patternParsers.add(currentGroupMap);
for (String line : lines) {
if (!"".equals(line.trim())) { // Not empty
if (line.startsWith("--")) { // group separator
currentGroupMap = new LinkedHashMap<Pattern, String>();
patternParsers.add(currentGroupMap);
} else {
String[] lineArray = StringUtils.splitByWholeSeparatorPreserveAllTokens(line, "\t");
String format = lineArray[0];
Pattern pattern = Pattern.compile(lineArray[1]);
currentGroupMap.put(pattern, format);
}
}
}
stream.close();
} catch (IOException e) {
// Throw exception
}
}
代码示例来源:origin: org.apache.nifi.registry/nifi-registry-security-utils
/**
* Tokenizes the specified proxy chain.
*
* @param rawProxyChain raw chain
* @return tokenized proxy chain
*/
public static List<String> tokenizeProxiedEntitiesChain(String rawProxyChain) {
final List<String> proxyChain = new ArrayList<>();
if (!StringUtils.isEmpty(rawProxyChain)) {
// Split the String on the >< token
List<String> elements = Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(rawProxyChain, "><"));
// Unsanitize each DN and collect back
elements = elements.stream().map(ProxiedEntitiesUtils::unsanitizeDn).collect(Collectors.toList());
// Remove the leading < from the first element
elements.set(0, elements.get(0).replaceFirst(LT, ""));
// Remove the trailing > from the last element
int last = elements.size() - 1;
String lastElement = elements.get(last);
if (lastElement.endsWith(GT)) {
elements.set(last, lastElement.substring(0, lastElement.length() - 1));
}
proxyChain.addAll(elements);
}
return proxyChain;
}
代码示例来源:origin: org.apache.nifi/nifi-web-security
/**
* Tokenizes the specified proxy chain.
*
* @param rawProxyChain raw chain
* @return tokenized proxy chain
*/
public static List<String> tokenizeProxiedEntitiesChain(String rawProxyChain) {
final List<String> proxyChain = new ArrayList<>();
if (!StringUtils.isEmpty(rawProxyChain)) {
// Split the String on the >< token
List<String> elements = Arrays.asList(StringUtils.splitByWholeSeparatorPreserveAllTokens(rawProxyChain, "><"));
// Unsanitize each DN and collect back
elements = elements.stream().map(ProxiedEntitiesUtils::unsanitizeDn).collect(Collectors.toList());
// Remove the leading < from the first element
elements.set(0, elements.get(0).replaceFirst(LT, ""));
// Remove the trailing > from the last element
int last = elements.size() - 1;
String lastElement = elements.get(last);
if (lastElement.endsWith(GT)) {
elements.set(last, lastElement.substring(0, lastElement.length() - 1));
}
proxyChain.addAll(elements);
}
return proxyChain;
}
代码示例来源:origin: org.xworker/xworker_core
public static String[] splitByWholeSeparatorPreserveAllTokens(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.splitByWholeSeparatorPreserveAllTokens(str, separator, max);
}
代码示例来源:origin: opencb/opencga
@Override
public QueryResult<PermissionRule> getPermissionRules(long studyId, Study.Entity entry) throws CatalogDBException {
// Get permission rules from study
Query query = new Query(QueryParams.UID.key(), studyId);
QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, QueryParams.PERMISSION_RULES.key());
QueryResult<Study> studyQueryResult = get(query, options);
if (studyQueryResult.getNumResults() == 0) {
throw new CatalogDBException("Unexpected error: Study " + studyId + " not found");
}
List<PermissionRule> permissionRules = studyQueryResult.first().getPermissionRules().get(entry);
if (permissionRules == null) {
permissionRules = Collections.emptyList();
}
// Remove all permission rules that are pending of some actions such as deletion
permissionRules.removeIf(permissionRule ->
StringUtils.splitByWholeSeparatorPreserveAllTokens(permissionRule.getId(), INTERNAL_DELIMITER, 2).length == 2);
return new QueryResult<>(String.valueOf(studyId), studyQueryResult.getDbTime(), permissionRules.size(), permissionRules.size(),
"", "", permissionRules);
}
代码示例来源:origin: org.xwiki.rendering/xwiki-rendering-syntax-xhtml
@Override
public ResourceReference parse(String rawReference)
{
String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR);
boolean isTyped = "true".equalsIgnoreCase(tokens[0]);
ResourceType type = new ResourceType(tokens[1]);
String reference = tokens[2];
ResourceReference resourceReference = new ResourceReference(reference, type);
resourceReference.setTyped(isTyped);
if (tokens.length == 4) {
for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) {
resourceReference.setParameter(parameter.getKey(), parameter.getValue());
}
}
return resourceReference;
}
}
内容来源于网络,如有侵权,请联系作者删除!