com.ebay.jetstream.util.StringUtils Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright © 2012-2015 eBay Software Foundation
* This program is dual licensed under the MIT and Apache 2.0 licenses.
* Please see LICENSE for more information.
*******************************************************************************/
package com.ebay.jetstream.util;
import java.util.ArrayList;
import java.util.List;
public class StringUtils {
private static final String STRING_LIST_SEPARATOR = ",";
/**
* Converts comma-separated string into a list. Performs trimming, ignores empty strings. For EPL like
*
* SELECT com.ebay.jetstream.util.StringUtils.convertToList('One, Two, Three, ') AS TopicList FROM ESPTestEvent1
*
* it returns a list of three strings: "One", "Two", "Three"
*
* @param vars
* @return
*/
public static List convertToList(String vars) {
List resultList = new ArrayList();
String[] resultArray = vars.split(STRING_LIST_SEPARATOR);
for (String var : resultArray) {
var = var.trim();
if (var.length() > 0) {
resultList.add(var);
}
}
return resultList;
}
}