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

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

Introduction

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

Prototype

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

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:com.npower.dm.util.MToneDeviceDataReaderV2.java

public DeviceData read() throws IOException {
    String line = readLine();//from w  w w.jav a  2s . c  o m
    while (StringUtils.isNotEmpty(line) && line.startsWith("#")) {
        line = this.readLine();
    }
    if (StringUtils.isEmpty(line)) {
        return null;
    }

    line = line.trim();
    String[] items = StringUtils.split(line, ',');
    if (items == null || items.length < 2) {
        return null;
    }
    String phone = items[0];
    String model = items[1];
    String imei_imsi = items[2];
    String imei = imei_imsi.substring(0, 15);
    String imsi = imei_imsi.substring(15, 30);
    String brand = (items.length < 4) ? "NOKIA" : items[3];

    DeviceData data = new DeviceData();
    data.setManufacturer(brand.trim());
    data.setModel(model.trim());
    data.setPhoneNumber(phone.trim());
    data.setLineNumber(this.currentLineNumber);
    data.setImei("IMEI:" + imei);
    data.setImsi(imsi);
    return data;
}

From source file:com.opengamma.util.money.CurrencyAmount.java

/**
 * Parses the string to produce a {@code CurrencyAmount}.
 * <p>//from w w w.  j  av a 2 s  . co m
 * This parses the {@code toString} format of '${currency} ${amount}'.
 * 
 * @param amountStr  the amount string, not null
 * @return the currency amount
 * @throws IllegalArgumentException if the amount cannot be parsed
 */
@FromString
public static CurrencyAmount parse(final String amountStr) {
    ArgumentChecker.notNull(amountStr, "amountStr");
    String[] parts = StringUtils.split(amountStr, ' ');
    if (parts.length != 2) {
        throw new IllegalArgumentException("Unable to parse amount, invalid format: " + amountStr);
    }
    try {
        Currency cur = Currency.parse(parts[0]);
        double amount = Double.parseDouble(parts[1]);
        return new CurrencyAmount(cur, amount);
    } catch (RuntimeException ex) {
        throw new IllegalArgumentException("Unable to parse amount: " + amountStr, ex);
    }
}

From source file:au.edu.anu.portal.portlets.basiclti.support.CollectionsSupport.java

/**
 * Split a String to a Map, based on the given delimiters, one for the sets and one for each pair. Can also chomp new lines
 * @param str// w  w  w  .jav a2  s. c o m
 * @param setDelimiter   the delimiter between each set of items
 * @param kvDelimiter   the delimiter between each item in a pair
 * @param chomp         whether or not to chomp new lines that may separate each pair
 * @return
 */
public static Map<String, String> splitStringToMap(String str, String setDelimiter, String kvDelimiter,
        boolean chomp) {
    List<String> list = splitStringToList(str, setDelimiter, chomp);
    Map<String, String> map = new HashMap<String, String>();
    for (String pair : list) {
        String[] kv = StringUtils.split(pair, kvDelimiter);
        map.put(kv[0], kv[1]);
    }
    return map;
}

From source file:gemlite.core.webapp.tools.ClusterController.java

@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView index() {
    ModelAndView view = new ModelAndView("tools/cluster_manage");
    ConfigService service = JpaContext.getService(ConfigService.class);
    Map<String, String> map = service.getConfig(ConfigTypes.clusterconfig.getValue());
    String cluster_list = map.get(ConfigKeys.cluster_list.getValue());
    String ips[] = StringUtils.split(cluster_list, ",");
    String cluster_primaryip = map.get(ConfigKeys.cluster_primaryip.getValue());
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    for (String ip : ips) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("ip", ip);
        if (StringUtils.equals(cluster_primaryip, ip))
            obj.put("isP", true);
        else/*from www .j  a v  a2s .c  o  m*/
            obj.put("isP", false);
        list.add(obj);
    }
    view.addObject("list", list);
    return view;
}

From source file:hydrograph.ui.validators.impl.DatabaseKeyValidation.java

