Example usage for org.apache.commons.lang3 StringUtils split

List of usage examples for org.apache.commons.lang3 StringUtils split

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils split.

Prototype

public static String[] split(final String str, final String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:io.mapzone.controller.vm.http.ServiceAuthProvision.java

/**
 *
 *//*from ww  w  .  j ava 2  s.co m*/
protected boolean checkAuthToken() {
    ProjectInstanceIdentifier pid = new ProjectInstanceIdentifier(request.get());

    // check param token; ignore parameter char case
    Optional<String> requestToken = requestParameter(REQUEST_PARAM_TOKEN);
    if (requestToken.isPresent()) {
        if (!isValidToken(requestToken.get(), pid)) {
            throw new HttpProvisionRuntimeException(401, "Given auth token is not valid for this project.");
        }
        return true;
    }

    // check path parts
    String path = StringUtils.defaultString(request.get().getPathInfo());
    for (String part : StringUtils.split(path, '/')) {
        if (isValidToken(part, pid)) {
            return true;
        }
    }
    return false;
}

From source file:cn.guoyukun.spring.jpa.web.bind.method.annotation.SearchableMethodArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    String searchPrefix = getSearchPrefix(parameter);

    Map<String, String[]> searcheableMap = getPrefixParameterMap(searchPrefix, webRequest, true);

    boolean hasCustomSearchFilter = searcheableMap.size() > 0;

    SearchableDefaults searchDefaults = getSearchableDefaults(parameter);

    boolean needMergeDefault = searchDefaults != null && searchDefaults.merge();

    Searchable searchable = null;/*from  w ww  . j a v  a  2 s.c o m*/
    //
    if (needMergeDefault || !hasCustomSearchFilter) {
        searchable = getDefaultFromAnnotation(searchDefaults);
    }
    if (hasCustomSearchFilter) {
        if (searchable == null) {
            searchable = Searchable.newSearchable();
        }
        for (String name : searcheableMap.keySet()) {
            String[] mapValues = filterSearchValues(searcheableMap.get(name));

            if (mapValues.length == 1) {
                if (name.endsWith("in")) {
                    searchable.addSearchParam(name, StringUtils.split(mapValues[0], ",; "));
                } else {
                    searchable.addSearchParam(name, mapValues[0]);
                }
            } else {
                searchable.addSearchParam(name, mapValues);
            }
        }
    }

    Pageable pageable = (Pageable) pageableMethodArgumentResolver.resolveArgument(parameter, mavContainer,
            webRequest, binderFactory);
    //??
    if (searchDefaults == null) {
        searchable.setPage(pageable);
    }
    //needPage=true ??
    if (searchDefaults != null && searchDefaults.needPage()) {
        searchable.setPage(pageable);
    }
    //needPage=false needSort=true  ???
    if (searchDefaults != null && !searchDefaults.needPage() && searchDefaults.needSort()) {
        searchable.addSort(pageable.getSort());
    }

    return searchable;
}

From source file:com.cognifide.aet.job.common.comparators.statuscodes.StatusCodesFilterTest.java

private List<Integer> prepareFilterCodes(String filterCodesParam) {
    String[] split = StringUtils.split(filterCodesParam, ";");
    List<Integer> filterCodes = Lists.newArrayList();
    for (String item : split) {
        filterCodes.add(Integer.parseInt(item));
    }//from  w ww  . j a v  a2s.c om
    return filterCodes;
}

From source file:com.techcavern.wavetact.eventListeners.CTCPListener.java

@Override
public void onUnknown(UnknownEvent event) throws Exception {
    class process implements Runnable {
        public void run() {
            String[] message = StringUtils.split(event.getLine(), " ");
            if (message[1].equals("PRIVMSG") && StringUtils.isAlphanumeric(message[2])
                    && message[3].startsWith(":\u0001") && event.getLine().endsWith("\u0001")) {
                IRCUtils.sendLogChanMsg(event.getBot(), "[PM] " + IRCUtils.noPing(message[0]).replace(":", "")
                        + ": " + StringUtils.join(message, " ", 3, message.length).replace(":", ""));
            }//from  w  ww.j av  a2s  . c  o m
        }
    }
    Registry.threadPool.execute(new process());
}

From source file:com.brianscottrussell.gameoflife.GameGrid.java

/**
 * Constructor which builds a GameGrid object from the given String
 *
 * if there is an invalid header format then this will initialize the grid as 0x0, empty grid
 * if there is an invalid body format then this will initialize the grid as the header size, all Dead cells
 *
 * @param gridAsString String/*from   w  ww .jav  a 2s.c o  m*/
 */
