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:de.qaware.chronix.solr.ingestion.format.InfluxDbFormatParser.java

@Override
public Iterable<MetricTimeSeries> parse(InputStream stream) throws FormatParseException {
    Map<Metric, MetricTimeSeries.Builder> metrics = new HashMap<>();

    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
    String line;//from ww w .j a va2s.c  o  m
    try {
        while ((line = reader.readLine()) != null) {
            // Format is: {metric},[{tag1}={value1},{tag2}={value2}] value={value} [nanosecond-timestamp]
            // Example: cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257

            String[] parts = StringUtils.split(line, ' ');
            // 2 parts: metric and value. Timestamp and tags are optional.
            if (parts.length < 2) {
                throw new FormatParseException(
                        "Expected at least 2 parts, found " + parts.length + " in line '" + line + "'");
            }

            String metricName = getMetricName(parts);
            Map<String, String> tags = getMetricTags(parts);
            double value = getMetricValue(parts);
            Instant timestamp = getMetricTimestamp(parts);

            // If the metric is already known, add a point. Otherwise create the metric and add the point.
            Metric metric = new Metric(metricName, tags);
            MetricTimeSeries.Builder metricBuilder = metrics.get(metric);
            if (metricBuilder == null) {
                metricBuilder = new MetricTimeSeries.Builder(metricName, METRIC_TYPE);
                for (Map.Entry<String, String> tagEntry : tags.entrySet()) {
                    metricBuilder.attribute(tagEntry.getKey(), tagEntry.getValue());
                }
                metrics.put(metric, metricBuilder);
            }

            metricBuilder.point(timestamp.toEpochMilli(), value);
        }
    } catch (IOException e) {
        throw new FormatParseException("IO exception while parsing OpenTSDB telnet format", e);
    }

    return metrics.values().stream().map(MetricTimeSeries.Builder::build).collect(Collectors.toList());
}

From source file:de.hybris.platform.addonsupport.setup.populator.SupportedUiExperienceImpexMacroParameterPopulator.java

protected List<UiExperienceLevel> getSupportedUiExperienceLevels() {
    final String[] levelsAsString = StringUtils.split(getSiteConfigService()
            .getString("storefront.supportedUiExperienceLevels", UiExperienceLevel.DESKTOP.getCode()), ",");

    final Set<UiExperienceLevel> levels = new LinkedHashSet<UiExperienceLevel>();
    for (int i = 0; i < levelsAsString.length; i++) {
        final UiExperienceLevel level = UiExperienceLevel.valueOf(levelsAsString[i]);
        levels.add(level);// ww  w.j  a v a 2 s .com
    }
    return new ArrayList<UiExperienceLevel>(levels);
}

From source file:com.berwickheights.spring.svc.security.UserRolesSvcImpl.java

/**
 * The map of user types stored in database to user roles used in Spring Security.
 *//* w  ww . ja va2  s  .  c  o  m*/
public void setRolesMap(Map<Short, String> rolesMap) {
    this.rolesMap = new HashMap<Short, Set<GrantedAuthority>>();
    for (Map.Entry<Short, String> entry : rolesMap.entrySet()) {
        String[] rolesArray = StringUtils.split(entry.getValue(), ",");
        Set<GrantedAuthority> roles = new TreeSet<GrantedAuthority>();
        for (String role : rolesArray) {
            roles.add(new GrantedAuthorityImpl(role));
        }

        this.rolesMap.put(entry.getKey(), roles);
    }
}

From source file:com.flexive.faces.FxJsf1Utils.java

/**
 * Workaround for facelets component tree update problems - deletes
 * the given components and its children so they can be recreated
 * when the component tree is rendered again
 *
 * @param componentIds comma separated component ids, e.g. frm:queryEditor, frm:contentEditor
 *//*from w  w w  .j a  v a2s .  c  o  m*/
public static void resetFaceletsComponents(String componentIds) {
    if (StringUtils.isBlank(componentIds)) {
        return;
    }
    String[] ids = StringUtils.split(componentIds, ",");
    for (String id : ids) {
        resetFaceletsComponent(id.trim());
    }
}

From source file:com.goosby.virgo.utils.PageRequest.java

/**
 * ???./* w  w w.jav  a2  s . c o m*/
 * 
 * @param orderDir ?descasc,?','.
 */
public void setOrderDir(final String orderDir) {
    final String lowcaseOrderDir = StringUtils.lowerCase(orderDir);

    // order?
    final String[] orderDirs = StringUtils.split(lowcaseOrderDir, ',');
    for (final String orderDirStr : orderDirs) {
        if (!StringUtils.equals(Sort.DESC, orderDirStr) && !StringUtils.equals(Sort.ASC, orderDirStr))
            throw new IllegalArgumentException("??" + orderDirStr + "??");
    }

    this.orderDir = lowcaseOrderDir;
}

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

