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:com.pamarin.game24.Probability.java

private boolean contains(String str, String target) {
    if (!str.isEmpty()) {
        String[] els = StringUtils.split(str, ":");
        for (String el : els) {
            if (el.equals(target)) {
                return true;
            }//from w  ww . j ava 2 s  .  c om
        }
    }

    return false;
}

From source file:com.monarchapis.driver.util.MIMEParse.java

/**
 * Carves up a mime-type and returns a ParseResults object
 * /*from   w ww.  jav  a  2  s .c o  m*/
 * For example, the media range 'application/xhtml;q=0.5' would get parsed
 * into:
 * 
 * ('application', 'xhtml', {'q', '0.5'})
 * 
 * @param mimeType
 *            The mime type
 */
protected static ParseResults parseMimeType(String mimeType) {
    String[] parts = StringUtils.split(mimeType, ";");
    ParseResults results = new ParseResults();
    results.params = new HashMap<String, String>();

    for (int i = 1; i < parts.length; ++i) {
        String p = parts[i];
        String[] subParts = StringUtils.split(p, '=');

        if (subParts.length == 2) {
            results.params.put(subParts[0].trim(), subParts[1].trim());
        }
    }

    String fullType = parts[0].trim();

    // Java URLConnection class sends an Accept header that includes a
    // single "*" - Turn it into a legal wildcard.
    if (fullType.equals("*")) {
        fullType = "*/*";
    }

    String[] types = StringUtils.split(fullType, "/");
    results.type = types[0].trim();
    results.subType = types[1].trim();

    return results;
}

From source file:com.nerve.commons.repository.utils.reflection.ReflectionUtils.java

/**
 * Getter./*from   w  ww . java2s  . c om*/
 * ???.??.
 */
public static Object invokeGetter2(Object obj, String propertyName) {
    Object object = obj;
    for (String name : StringUtils.split(propertyName, ".")) {
        String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
        object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
    }
    return object;
}

From source file:com.thruzero.common.core.utils.MapUtilsExt.java

/**
 * Takes the comma separated series of keys and returns an array of int values for each key in the series (trimming
 * each key segment before lookup).//from   www  .  j a  va  2s .  c o  m
 *
 * @param key to a value in the map, that's a comma separated series of strings that are in-turn, each used to look up
 * a value in the map (e.g., "foo, bar").
 * @return value for each key in the series (e.g., int[] {123, 456}).
 */
public static <K, V> int[] getValueAsIntSeries(final K key, final Map<K, V> map) {
    Object mapValue = map.get(key);

    if (mapValue == null) {
        return null;
    } else {
        String[] series = StringUtils.split(mapValue.toString(), ',');

        return getValueAsIntSeries(series);
    }
}

From source file:com.techcavern.wavetact.ircCommands.dnsinfo.BlacklistLookup.java

@Override
public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel,
        boolean isPrivate, int userPermLevel, String... args) throws Exception {
    String BeforeIP = GeneralUtils.getIP(args[1], network, false);
    if (BeforeIP == null) {
        IRCUtils.sendError(user, network, channel, "Invalid ip/user", prefix);
        return;//from  w  w  w  .  j  a v a  2s.c o m
    } else if (BeforeIP.contains(":")) {
        IRCUtils.sendError(user, network, channel, "IPv6 is not supported", prefix);
        return;
    }
    String[] IPString = StringUtils.split(BeforeIP, ".");
    String IP = "";
    for (int i = IPString.length - 1; i >= 0; i--) {
        if (IP.isEmpty()) {
            IP = IPString[i];
        } else {
            IP += "." + IPString[i];
        }
    }
    Boolean sent = false;
    Resolver resolver = new SimpleResolver();
    Result<Record> blacklist = DatabaseUtils.getBlacklists(args[0]);
    if (blacklist.isEmpty()) {
        IRCUtils.sendError(user, network, channel, "No " + args[0] + " blacklists found in database", prefix);
        return;
    }
    for (org.jooq.Record Blacklist : blacklist) {
        Lookup lookup = new Lookup(IP + "." + Blacklist.getValue(BLACKLISTS.URL), Type.ANY);
        lookup.setResolver(resolver);
        lookup.setCache(null);
        org.xbill.DNS.Record[] records = lookup.run();
        if (lookup.getResult() == Lookup.SUCCESSFUL) {
            String msg = BeforeIP + " found in " + Blacklist.getValue(BLACKLISTS.URL);
            sent = true;
            for (org.xbill.DNS.Record rec : records) {
                if (rec instanceof TXTRecord) {
                    msg += " - [" + Type.string(rec.getType()) + "] " + StringUtils.join(rec, " ");
                }
            }
            IRCUtils.sendMessage(user, network, channel,
                    BeforeIP + " found in " + Blacklist.getValue(BLACKLISTS.URL), prefix);
        }
    }
    if (!sent) {
        IRCUtils.sendMessage(user, network, channel, BeforeIP + " not found in " + args[0] + " blacklists",
                prefix);
    }

}

From source file:com.adguard.commons.utils.ProductVersion.java

public ProductVersion(String version) {
    if (StringUtils.isEmpty(version)) {
        return;/*from  w ww.j  ava  2  s . c  o  m*/
    }

    String[] parts = StringUtils.split(version, ".");

    if (parts.length >= 4) {
        build = parseVersionPart(parts[3]);
    }
    if (parts.length >= 3) {
        revision = parseVersionPart(parts[2]);
    }
    if (parts.length >= 2) {
        minor = parseVersionPart(parts[1]);
    }
    if (parts.length >= 1) {
        major = parseVersionPart(parts[0]);
    }
}

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