@Override
public boolean validate(Object object, String propertyName, Map<String, List<FixedWidthGridRow>> inputSchemaMap,
        boolean isJobFileImported) {
    if (object != null) {
        List<String> tmpList = new LinkedList<>();
        Map<String, Object> keyFieldsList = (LinkedHashMap<String, Object>) object;

        if (keyFieldsList != null && !keyFieldsList.isEmpty()
                && keyFieldsList.containsKey(Constants.LOAD_TYPE_NEW_TABLE_KEY)) {
            if (inputSchemaMap != null) {
                for (java.util.Map.Entry<String, List<FixedWidthGridRow>> entry : inputSchemaMap.entrySet()) {
                    List<FixedWidthGridRow> gridRowList = entry.getValue();
                    gridRowList.forEach(gridRow -> tmpList.add(gridRow.getFieldName()));
                }/*from  w  w w .j  ava2s  . co m*/
            }
            for (Entry<String, Object> grid : keyFieldsList.entrySet()) {
                String[] keyValues = StringUtils.split((String) grid.getValue(), ",");
                for (String values : keyValues) {
                    if (!tmpList.contains(values)) {
                        errorMessage = "Target Fields Should be present in Available Fields";
                        return false;
                    }
                }
            }

            return true;
        } else if (keyFieldsList != null && !keyFieldsList.isEmpty()
                && keyFieldsList.containsKey(Constants.LOAD_TYPE_INSERT_KEY)) {
            return true;
        } else if (keyFieldsList != null && !keyFieldsList.isEmpty()
                && keyFieldsList.containsKey(Constants.LOAD_TYPE_REPLACE_KEY)) {
            return true;
        }
    }
    return true;
}

From source file:com.cyclopsgroup.waterview.valves.ParseURLValve.java

/**
 * Override or implement method of parent class or interface
 *
 * @see com.cyclopsgroup.waterview.Valve#invoke(com.cyclopsgroup.waterview.PageRuntime, com.cyclopsgroup.waterview.PipelineContext)
 *///from  ww w .j  a  va2 s  . c o  m
public void invoke(PageRuntime runtime, PipelineContext context) throws Exception {
    Context ctx = runtime.getPageContext();
    ctx.put("runtime", runtime);
    ctx.put("context", ctx);
    ctx.put("params", runtime.getRequestParameters());
    ctx.put("applicationBase", runtime.getApplicationBaseUrl());
    ctx.put("pageBase", runtime.getPageBaseUrl());
    String path = runtime.getRequestPath();
    if (path.indexOf('|') != -1) {
        String[] parts = StringUtils.split(path, '|');
        for (int i = 0; i < parts.length; i++) {
            String part = parts[i];
            if (i == parts.length - 1) {
                path = part;
            } else {
                runtime.getActions().add(part);
            }
        }
    }
    if (StringUtils.isEmpty(path)) {
        path = defaultPage;
    }
    runtime.setPage(path);
    ctx.put("page", path);
    context.invokeNextValve(runtime);
}

From source file:com.bstek.dorado.view.resolver.DefaultSkinResolver.java

