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:it.attocchi.utils.StringFunc.java

public static List<String> readLines(String aText) {
    List<String> res = null;

    if (StringUtils.isNotBlank(aText))
        res = Arrays.asList(StringUtils.split(aText, NEW_LINE));

    return res;/*  ww  w  .j av a 2s .c  o m*/
}

From source file:com.cognifide.qa.bb.aem.core.sidepanel.internal.ComponentTreeLocatorHelper.java

/**
 * Search component on tree// www  . j  ava 2  s.  c  o  m
 *
 * @param path          how many containers is between
 * @param componentName component name
 * @param elementNumber which component (default 0) it there is more then one
 * @param currentScope
 * @return
 */
public static WebElement getComponentWebElement(String path, String componentName, int elementNumber,
        WebElement currentScope) {
    String[] containers = StringUtils.split(path, "/");
    WebElement component = currentScope;
    for (String container : containers) {
        component = setComponent(component, container);
    }

    List<WebElement> elements = component.findElement(By.cssSelector(".coral3-Tree-subTree"))
            .findElements(By.xpath(String.format(COMPONENT_ITEM_XPATH_FORMAT, componentName, componentName)));
    if (!elements.isEmpty()) {
        component = elements.get(elementNumber);
    }
    return component;
}

From source file:edu.illinois.cs.cogcomp.wikifier.utils.io.CSVAdapter.java

@Override
public List<String> unmarshal(String v) throws Exception {
    return new ArrayList<String>(Arrays.asList(StringUtils.split(v, ',')));
}

From source file:com.yiji.openapi.sdk.util.Reflections.java

public static List<Object> invokeGetter(Object obj, String[] propertyNames) {
    List<Object> list = new ArrayList<Object>(propertyNames.length);
    for (String propertyName : propertyNames) {
        Object propertyValue = null;
        if (StringUtils.contains(propertyName, ".")) {
            String[] propertyNamePaths = StringUtils.split(propertyName, ".");
            Object temp = obj;//from ww w  .  ja  v  a2 s  .  c o  m
            for (String propertyNamePath : propertyNamePaths) {
                if (temp == null) {
                    break;
                }
                temp = Reflections.invokeGetter(temp, propertyNamePath);
            }
            propertyValue = temp;
        } else {
            propertyValue = Reflections.invokeGetter(obj, propertyName);
        }
        list.add(propertyValue);
    }
    return list;
}

From source file:net.gtaun.shoebill.util.config.MapConfiguration.java

@SuppressWarnings("unchecked")
public static Object get(Map<String, Object> map, String path) {
    String[] childs = StringUtils.split(path, '.');
    if (childs.length == 0)
        return map;

    Map<String, Object> node = map;
    for (int i = 0; i < childs.length - 1; i++) {
        Object obj = node.get(childs[i]);
        if (obj instanceof Map<?, ?> == false)
            return null;
        node = (HashMap<String, Object>) obj;
    }//  ww w  . j  a v a  2 s . c o m

    return node.get(childs[childs.length - 1]);
}

From source file:com.neocotic.blingaer.common.RequestUtils.java

/**
 * Returns the IP address that appears to be the source of the specified
 * {@code request}./*from   www  .j a  v a2s .  com*/
 * 
 * @param request
 *            the {@code HttpServletRequest} to check
 * @return the IP address
 */
public static String getIpAddress(HttpServletRequest request) {
    String ipAddress = request.getHeader("X-Forwarded-For");

    if (ipAddress == null) {
        ipAddress = request.getRemoteAddr();
    } else {
        String[] ipAddresses = StringUtils.split(ipAddress, ",");

        if (ipAddresses.length > 0) {
            ipAddress = ipAddresses[0];
        }
    }

    return ipAddress;
}

From source file:com.mxep.web.common.persistence.SearchFilter.java

/**
 * searchParamskey?OPERATOR_FIELDNAME//from  w  w w  . ja  va 2  s .  com
 */
