本文整理匯總了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);
}
}