protected String doDetermineSkin(DoradoContext context, String skins) throws Exception {
    int currentClientType = VariantUtils.toInt(context.getAttribute(ClientType.CURRENT_CLIENT_TYPE_KEY));
    boolean isIE = false, isIE6 = false, isOldIE = false;
    String ieVersion = null;//ww  w .  ja  v  a  2 s .c o m
    if (currentClientType == 0) {
        String ua = context.getRequest().getHeader("User-Agent");
        if (ua.indexOf(CHROME_FRAME) < 0) {
            isIE = (ua != null && ua.indexOf(MSIE) != -1);
            if (isIE) {
                ieVersion = MSIE_VERSION_PATTERN.matcher(ua).replaceAll("$1");
                if (StringUtils.isNotEmpty(ieVersion) && ieVersion.length() == 1) {
                    if ("9".compareTo(ieVersion) > 0) {
                        isOldIE = true;
                        if ("7".compareTo(ieVersion) > 0) {
                            isIE6 = true;
                        }
                    }
                }
            }
        }
    }

    if (skins != null) {
        skins += (',' + DEFAULT_SKIN);
    } else {
        skins = DEFAULT_SKIN;
    }

    String realSkin = null;
    String[] skinArray = StringUtils.split(skins, ',');
    for (String skin : skinArray) {
        SkinSetting skinSetting;
        if (currentClientType != 0) {
            String tempSkin = skin + '.' + ClientType.toString(currentClientType);

            skinSetting = skinSettingManager.getSkinSetting(context, tempSkin);
            if (skinSetting != null) {
                if (ClientType.supports(skinSetting.getClientTypes(), currentClientType)) {
                    realSkin = tempSkin;
                    break;
                }
            }
        }

        if (isIE6) {
            String tempSkin = skin + ".ie6";

            skinSetting = skinSettingManager.getSkinSetting(context, tempSkin);
            if (skinSetting != null) {
                String skinUserAgent = skinSetting.getUserAgent();
                if (StringUtils.isEmpty(skinUserAgent) || skinUserAgent.indexOf("-ie") < 0) {
                    realSkin = tempSkin;
                    break;
                }
            }
        }

        skinSetting = skinSettingManager.getSkinSetting(context, skin);
        if (skinSetting != null) {
            if (currentClientType != 0) {
                if (!ClientType.supports(skinSetting.getClientTypes(), currentClientType)) {
                    break;
                }
            }
            if (isOldIE) {
                String skinUserAgent = skinSetting.getUserAgent();
                if (StringUtils.isNotEmpty(skinUserAgent)) {
                    int i = skinUserAgent.indexOf("-ie");
                    if (i >= 0) {
                        i += 3;
                        String version = "";
                        int len = skinUserAgent.length();
                        while (i < len) {
                            char c = skinUserAgent.charAt(i);
                            i++;
                            if (c >= '0' && c <= '9' || c == '.') {
                                version += c;
                            } else {
                                break;
                            }
                        }

                        if (ieVersion.compareTo(version) <= 0) {
                            continue;
                        }
                    }
                }
            }
            realSkin = skin;
            break;
        }
    }

    if (realSkin == null) {
        realSkin = DEFAULT_SKIN;
        if (isOldIE) {
            realSkin += ".ie6";
        } else if (currentClientType > ClientType.DESKTOP) {
            realSkin += '.' + ClientType.toString(currentClientType);
        }
    }
    return realSkin;
}

From source file:ml.shifu.shifu.udf.PSICalculatorUDF.java

@Override
public Tuple exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2) {
        return null;
    }/*from  www.  j  a  v  a2s . c  om*/

    Integer columnId = (Integer) input.get(0);
    DataBag databag = (DataBag) input.get(1);

    ColumnConfig columnConfig = this.columnConfigList.get(columnId);

    List<Integer> negativeBin = columnConfig.getBinCountNeg();
    List<Integer> positiveBin = columnConfig.getBinCountPos();
    List<Double> expected = new ArrayList<Double>(negativeBin.size());
    for (int i = 0; i < columnConfig.getBinCountNeg().size(); i++) {
        if (columnConfig.getTotalCount() == 0) {
            expected.add(0D);
        } else {
            expected.add(
                    ((double) negativeBin.get(i) + (double) positiveBin.get(i)) / columnConfig.getTotalCount());
        }
    }

    Iterator<Tuple> iter = databag.iterator();
    Double psi = 0D;
    List<String> unitStats = new ArrayList<String>();

    while (iter.hasNext()) {
        Tuple tuple = iter.next();
        if (tuple != null && tuple.size() != 0) {
            String subBinStr = (String) tuple.get(1);
            String[] subBinArr = StringUtils.split(subBinStr, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR);
            List<Double> subCounter = new ArrayList<Double>();
            Double total = 0D;
            for (String binningElement : subBinArr) {
                Double dVal = Double.valueOf(binningElement);
                subCounter.add(dVal);
                total += dVal;
            }

            int i = 0;
            for (Double sub : subCounter) {
                if (total == 0) {
                    continue;
                } else if (expected.get(i) == 0) {
                    continue;
                } else {
                    double logNum = (sub / total) / expected.get(i);
                    if (logNum <= 0) {
                        continue;
                    } else {
                        psi = psi + ((sub / total - expected.get(i)) * Math.log(logNum));
                    }
                }
                i++;
            }

            unitStats.add((String) tuple.get(2));
        }
    }

    // sort by unit
    Collections.sort(unitStats);

    Tuple output = TupleFactory.getInstance().newTuple(3);
    output.set(0, columnId);
    output.set(1, psi);
    output.set(2, StringUtils.join(unitStats, CalculateStatsUDF.CATEGORY_VAL_SEPARATOR));

    return output;
}

