Example usage for org.apache.commons.lang StringUtils splitByWholeSeparator

List of usage examples for org.apache.commons.lang StringUtils splitByWholeSeparator

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitByWholeSeparator.

Prototype

public static String[] splitByWholeSeparator(String str, String separator) 

Source Link

Document

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

Usage

From source file:com.ewcms.publication.uri.RuleParse.java

/**
 * ?uri??/*from w  w w.j a va2 s. co m*/
 * 
 * @param patter
 *            uri
 * @return  key:?? value:?
 */
private static Map<String, String> parseVariables(String patter) {
    Map<String, String> variables = new HashMap<String, String>();
    if (!StringUtils.contains(patter, VARIABLE_START)) {
        return variables;
    }
    String[] tokens = StringUtils.splitByWholeSeparator(patter, VARIABLE_START);
    for (String token : tokens) {
        logger.debug("Token with ${{}", token);
        if (!StringUtils.contains(token, "}")) {
            logger.warn("\"{}\" is not closed", token);
            continue;
        }
        String value = StringUtils.split(token, VARIABLE_END)[0];
        if (StringUtils.isBlank(value)) {
            logger.warn("Variable's nam is null");
            continue;
        }
        logger.debug("variable is {}", value);
        String[] s = StringUtils.splitByWholeSeparator(value, VARIABLE_FORMAT);
        if (s.length == 1) {
            variables.put(s[0], null);
        } else {
            variables.put(s[0], s[1]);
        }
    }
    return variables;
}

From source file:com.codeabovelab.dm.cluman.cluster.docker.model.PortBinding.java

