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.jdom.word.playdough.model.gamepack.GamePackFileParser.java

private Map<String, List<Bonus>> setupBonusesMap(Properties properties) {
    Map<String, List<Bonus>> bonusesMap = new HashMap<String, List<Bonus>>();

    for (Bonus bonus : Bonus.AVAILABLE_BONUSES) {
        for (Object propertyKey : properties.keySet()) {
            String key = (String) propertyKey;

            if (key.endsWith(bonus.getLookupSuffix())) {
                String originalWord = key.substring(0, key.indexOf(bonus.getLookupSuffix()));
                String answersApplicableToBonusString = properties.getProperty(key);
                if (answersApplicableToBonusString != null) {
                    String[] answersApplicableToBonus = StringUtils.split(answersApplicableToBonusString,
                            PropertiesUtil.SEPARATOR);

                    for (String answer : answersApplicableToBonus) {
                        String bonusesMapKey = GamePack.getBonusesLookupKey(originalWord, answer);
                        List<Bonus> bonusesForAnswer = CollectionUtil.getOrPutAndGetList(bonusesMap,
                                bonusesMapKey);
                        bonusesForAnswer.add(bonus);
                    }/*from   w ww  .  j a va 2s .  c o  m*/
                }
            }
        }
    }

    return bonusesMap;
}

From source file:io.wcm.handler.media.CropDimension.java

/**
 * Get crop dimension from crop string./*from   w w  w  .j  ava2s  . co m*/
 * Please note: Crop string contains not width/height as 3rd/4th parameter but right, bottom.
 * @param cropString Cropping string from CQ5 smartimage widget
 * @return Crop dimension instance
 * @throws IllegalArgumentException if crop string syntax is invalid
 */
public static CropDimension fromCropString(String cropString) {
    if (StringUtils.isEmpty(cropString)) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }

    // strip off optional size parameter after "/"
    String crop = cropString;
    if (StringUtils.contains(crop, "/")) {
        crop = StringUtils.substringBefore(crop, "/");
    }

    String[] parts = StringUtils.split(crop, ",");
    if (parts.length != 4) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }
    long x1 = NumberUtils.toLong(parts[0]);
    long y1 = NumberUtils.toLong(parts[1]);
    long x2 = NumberUtils.toLong(parts[2]);
    long y2 = NumberUtils.toLong(parts[3]);
    long width = x2 - x1;
    long height = y2 - y1;
    if (x1 < 0 || y1 < 0 || width <= 0 || height <= 0) {
        throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'.");
    }
    return new CropDimension(x1, y1, width, height);
}

From source file:$.User.java

@Transient
    @JsonIgnore/* w  w  w  . j  a va 2 s . c o m*/
    public List<String> getRoleList() {
        // ???List.
        return ImmutableList.copyOf(StringUtils.split(roles, ","));
    }

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

@Test
public void testBestMatch() {
    List<String> mimeTypesSupported = Arrays
            .asList(StringUtils.split("application/xbel+xml,application/xml", ','));

    // direct match
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/xbel+xml"), "application/xbel+xml");

    // direct match with a q parameter
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/xbel+xml;q=1"), "application/xbel+xml");

    // direct match of our second choice with a q parameter
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/xml;q=1"), "application/xml");

    // match using a subtype wildcard
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/*;q=1"), "application/xml");

    // match using a type wildcard//w w w.j a  v  a2 s .co  m
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "*/*"), "application/xml");

    mimeTypesSupported = Arrays.asList(StringUtils.split("application/xbel+xml,text/xml", ','));

    // match using a type versus a lower weighted subtype
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1"), "text/xml");

    // fail to match anything
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "text/html,application/atom+xml; q=0.9"), "");

    // common AJAX scenario
    mimeTypesSupported = Arrays.asList(StringUtils.split("application/json,text/html", ','));
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/json,text/javascript, */*"),
            "application/json");

    // verify fitness ordering
    assertEquals(MIMEParse.bestMatch(mimeTypesSupported, "application/json,text/html;q=0.9"),
            "application/json");
}

From source file:com.thinkmore.framework.orm.PropertyFilter.java

/**
 * @param filterName ,???. /* ww  w . ja  v a2  s .  c om*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtil.convertStringToObject(value, propertyType);
}

From source file:com.uber.stream.kafka.chaperone.collector.KafkaMonitor.java

public KafkaMonitor(long checkIntervalInSec, String brokerList, String auditTopics,
        IAuditReporter auditReporter) {//from   w  ww  . j  a  v  a  2  s  .co  m
    this.checkIntervalInSec = checkIntervalInSec;
    this.brokerList = Arrays.asList(StringUtils.split(brokerList, ","));
    this.auditTopics = Arrays.asList(StringUtils.split(auditTopics, ","));
    this.auditReporter = auditReporter;
    this.brokerConsumer = new HashMap<>();
    this.partitionLeader = new HashMap<>();
    this.partitionLag = new ConcurrentHashMap<>();
    this.partitionInjected = new HashSet<>();

    cronExecutor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("kafka-monitor-%d").build());
}

From source file:com.thinkbiganalytics.policy.precondition.FeedExecutedSinceFeeds.java

public FeedExecutedSinceFeeds(@PolicyPropertyRef(name = "Since Feed") String sinceCategoryAndFeedName,
        @PolicyPropertyRef(name = "Dependent Feeds") String categoryAndFeeds) {
    this.sinceCategoryAndFeedName = sinceCategoryAndFeedName;
    this.categoryAndFeeds = categoryAndFeeds;
    categoryAndFeedList = Arrays.asList(StringUtils.split(categoryAndFeeds, ","));
}

From source file:com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler.ThirdBrainFx2TweetHandler.java

@Override
protected NewFXTradeTweet<String> parseNewTrade(String[] tokens) {
    String ccyPair = this.deriveCcyPair(tokens);
    String side = tokens[3];/*from  ww  w . jav a2  s .com*/
    double stopLoss = 0.0;
    double takeProfit = 0.0;
    try {
        if (tokens[6].startsWith(TPCOLON)) {
            String[] tokens2 = StringUtils.split((String) tokens[6], TradingConstants.COLON);
            takeProfit = Double.parseDouble(tokens2[1]);
        }
        if (SL.equals(tokens[4]) && tokens[5].startsWith(TradingConstants.COLON)) {
            stopLoss = Double.parseDouble(tokens[5].substring(1));
        }
        return new NewFXTradeTweet<>(new TradeableInstrument<>(ccyPair), 0.0, stopLoss, takeProfit,
                BUY.equals(side) ? TradingSignal.LONG : TradingSignal.SHORT);
    } catch (NumberFormatException nfe) {
        LOG.error(nfe);
        return null;
    }
}

From source file:com.eudemon.taurus.app.service.ShiroDbRealm.java

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
    User user = userService.findUserByName(shiroUser.loginName);
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    info.addRoles(Arrays.asList(StringUtils.split(user.getRoles(), ",")));
    info.addStringPermission(user.getPermissions());
    return info;//  w  w w .j  a  va2s .  c o m
}

From source file:com.github.rvesse.airline.parser.options.ListValueOptionParser.java

protected final List<String> getValues(String list) {
    return AirlineUtils.arrayToList(StringUtils.split(list, this.separator));
}