当前位置: 首页>>代码示例>>Java>>正文


Java StringUtils.splitByWholeSeparatorPreserveAllTokens方法代码示例

本文整理汇总了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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:27,代码来源:Topics.java

示例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;
}
 
开发者ID:12315jack,项目名称:j1st-mqtt,代码行数:32,代码来源:Topics.java

示例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);
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:9,代码来源:SplitByWholeSeparator.java


注:本文中的org.apache.commons.lang3.StringUtils.splitByWholeSeparatorPreserveAllTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。