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:edu.mayo.cts2.framework.plugin.service.bioportal.transform.AbstractTransform.java

/**
 * Builds the scoped entity name.//w  ww  .  j av  a 2  s .c  o  m
 *
 * @param name the name
 * @param codeSystemName the code system name
 * @return the scoped entity name
 */
protected ScopedEntityName buildScopedEntityName(String name, String codeSystemName) {
    ScopedEntityName scopedName = new ScopedEntityName();

    String[] namePartsColon = StringUtils.split(name, ':');
    String[] namePartsHash = StringUtils.split(name, '#');

    String[] nameParts;
    if (namePartsColon.length > namePartsHash.length) {
        nameParts = namePartsColon;
    } else {
        nameParts = namePartsHash;
    }

    if (nameParts.length == 1) {
        scopedName.setName(nameParts[0]);
        scopedName.setNamespace(codeSystemName);
    } else {
        boolean isNamespaceValidNCName = XMLChar.isValidNCName(nameParts[0]);
        if (isNamespaceValidNCName) {
            scopedName.setNamespace(nameParts[0]);
        } else {
            scopedName.setNamespace(codeSystemName);
        }
        scopedName.setName(nameParts[1]);
    }

    return this.sanitizeNcNameNamespace(scopedName);
}

From source file:net.morematerials.commands.GeneralExecutor.java

private boolean showHelp(CommandSender sender, String[] args) {
    Map<String, Map<String, Object>> commands = this.plugin.getDescription().getCommands();
    ArrayList<String> messages = new ArrayList<String>();

    if (args.length > 1 && commands.containsKey(args[1])) {
        // Show specified command.
        messages.add(ChatColor.RED + "Help page for /" + args[1]);
        messages.add(ChatColor.RED + "---------------------------------");
        for (String use : StringUtils.split((String) commands.get(args[1]).get("usage"), "\n")) {
            use = use.replaceAll("<command>", args[1] + ChatColor.GOLD);
            messages.add(ChatColor.GREEN + use);
        }/*from   www  . j  a  v a2 s  . c o  m*/
    } else {
        // Show all commands.
        messages.add(ChatColor.RED + "Help page");
        messages.add(ChatColor.RED + "---------------------------------");
        // Getting commands from plugin.yml
        for (String commandsEntry : commands.keySet()) {
            messages.add(ChatColor.RED + "/" + commandsEntry);
            messages.add("-> " + ChatColor.GOLD + commands.get(commandsEntry).get("description"));
        }
    }

    // Send all messages.
    for (Integer i = 0; i < messages.size(); i++) {
        sender.sendMessage(messages.get(i));
    }

    return true;
}

From source file:com.netflix.simianarmy.aws.janitor.rule.asg.ASGInstanceValidator.java

/**
 * Checks whether an ASG resource contains any active instances.
 * @param resource the ASG resource//ww w .j  a v a  2s  .  c o  m
 * @return true if the ASG contains any active instances, false otherwise.
 */
public boolean hasActiveInstance(Resource resource) {
    String instanceIds = resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_INSTANCES);
    String maxSizeStr = resource.getAdditionalField(ASGJanitorCrawler.ASG_FIELD_MAX_SIZE);
    if (StringUtils.isBlank(instanceIds)) {
        if (maxSizeStr != null && Integer.parseInt(maxSizeStr) == 0) {
            // The ASG is empty when it has not instance and the max size of the ASG is 0.
            // If the max size is not 0, the ASG could probably be in the process of starting new instances.
            LOGGER.info(String.format("ASG %s is empty.", resource.getId()));
            return false;
        } else {
            LOGGER.info(String.format("ASG %s does not have instances but the max size is %s", resource.getId(),
                    maxSizeStr));
            return true;
        }
    }
    String[] instances = StringUtils.split(instanceIds, ",");
    LOGGER.debug(String.format("Checking if the %d instances in ASG %s are active.", instances.length,
            resource.getId()));
    for (String instanceId : instances) {
        if (isActiveInstance(instanceId)) {
            LOGGER.info(String.format("ASG %s has active instance.", resource.getId()));
            return true;
        }
    }
    LOGGER.info(String.format("ASG %s has no active instance.", resource.getId()));
    return false;
}

From source file:info.magnolia.cms.beans.config.HostBasedVirtualURIMapping.java

public void setHosts(List<String> hosts) {
    String[] hostToPath = null;/*from w w  w  .  j  a  v a  2s .c o m*/
    for (String host : hosts) {
        hostToPath = StringUtils.split(host, "=");
        if (hostToPath != null && hostToPath.length == 2) {
            this.hosts.put(hostToPath[0], hostToPath[1]);
        }
    }
}

From source file:jp.co.acroquest.endosnipe.perfdoctor.rule.RulePreferenceUtil.java

/**
 * ?ID??/* w w w . jav a 2  s  .  co  m*/
 * @return ID????????0???
 */
public static String[] loadRuleSetIds() {
    String ids = preferenceMap__.get(CONFIG_RULESET_IDS);

    if (ids == null || ids.length() == 0) {
        return new String[0];
    }

    String[] ruleIds = StringUtils.split(ids, ",");
    return ruleIds;
}

From source file:de.pawlidi.openaletheia.base.model.User.java

public User toObject(final String userString) {
    if (StringUtils.isNotEmpty(userString)) {
        String[] values = StringUtils.split(userString, VALUE_SEPARATOR);
        if (ArrayUtils.isNotEmpty(values) && values.length >= 3) {
            uuid = values[0];//from ww  w. ja v a2  s . co  m
            username = values[1];
            password = values[2];
        }
    }
    return this;
}