public void onConnect(ConnectEvent event) throws Exception {
    String NickServCommand = DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot()))
            .getValue(NETWORKS.NICKSERVCOMMAND);
    String NickServNick = DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot()))
            .getValue(NETWORKS.NICKSERVNICK);
    if (NickServNick == null) {
        NickServNick = "NickServ";
    }/*from  w w w .j  a  va  2s. co m*/
    if (NickServCommand != null) {
        event.getBot().sendRaw().rawLine("PRIVMSG " + NickServNick + " :" + NickServCommand);
    }
    TimeUnit.SECONDS.sleep(10);
    Registry.messageQueue.get(event.getBot()).addAll(Arrays
            .asList(StringUtils.split(DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(event.getBot()))
                    .getValue(NETWORKS.CHANNELS), ", "))
            .stream().map(channel -> ("JOIN :" + channel)).collect(Collectors.toList()));
    TimeUnit.SECONDS.sleep(10);
    ListenerManager listenerManager = event.getBot().getConfiguration().getListenerManager();
    listenerManager.getListeners().stream()
            .filter(lis -> !(lis instanceof ConnectListener || lis instanceof CoreHooks))
            .forEach(listener -> listenerManager.removeListener(listener));
    listenerManager.addListener(new ChanMsgListener());
    listenerManager.addListener(new PartListener());
    listenerManager.addListener(new PrivMsgListener());
    listenerManager.addListener(new KickListener());
    listenerManager.addListener(new BanListener());
    listenerManager.addListener(new JoinListener());
    listenerManager.addListener(new FunMsgListener());
    listenerManager.addListener(new RelayMsgListener());
    listenerManager.addListener(new InviteListener());
    listenerManager.addListener(new TellMsgListener());
    listenerManager.addListener(new NoticeListener());
    listenerManager.addListener(new ActionListener());
    listenerManager.addListener(new CTCPListener());
    IRCUtils.sendLogChanMsg(event.getBot(), "[Connection Successful]");
}

From source file:com.i5le.framwork.core.persistence.SearchFilter.java

/**
 * searchParamskey?LIKES_name//from   ww  w.j av  a2  s  . c  o  m
 */
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 (StringUtils.isBlank((String) value)) {
            continue;
        }
        // operatorfiledAttribute
        String[] names = StringUtils.split(key, "_");
        if (names.length != 2 && names.length != 3) {
            // throw new IllegalArgumentException(key +
            // " is not a valid search filter name");
            logger.warn(key + " is not a valid search filter name");
            continue;
        }

        Class<?> propertyClass = null;
        if (names.length == 3) {
            try {
                propertyClass = Enum.valueOf(PropertyType.class, names[2]).getValue();
                logger.debug(key + ":" + propertyClass.getName());
                if (propertyClass != null) {
                    if (propertyClass.getName().equals("java.util.Date")) {
                        String str = value.toString();
                        if (str.length() == 10) {
                            if (names[0].equals("GT") || names[0].equals("GTE")) {
                                str += " 00:00:00";
                            } else if (names[0].equals("LT") || names[0].equals("LTE")) {
                                str += " 23:59:59";
                            }
                        }
                        value = dateTimeFormat.parseObject(str);
                    } else {
                        //value = ConvertUtils.convert(value, propertyClass);
                    }

                }

            } catch (RuntimeException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            } catch (ParseException e) {
                logger.warn(key + " PropertyType is not a valid type!", e);
            }
        }

        String filedName = names[1];
        Operator operator = Operator.valueOf(names[0]);

        // searchFilter
        SearchFilter filter = new SearchFilter(filedName, operator, value);
        filters.put(key, filter);
    }

    return filters;
}

From source file:com.xpn.xwiki.notify.XWikiPageNotification.java

public void notify(XWikiNotificationRule rule, XWikiDocument doc, String action, XWikiContext context) {
    try {/*from  ww w  . j  av  a2s .  c om*/
        String notifpages = context.getWiki().getXWikiPreference("notification_pages", context);
        if ((notifpages != null) && (!notifpages.equals(""))) {
            String[] notifpages2 = StringUtils.split(notifpages, " ,");
            for (int i = 0; i < notifpages2.length; i++) {
                notifyPage(notifpages2[i], rule, doc, action, context);
            }
        }
        String xnotif = (context.getRequest() != null) ? context.getRequest().getParameter("xnotification")
                : null;
        if ((xnotif != null) && (!xnotif.equals(""))) {
            notifyPage(xnotif, rule, doc, action, context);
        }
    } catch (Throwable e) {
        XWikiException e2 = new XWikiException(XWikiException.MODULE_XWIKI_NOTIFICATION,
                XWikiException.ERROR_XWIKI_NOTIFICATION, "Error executing notifications", e);
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error(e2.getFullMessage());
        }
    }
}

From source file:com.thinkbiganalytics.policy.validation.LookupValidator.java

public LookupValidator(@PolicyPropertyRef(name = "List") String values) {
    log.info("Lookup Validator for {} ", values);
    this.lookupList = values;
    String[] arr = StringUtils.split(values, ",");
    if (arr != null) {
        lookupValues = new HashSet<>(Arrays.asList(arr));
    } else {//from   ww  w  .java  2s.c o  m
        log.error("Lookup Validator error NULL array ");
    }
}