/* * Copyright © 2014 Cask Data, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package co.cask.cdap.common.utils; import java.util.Arrays; import java.util.Collection; /** * General string utils. */ public class StringUtils { public static final String[] EMPTY_STRING_ARRAY = {}; /** * Splits a comma separated value <code>String</code>, trimming leading and trailing whitespace on each value. * @param str a comma separated <String> with values * @return a <code>Collection</code> of <code>String</code> values */ public static Collection<String> getTrimmedStringCollection(String str) { return Arrays.asList(getTrimmedStrings(str)); } /** * Splits a comma separated value <code>String</code>, trimming leading and trailing whitespace on each value. * @param str a comma separated <String> with values * @return an array of <code>String</code> values */ public static String[] getTrimmedStrings(String str) { if (null == str || "".equals(str.trim())) { return EMPTY_STRING_ARRAY; } return str.trim().split("\\s*,\\s*"); } }