From source file:com.hangum.tadpole.mongodb.core.connection.MongoConnectionManager.java

/**
 * //from w  w  w .j av a  2s .c o m
 * @param userDB
 * @return
 * @throws Exception
 */
public static DB getInstance(UserDBDAO userDB) throws MongoDBNotFoundException, Exception {
    DB db = null;

    /*
     * https://mongodb.github.io/casbah/guide/connecting.html
     */
    synchronized (dbManager) {
        String searchKey = getKey(userDB);
        try {
            MongoClient mongoDB = dbManager.get(searchKey);

            if (mongoDB == null) {
                MongoClientOptions clientOptions = MongoClientOptions.builder().connectionsPerHost(200)
                        .connectTimeout(5000).socketTimeout(5000).build();

                List<MongoCredential> listCredential = new ArrayList<>();
                if (!"".equals(userDB.getUsers())) { //$NON-NLS-1$
                    // pass change
                    String passwdDecrypt = "";
                    try {
                        passwdDecrypt = CipherManager.getInstance().decryption(userDB.getPasswd());
                    } catch (Exception e) {
                        passwdDecrypt = userDB.getPasswd();
                    }

                    MongoCredential mongocredintial = MongoCredential.createCredential(userDB.getUsers(),
                            userDB.getDb(), passwdDecrypt.toCharArray());
                    listCredential.add(mongocredintial);
                }

                String strReplcaSet = userDB.getExt1();
                if (strReplcaSet == null | "".equals(strReplcaSet)) {
                    if (!listCredential.isEmpty()) {
                        ServerAddress sa = new ServerAddress(userDB.getHost(),
                                Integer.parseInt(userDB.getPort()));
                        mongoDB = new MongoClient(sa, listCredential, clientOptions);
                    } else {
                        mongoDB = new MongoClient(new MongoClientURI(userDB.getUrl()));
                    }

                } else {
                    List<ServerAddress> listServerList = new ArrayList<ServerAddress>();
                    listServerList.add(new ServerAddress(userDB.getHost(), Integer.parseInt(userDB.getPort())));

                    String[] urls = StringUtils.split(strReplcaSet, ",");
                    for (String ipPort : urls) {
                        String[] strIpPort = StringUtils.split(ipPort, ":");

                        listServerList.add(new ServerAddress(strIpPort[0], Integer.parseInt(strIpPort[1])));
                    }

                    if (!listCredential.isEmpty()) {
                        mongoDB = new MongoClient(listServerList, listCredential, clientOptions);
                    } else {
                        mongoDB = new MongoClient(listServerList, clientOptions);
                    }
                }

                // db map? .
                dbManager.put(searchKey, mongoDB);
            }
            db = mongoDB.getDB(userDB.getDb());

        } catch (Exception e) {
            logger.error("mongodb connection error", e);
            dbManager.remove(searchKey);

            throw e;
        }
    }

    return db;

}

From source file:com.netflix.simianarmy.conformity.TestSameZonesInElbAndAsg.java

@Override
protected List<String> getAvailabilityZonesForAsg(String region, String asgName) {
    return Arrays.asList(StringUtils.split(asgToZones.get(asgName), ","));
}

From source file:joshelser.LimitAndSumColumnFamilyIterator.java

private SortedSet<Text> getColumns(Map<String, String> options) {
    String serializedColumns = options.get(COLUMNS);
    if (null == serializedColumns) {
        throw new IllegalArgumentException("Did not find " + COLUMNS + " in the options map");
    }/*from   ww w  .  ja  v  a2s . c  om*/

    String[] columns = StringUtils.split(serializedColumns, ',');
    TreeSet<Text> sortedColumns = new TreeSet<Text>();
    for (String column : columns) {
        sortedColumns.add(new Text(column));
    }

    return sortedColumns;
}

From source file:com.google.code.configprocessor.processing.ModifyAction.java

protected int parseFlags() {
    int flagsToUse = 0;
    String flagsToTest = getFlags() == null ? DEFAULT_PATTERN_FLAGS : getFlags();
    String[] flagArray = StringUtils.split(flagsToTest, PATTERN_FLAG_SEPARATOR);
    for (String flag : flagArray) {
        if ("UNIX_LINES".equals(flag)) {
            flagsToUse |= Pattern.UNIX_LINES;
        } else if ("CASE_INSENSITIVE".equals(flag)) {
            flagsToUse |= Pattern.CASE_INSENSITIVE;
        } else if ("COMMENTS".equals(flag)) {
            flagsToUse |= Pattern.COMMENTS;
        } else if ("MULTILINE".equals(flag)) {
            flagsToUse |= Pattern.MULTILINE;
        } else if ("LITERAL".equals(flag)) {
            flagsToUse |= Pattern.LITERAL;
        } else if ("DOTALL".equals(flag)) {
            flagsToUse |= Pattern.DOTALL;
        } else if ("UNICODE_CASE".equals(flag)) {
            flagsToUse |= Pattern.UNICODE_CASE;
        } else if ("CANON_EQ".equals(flag)) {
            flagsToUse |= Pattern.CANON_EQ;
        } else {//from www .jav a2  s.c om
            throw new IllegalArgumentException("Unknown flag: " + flag);
        }
    }

    return flagsToUse;
}