public static PortBinding parse(String serialized) throws IllegalArgumentException {
    try {//from  w  ww  . ja va  2 s  . co  m
        String[] parts = StringUtils.splitByWholeSeparator(serialized, ":");
        switch (parts.length) {
        case 3:
            // 127.0.0.1:80:8080/tcp
            return createFromSubstrings(parts[0] + ":" + parts[1], parts[2]);
        case 2:
            // 80:8080 // 127.0.0.1::8080
            return createFromSubstrings(parts[0], parts[1]);
        case 1:
            // 8080
            return createFromSubstrings("", parts[0]);
        default:
            throw new IllegalArgumentException();
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Error parsing PortBinding '" + serialized + "'", e);
    }
}

From source file:cn.fastmc.core.jpa.specification.Specifications.java

/**
 * ???/*from  w  w w .j av  a 2s .c  o m*/
 * 
 * @param propertyName ??
 * @param root Query roots always reference entities
 * 
 * @return {@link Path}
 */
public static Path<?> getPath(String propertyName, Root<?> root) {

    Path<?> path = null;

    if (StringUtils.contains(propertyName, ".")) {
        String[] propertys = StringUtils.splitByWholeSeparator(propertyName, ".");
        path = root.get(propertys[0]);
        for (int i = 1; i < propertys.length; i++) {
            path = path.get(propertys[i]);
        }
    } else {
        path = root.get(propertyName);
    }

    return path;
}

From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java

/**
 * Split components of a line, with an optional starting string and a component separator.
 * Adjacent separators are treated as one separator.
 * This method does not validate the starting string presence, it just strips it if present.
 * this methods uses {@link StringUtils#splitByWholeSeparator(String, String)}
 *
 * @param line the string to parse/*ww  w  . j  a  v a 2 s . co  m*/
 * @param starting an optional starting string
 * @param separator the components separator
 * @return a list of String with the found components or an empty list if none is found
 */
public static List<String> splitComponents(final String line, final String starting, final String separator) {
    final ArrayList<String> result = new ArrayList<String>();

    if (StringUtils.isNotBlank(line)) {
        String lineNoPrefix = removePrefix(line, starting);

        if (StringUtils.isNotBlank(separator)) {
            final String[] tokens = StringUtils.splitByWholeSeparator(lineNoPrefix, separator);
            //add not empty tokens to result
            for (int i = 0; i < tokens.length; i++) {
                if (StringUtils.isNotBlank(tokens[i])) {
                    result.add(tokens[i]);
                }
            }
        } else {
            result.add(lineNoPrefix);
        }
    }
    return result;
}

From source file:it.csi.iride2.iridefed.entity.Role.java

/**
 * Utility method to parse an <code>IRIDE</code> Role mnemonic string representation.<br />
 * It accepts a mnemonic string representation, expressed with the following format: <code>"role code{@link #SEPARATOR}domain code"</code>.
 *
 * @param mnemonic <code>IRIDE</code> Role mnemonic string representation
 * @return an <code>IRIDE</code> Role entity object
 * @throws IllegalArgumentException if the given mnemonic string representation is not in the expected format
 *//*from   w w w  . j av a  2s  .co  m*/
public static Role parseRole(String mnemonic) {
    final String[] tokens = StringUtils.splitByWholeSeparator(mnemonic, SEPARATOR);
    if (ArrayUtils.getLength(tokens) != 2) {
        throw new IllegalArgumentException(mnemonic);
    }

    return new Role(tokens[0], tokens[1]);
}

From source file:com.dianping.squirrel.client.config.listener.SingleCacheRemoveListener.java

public void handleMessage(SingleCacheRemoveDTO cacheRemoveDTO) {
    if (cacheRemoveDTO != null) {
        List<String> destinations = cacheRemoveDTO.getDestinations();
        if (serverIp == null) {
            serverIp = IPUtils.getFirstNoLoopbackIP4Address();
        }// ww w . j a v a 2  s .  c o  m
        if (destinations == null || destinations.contains(serverIp)) {
            String cacheType = cacheRemoveDTO.getCacheType();
            String cacheKeys = cacheRemoveDTO.getCacheKey();
            StoreClient cacheClient = StoreClientConfigManager.getInstance().findCacheClient(cacheType);
            if (cacheClient != null) {
                String[] keyList = StringUtils.splitByWholeSeparator(cacheKeys, CACHE_FINAL_KEY_SEP);
                if (keyList != null) {
                    List<String> failedKeys = new ArrayList<String>();
                    List<String> removedKeys = new ArrayList<String>();
                    Throwable lastError = null;
                    for (String finalKey : keyList) {
                        try {
                            cacheClient.delete(finalKey);
                            removedKeys.add(finalKey);
                        } catch (Throwable e) {
                            failedKeys.add(finalKey);
                            lastError = e;
                        }
                    }
                    if (!failedKeys.isEmpty()) {
                        logger.warn(String.format("failed to clear cache key %s: failed keys %s, error %s",
                                cacheKeys, StringUtils.join(failedKeys, ','), lastError));
                    } else if (!removedKeys.isEmpty()) {
                        logger.warn(String.format("cleard cache key %s: removed keys %s", cacheKeys,
                                StringUtils.join(removedKeys, ',')));
                    }
                }
            } else {
                logger.error("failed to clear cache key [" + cacheKeys + "]: no cache client found");
            }
        }
    }
}

From source file:com.dianping.avatar.cache.listener.SingleCacheRemoveListener.java

public void handleMessage(SingleCacheRemoveDTO cacheRemoveDTO) {
    if (cacheRemoveDTO != null) {
        List<String> destinations = cacheRemoveDTO.getDestinations();
        String serverIp = IPUtils.getFirstNoLoopbackIP4Address();
        if (destinations == null || destinations.contains(serverIp)) {
            String cacheType = cacheRemoveDTO.getCacheType();
            String cacheKeys = cacheRemoveDTO.getCacheKey();
            CacheClient cacheClient = cacheClientFactory.findCacheClient(cacheType);
            if (cacheClient != null) {
                String[] keyList = StringUtils.splitByWholeSeparator(cacheKeys, CACHE_FINAL_KEY_SEP);
                if (keyList != null) {
                    List<String> failedKeys = new ArrayList<String>();
                    Throwable lastError = null;
                    for (String finalKey : keyList) {
                        try {
                            cacheClient.remove(finalKey, getCategory(finalKey));
                        } catch (Throwable e) {
                            failedKeys.add(finalKey);
                            lastError = e;
                        }//from   w  w w.j  a  va2s .c  o m
                    }
                    if (!failedKeys.isEmpty()) {
                        logger.info("Clear cache with key[" + cacheKeys + "] from cache[" + cacheType
                                + "], but [" + StringUtils.join(failedKeys, ',') + "] failed.", lastError);
                    } else {
                        logger.info("Clear cache with key[" + cacheKeys + "] from cache[" + cacheType
                                + "] succeed.");
                    }
                }
            } else {
                logger.error("Clear cache with key[" + cacheKeys + "] failed, because cache[" + cacheType
                        + "] not found.");
            }
        }
    }
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResolver.java

/**
 *
 * @param text Text to use as base for resolving
 * @param classPath/*from  ww w  .ja  va  2 s.  c o  m*/
 */
public MemberLookupResolver(String text, ClassPath classPath) {
    super(classPath);
    this.commands = StringUtils.splitByWholeSeparator(text, "data-sly-");
}

From source file:com.bjwg.back.util.PropertyFilter.java

/**
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value/* www . j  a  v  a2  s .c o m*/
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(filterName, e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), filterName);
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:cn.hxh.springside.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*from  ww  w . j a v a  2  s .  c o  m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}