public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) {
    Map<String, SearchFilter> filters = Maps.newHashMap();

    for (Entry<String, Object> entry : searchParams.entrySet()) {
        // 
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value != null && StringUtils.isBlank(value.toString())) {
            continue;
        }

        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length < 2) {
            throw new IllegalArgumentException(key + " is not a valid search filter name");
        }
        String filedName = "";
        for (int i = 1; i < names.length; i++) {
            filedName += names[i];
            if ((i + 1) < names.length) {
                filedName += ".";
            }
        }

        Operator operator = getOperator(names[0]);
        if (null == operator) {
            continue;
        }

        // searchFilter
        if (isValidDate(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd");
                // ?
                if (operator.equals(Operator.LT) || operator.equals(Operator.LTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    cal.add(Calendar.DAY_OF_YEAR, 1);
                    date = cal.getTime();
                }
                // ????
                if (operator.equals(Operator.GT) || operator.equals(Operator.GTE)) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);
                    date = cal.getTime();
                }
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (isValidDateTime(value.toString())) {
            try {
                Date date = DateUtils.parseDate((String) value, "yyyy-MM-dd HH:mm:ss");
                value = date;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:com.thinkbiganalytics.metadata.jpa.support.QueryDslPathInspector.java

/**
 * for a given path (separated by dot) get the final object
 *
 * @param basePath the object to start inspecting example:  QJpaBatchJobExecution jpaBatchJobExecution
 * @param fullPath a string representing the path you wish to inspect.  example:  jobInstance.jobName
 * @return return the Object for the path.  example: will return the StringPath jobName on the QJpaBatchJobInstance class
 *//*from  w w  w  .jav a 2 s .c om*/
public static Object getFieldObject(BeanPath basePath, String fullPath) throws IllegalAccessException {

    LinkedList<String> paths = new LinkedList<>();
    paths.addAll(Arrays.asList(StringUtils.split(fullPath, ".")));
    return getFieldObject(basePath, paths);
}

From source file:com.thetechwarriors.cidrutils.Subnet.java

public Subnet(String ipAddress, int maskSize) {
    String[] split = StringUtils.split(ipAddress, '.');
    for (int i = 0; i < 4; i++) {
        this.octets[i] = Integer.parseInt(split[i]);
    }//w w  w.  ja  va2  s  .  c  o m
    this.maskSize = maskSize;
}

From source file:com.creditcloud.ump.model.ump.utils.UmpUtils.java

public static List<UmpSeqTransaction> parseSeqTrans(String transDetail) {
    List<UmpSeqTransaction> transList = new ArrayList<>();
    if (StringUtils.isBlank(transDetail)) {
        return transList;
    }/*from   w  w  w.  jav  a  2s  .  c  om*/
    String[] transStrArray = StringUtils.split(transDetail, '|');
    for (String transStr : transStrArray) {
        String[] fieldStrArray = transStr.split(",");
        Map<String, String> values = new HashMap<String, String>();
        for (String fieldStr : fieldStrArray) {
            String[] pair = fieldStr.split("=");
            if (pair.length != 2) {
                logger.log(Level.WARNING, "cannot parse transaction field string:" + fieldStr + ", ignore");
                continue;
            } else {
                values.put(pair[0], pair[1]);
            }
        }
        UmpSeqTransaction trans = new UmpSeqTransaction();
        trans.setAccCheckDate(values.get("acc_check_date"));
        trans.setAmount(fromCents(values.get("amount")));
        trans.setComAmt(
                values.get("com_amt") != null ? fromCents(values.get("com_amt")).setScale(2) : BigDecimal.ZERO);
        trans.setDcMark(UmpSeqCashFlow.getEnum(values.get("dc_mark")));
        trans.setTransType(UmpBusiType.getEnum(values.get("trans_type")));
        trans.setTransState(UmpSeqTransStatus.getEnum(values.get("trans_state")));
        transList.add(trans);
    }
    return transList;
}