protected synchronized SkinSetting doGetSkinSetting(DoradoContext context, String skin) throws Exception {
    SkinSetting skinSetting = skinSettingMap.get(skin);
    if (skinSetting == null) {
        boolean shouldCache = true;
        String metaInfoPath = null;
        String customSkinPath = WebConfigure.getString("view.skin." + skin);
        if (StringUtils.isNotEmpty(customSkinPath)) {
            metaInfoPath = PathUtils.concatPath(customSkinPath, META_INFO_FILE);
        } else {/*from w  w w  .ja v  a 2s .c  o  m*/
            String libraryRoot = Configure.getString("view.libraryRoot");

            if ("debug".equals(Configure.getString("core.runMode")) && libraryRoot != null
                    && StringUtils.indexOfAny(libraryRoot, RESOURCE_PREFIX_DELIM) >= 0) {
                String[] roots = StringUtils.split(libraryRoot, RESOURCE_PREFIX_DELIM);
                for (String root : roots) {
                    String tempPath = PathUtils.concatPath(root, SKINS, skin, META_INFO_FILE);
                    if (context.getResource(tempPath).exists()) {
                        metaInfoPath = tempPath;
                        break;
                    }
                }
            } else {
                metaInfoPath = PathUtils.concatPath(libraryRoot, SKINS, skin, META_INFO_FILE);
            }
        }

        if (StringUtils.isNotEmpty(metaInfoPath)) {
            Resource metaInfoResource = context.getResource(metaInfoPath);
            if (metaInfoResource.exists()) {
                InputStream in = metaInfoResource.getInputStream();
                try {
                    Map<String, Object> map = objectMapper.readValue(in,
                            new TypeReference<Map<String, Object>>() {
                            });

                    if (VariantUtils.toBoolean(map.remove("tempSkin"))) {
                        shouldCache = false;
                    }

                    skinSetting = new SkinSetting();

                    String clientTypes = (String) map.remove("clientType");
                    if (StringUtils.isNotEmpty(clientTypes)) {
                        skinSetting.setClientTypes(ClientType.parseClientTypes(clientTypes));
                    } else {
                        skinSetting.setClientTypes(ClientType.DESKTOP);
                    }

                    BeanUtils.copyProperties(skinSetting, map);
                } finally {
                    in.close();
                }
            }
        }

        if (shouldCache) {
            if (skinSetting == null) {
                skinSettingMap.put(skin, NULL_SKIN_SETTING);
            } else {
                skinSettingMap.put(skin, skinSetting);
            }
        }
    } else if (skinSetting == NULL_SKIN_SETTING) {
        skinSetting = null;
    }
    return skinSetting;
}

From source file:edu.ku.brc.specify.toycode.mexconabio.AgentNames.java

private void parseForFirstLastName(final String str) {
    if (StringUtils.contains(str, ',')) {
        String[] toks = StringUtils.split(str, ',');
        String lastName = toks[0].trim();
        String first = "";
        if (toks.length > 1) {
            first = toks[1].trim();/*from w  w  w.  j a v  a 2 s  .c  om*/
            //if (StringUtils.contains(first, '.'))
        }
        System.out.println(
                "    [" + first + "][" + lastName + "] " + (StringUtils.contains(first, '.') ? "*" : ""));
    } else {
        System.out.println("    [" + str.trim() + "]");
    }
}

From source file:com.voa.weixin.task.WeixinResult.java

public long getLong(String xpath) {
    long value = 0;
    JSONObject temp = result;//from  ww w  . j a  v  a  2s. c om
    String[] names = StringUtils.split(xpath, "/");
    for (int i = 0; i < names.length; i++) {
        if (i == (names.length - 1)) {
            value = temp.getLong(names[i]);
            break;
        }

        temp = temp.getJSONObject(names[i]);
    }

    return value;
}

From source file:com.openshift.internal.restclient.capability.resources.OpenShiftBinaryPortForwarding.java

@Override
protected String[] buildArgs(String location) {
    StringBuilder args = new StringBuilder(location);
    args.append(" port-forward ").append("--insecure-skip-tls-verify=true ").append("--server=")
            .append(getClient().getBaseURL()).append(" ");
    addToken(args).append("-n ").append(pod.getNamespace()).append(" ").append("-p ").append(pod.getName())
            .append(" ");
    for (PortPair pair : pairs) {
        args.append(pair.getLocalPort()).append(":").append(pair.getRemotePort()).append(" ");
    }//from  w ww. j  a  va2 s.com
    return StringUtils.split(args.toString(), " ");
}

From source file:com.apexxs.neonblack.dao.GeoNamesEntry.java

public GeoNamesEntry(String line) {
    String[] tokens = line.split("\t");

    if (tokens.length < 6)
        return;//from  ww  w .j  a  va2  s .c  o m

    Set<String> tempNames = new HashSet<>();

    //this.id = tokens[0];
    this.id = MD5Utilities.getMD5Hash(line);
    this.name = tokens[1];
    String asciiName = tokens[2];

    if (!this.name.equals(asciiName)) {
        tempNames.add(tokens[1]);
        tempNames.add(tokens[2]);
        this.name = asciiName;
    } else {
        tempNames.add(tokens[1]);
    }

    if (tokens[3].length() > 0) {
        String[] altNames = StringUtils.split(tokens[3], ",");
        for (String altName : altNames) {
            if (!tempNames.contains(altName)) {
                tempNames.add(altName);
            }
        }
    }
    this.allNames = new ArrayList<>(tempNames);
    this.lonLat = tokens[5] + " " + tokens[4];

    if (tokens.length >= 7) {
        if (!StringUtils.isBlank(tokens[6])) {
            featureClass = tokens[6];
        }
    }
    if (tokens.length >= 8) {
        if (!StringUtils.isBlank(tokens[7])) {
            featureCode = tokens[7];
        }
    }
    if (tokens.length >= 9) {
        if (!StringUtils.isBlank(tokens[8])) {
            countryCode = tokens[8];
        }
    }
    if (tokens.length >= 11) {
        if (!StringUtils.isBlank(tokens[10])) {
            admin1 = tokens[10];
        }
    }
    if (tokens.length >= 12) {
        if (!StringUtils.isBlank(tokens[11])) {
            admin2 = tokens[11];
        }
    }
    if (tokens.length >= 15) {
        try {
            if (!StringUtils.isBlank(tokens[14])) {
                population = Long.parseLong(tokens[14]);
            }
        } catch (NumberFormatException e) {
            //ignore it
        }
    }
}