From source file:com.qualogy.qafe.gwt.server.helper.UIAssemblerHelper.java

public static void copyFields(Component component, Window currentWindow, ComponentGVO vo,
        ApplicationMapping applicationMapping, ApplicationContext context, SessionContainer sc) {
    if ((component != null) && (vo != null)) {

        vo.setId(component.getId());//  w w  w  .  j  av a2 s .co m
        vo.setFieldName(component.getFieldName());
        vo.setGroup(component.getGroup());
        vo.setTooltip(component.getTooltip());
        vo.setMenu((MenuItemGVO) ComponentUIAssembler.convert(component.getMenu(), currentWindow,
                applicationMapping, context, sc));
        if (vo.getMenu() != null) {
            manageMenuId(vo.getMenu(), component.getId());
        }
        vo.setDisabled(component.getDisabled());
        vo.setVisible(component.getVisible());
        vo.setWidth(component.getWidth());
        vo.setHeight(component.getHeight());
        if (currentWindow != null) {
            vo.setWindow(currentWindow.getId());
        }
        if (context != null) {
            vo.setContext(context.getId().toString());
        }

        // Style
        vo.setStyleClass(component.getStyleClass());
        String[] properties = StringUtils.split(component.getStyle() == null ? "" : component.getStyle(), ';');
        String[][] styleProperties = new String[properties.length][2];
        for (int i = 0; i < properties.length; i++) {
            styleProperties[i] = StringUtils.split(properties[i], ':');
        }

        /*
         * Modify the properties since this is DOM manipulation : font-size for css has to become fontSize for DOM
         */
        for (int i = 0; i < styleProperties.length; i++) {
            styleProperties[i][0] = StyleDomUtil.initCapitalize(styleProperties[i][0]);
        }

        vo.setStyleProperties(styleProperties);

        if (component instanceof EditableComponent) {
            if (vo instanceof EditableComponentGVO) {
                EditableComponent editableComponent = (EditableComponent) component;
                EditableComponentGVO editableComponentGVO = (EditableComponentGVO) vo;
                editableComponentGVO.setEditable(editableComponent.getEditable());

                ConditionalStyle conditionalStyle = editableComponent.getConditionalStyleRef();

                if (conditionalStyle != null) {
                    editableComponentGVO
                            .setConditionalStyleRef(ConditionalStyleUIAssembler.convert(conditionalStyle));
                }

            }
        }

        manageInternationalisation(component, vo, applicationMapping, sc);

        if (component instanceof HasRequiredProperty && vo instanceof HasRequired) {
            ((HasRequired) vo).setRequired(((HasRequiredProperty) component).getRequired());
        }
    }
}

From source file:net.shopxx.plugin.ftpStorage.FtpStoragePlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String host = pluginConfig.getAttribute("host");
        Integer port = Integer.valueOf(pluginConfig.getAttribute("port"));
        String username = pluginConfig.getAttribute("username");
        String password = pluginConfig.getAttribute("password");
        FTPClient ftpClient = new FTPClient();
        InputStream inputStream = null;
        try {/*w w w  .  ja v a  2 s.  c o  m*/
            inputStream = new BufferedInputStream(new FileInputStream(file));
            ftpClient.connect(host, port);
            ftpClient.login(username, password);
            ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                String directory = StringUtils.substringBeforeLast(path, "/");
                String filename = StringUtils.substringAfterLast(path, "/");
                if (!ftpClient.changeWorkingDirectory(directory)) {
                    String[] paths = StringUtils.split(directory, "/");
                    String p = "/";
                    ftpClient.changeWorkingDirectory(p);
                    for (String s : paths) {
                        p += s + "/";
                        if (!ftpClient.changeWorkingDirectory(p)) {
                            ftpClient.makeDirectory(s);
                            ftpClient.changeWorkingDirectory(p);
                        }
                    }
                }
                ftpClient.storeFile(filename, inputStream);
                ftpClient.logout();
            }
        } catch (SocketException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(inputStream);
            try {
                if (ftpClient.isConnected()) {
                    ftpClient.disconnect();
                }
            } catch (IOException e) {
            }
        }
    }
}