public GameGrid(String gridAsString) {
    // initialize empty grid
    initializeGrid(0, 0);

    if (StringUtils.isNotBlank(gridAsString)) {
        // default the row & col counts to 0
        int rowCount = 0;
        int colCount = 0;

        // get row/col counts from input
        try {
            rowCount = parseRowCountFromInputString(gridAsString);
        } catch (InvalidGameGridInputException e) {
            // TODO: handle error?
            // System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage());
        }
        try {
            // get the character(s), before the 1st carriage return as the rowCount
            colCount = parseColumnCountFromInputString(gridAsString);
        } catch (InvalidGameGridInputException e) {
            // TODO: handle error?
            // System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage());
        }

        // only need to move forward if we retrieved valid row & col counts
        if (rowCount > 0 && colCount > 0) {
            // initialize grid
            initializeGrid(rowCount, colCount);

            // split the input string so that we're getting all lines of the string as rows, after the first line.
            //   this is the input Grid that will give us the starting point of each cell as Alive or Dead
            String[] gridRows = StringUtils.split(StringUtils.substringAfter(gridAsString, GameOfLife.LF),
                    GameOfLife.LF);
            // iterate over the rows of the grid
            // todo: improve from O(n^2)
            int rowIndex = 0;
            for (String row : gridRows) {
                // iterate over the chars of the row String
                int colIndex = 0;
                for (char symbol : row.toCharArray()) {
                    // check if a valid CellStatus symbol, otherwise skip it.
                    if (CellStatus.isValidCellStatusSymbol(symbol)) {
                        // if the cell is "alive", make it Alive in the CellStatus grid
                        this.grid[rowIndex][colIndex] = CellStatus.getCellStatusBySymbol(symbol);
                        colIndex++;
                    }
                }
                rowIndex++;
            }
        }
    }

    // start the generation at 1
    this.generation = 1;
}

From source file:com.neocotic.blingaer.common.dao.DAOLocator.java

/**
 * Retrieves the POJO implementation of the {@link DAO} {@code class}
 * provided./*from w  ww . j a  v  a  2s .  c o  m*/
 * <p>
 * Reflection is used to lookup the POJO implementation and delegate calls
 * to it.
 * 
 * @param cls
 *            the {@code DAO class} whose POJO implementation is to be
 *            located
 * @return the POJO implementation of the specified {@code class}
 * @throws BlingaerRuntimeException
 *             If an error occurs while loading/instantiating the new
 *             {@code Service class}.
 */
@SuppressWarnings("unchecked")
public <T extends DAO> T getDAO(Class<T> cls) throws BlingaerRuntimeException {
    LOG.trace("Entered method - getDAO");

    String className = cls.getName() + IMPL_CLASS_SUFFIX;

    // Injects datastore package name in to
    String[] arr = StringUtils.split(className, ClassUtils.PACKAGE_SEPARATOR_CHAR);
    arr = ArrayUtils.add(arr, arr.length - 1, dataStore);
    className = StringUtils.join(arr, ClassUtils.PACKAGE_SEPARATOR_CHAR);

    DAO impl = newDAOImpl(className);

    /*
     * Currently not caching these results as I'm not sure if it will have a
     * negative affect on objectify
     */

    LOG.trace("Exiting method - getDAO");

    return (T) impl;
}

From source file:com.xpn.xwiki.objects.classes.ListClass.java

public static List<String> getListFromString(String value, String separators, boolean withMap) {
    List<String> list = new ArrayList<String>();
    if (value == null) {
        return list;
    }/*from  w w  w  .j av a  2 s .c  o  m*/
    if (separators == null) {
        separators = "|";
    }

    String val = value;
    if (separators.length() == 1) {
        val = StringUtils.replace(val, "\\" + separators, "%PIPE%");
    }

    String[] result = StringUtils.split(val, separators);
    String item = "";
    for (int i = 0; i < result.length; i++) {
        String element = StringUtils.replace(result[i], "%PIPE%", separators);
        if (withMap && (element.indexOf('=') != -1)) {
            item = StringUtils.split(element, "=")[0];
        } else {
            item = element;
        }
        if (!item.trim().equals("")) {
            list.add(item);
        }
    }
    return list;
}

From source file:com.sonicle.webtop.core.sdk.ServiceVersion.java

public String getMajor() {
    if (isUndefined())
        return null;
    String[] tokens = StringUtils.split(this.version, ".");
    return tokens[0];
}

From source file:com.coveo.spillway.storage.RedisStorage.java

@Override
public Map<LimitKey, Integer> debugCurrentLimitCounters() {
    Map<LimitKey, Integer> counters = new HashMap<>();

    Set<String> keys = jedis.keys(keyPrefix + KEY_SEPARATOR + "*");
    for (String key : keys) {
        int value = Integer.parseInt(jedis.get(key));

        String[] keyComponents = StringUtils.split(key, KEY_SEPARATOR);

        counters.put(new LimitKey(keyComponents[1], keyComponents[2], keyComponents[3],
                Instant.parse(keyComponents[4])), value);
    }//from  w ww  .j  a  v a2s.  c o m

    return counters;
}

From source file:com.mingo.query.util.QueryUtils.java

/**
 * Validates composite id./*from w  w  w  .  j  a  v  a  2 s.  c om*/
 *
 * @param compositeId expected format ( [database-name].[collection-name].[query-id] )
 * @throws NullPointerException     {@link NullPointerException}
 * @throws IllegalArgumentException {@link IllegalArgumentException}
 *                                  if composite id is null, empty, contains only spaces or has wrong format.
 */
public static void validateCompositeId(String compositeId)
        throws NullPointerException, IllegalArgumentException {
    Validate.notBlank(compositeId, "compositeId cannot be null or empty");
    String[] elements = StringUtils.split(compositeId, ".");
    Validate.isTrue(elements.length == NUMBER_OF_ELEMENTS, "composite id should consist of three parts: "
            + "([database-name].[collection-name].[query-id]). current value: " + compositeId);
    for (int index = 0; index < elements.length; index++) {
        Validate.notBlank(elements[index], "element with position: " + (index + 1)
                + " in composite id is empty. current value: " + compositeId);
    }
}