本文整理汇总了Java中org.apache.commons.lang3.StringUtils.splitByWholeSeparatorPreserveAllTokens方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.splitByWholeSeparatorPreserveAllTokens方法的具体用法?Java StringUtils.splitByWholeSeparatorPreserveAllTokens怎么用?Java StringUtils.splitByWholeSeparatorPreserveAllTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.splitByWholeSeparatorPreserveAllTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sanitizeTopicName
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* 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;
}
示例2: sanitizeTopicFilter
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Validate the topic filter, add EMPTY and END, return as a List of levels
*
* @param topicFilter Topic Filter
* @return List of levels
*/
public static List<String> sanitizeTopicFilter(String topicFilter) {
if (StringUtils.isEmpty(topicFilter)) throw new IllegalArgumentException("Empty topic filer");
if (!topicFilter.contains("+") && !topicFilter.contains("#"))
throw new IllegalArgumentException("Topic filter does not contain wildcard");
List<String> levels = new ArrayList<>();
if (topicFilter.startsWith("/")) topicFilter = EMPTY + topicFilter;
if (topicFilter.endsWith("/")) topicFilter = topicFilter + EMPTY;
String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(topicFilter, "/");
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].contains("+") && !tokens[i].equals("+"))
throw new IllegalArgumentException("Illegal topic filter: " + topicFilter);
if (tokens[i].contains("#") && !tokens[i].equals("#"))
throw new IllegalArgumentException("Illegal topic filter: " + topicFilter);
if (tokens[i].equals("#") && !(i == tokens.length - 1 || (i == tokens.length - 2 && END.equals(tokens[i + 1]))))
throw new IllegalArgumentException("Illegal topic filter: " + topicFilter);
levels.add(StringUtils.isNotEmpty(tokens[i]) ? tokens[i] : EMPTY);
}
if (!topicFilter.endsWith(END)) levels.add(END);
return levels;
}
示例3: split
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@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);
}
}