/** * Splits the given text into a list of tokens by using the supplied separators. Empty tokens are created for * successive separators, or if the the supplied text starts with or ends with a separator. If the given text string * is empty, and empty array is returned, but never <code>null</code>. The tokens in the returned array will never * contain separators. * * @param text the text to be splitted into tokens * @param separators the characters used to separate the tokens * @param trimTokens if true, white space characters are removed from both ends of each token * @return an array of tokens extracted from the given text, never <code>null</code> * @see java.util.StringTokenizer */ public static String[] split(String text, char[] separators, boolean trimTokens) { List tokens = split(text, separators, trimTokens, null); return (String[]) tokens.toArray(new String[tokens.size()]); }
private static String[] parseValues(String values) { final List<String> tokens = new ArrayList<String>(); StringUtils.split(values, new char[]{'(', '\"', ',', ')'}, true, tokens); // remove empty tokens while (tokens.contains("")) { tokens.remove(""); } return tokens.toArray(new String[tokens.size()]); }
/** * Gets the resource strings for the given command command-ID and command property name. */ protected String[] getConfigStrings(ConfigurationElement config, String elementName) { String value = getConfigString(config, elementName); if (value == null) { return null; } return StringUtils.split(value, new char[]{','}, true); }
/** * Gets the resource strings for the given command command-ID and command property name. */ protected String[] getResourceStrings(ResourceBundle resourceBundle, String commandPropertyName) { String value = getResourceString(resourceBundle, commandPropertyName); if (value == null) { return null; } return StringUtils.split(value, new char[]{','}, true); }
/** * Converts the given text into an array of <code>String</code> tokens. * <p/> * <p>The number values are expected to be separated by one of the characters given in the delimiter string. * <p/> * <p>If the delimiter string is null or empty, the default delimiter "," will be used. * * @param text the text to be converted * @param delims the delimiter characters used between the tokens * @return the <code>String</code> array parsed from the given text, never null * @throws IllegalArgumentException if the text is null or cannot be converted to an array of the requested number * type */ public static String[] toStringArray(String text, String delims) { Guardian.assertNotNull("text", text); if (delims == null || delims.length() == 0) { delims = ","; } return split(text, delims.toCharArray(), true); }
/** * Scans the map key passed in and loads the ranges read out to the coefficients passed in */ private static void loadMapStringToCoefficients(String map, SstCoefficients coeffs) { String[] rangeStrings = StringUtils.split(map, _separators, true); // check that we have TWO values if (rangeStrings.length != 2) { throw new OperatorException("illegal coefficient file format: map.x must have two values"); } coeffs.setRange(Integer.parseInt(rangeStrings[0]), Integer.parseInt(rangeStrings[1])); }
/** * Converts a textual representation of an RGB(A) color to a <code>Color</code> object. */ public static Color parseColor(String text) throws NumberFormatException { Color color = null; String trimedText = text.trim(); String[] components = split(trimedText, new char[]{','}, true /*trim?*/); try { if (components.length == 1) { color = Color.decode(trimedText); } if (components.length >= 3) { int r = Integer.parseInt(components[0]); int g = Integer.parseInt(components[1]); int b = Integer.parseInt(components[2]); int a = 255; if (components.length > 3) { a = Integer.parseInt(components[3]); } color = new Color(r, g, b, a); } } catch (NumberFormatException e) { color = null; } return color; }
/** * Converts the given text into an <code>float</code> array. * <p/> * <p>The number values are expected to be separated by one of the characters given in the delimiter string. * <p/> * <p>If the delimiter string is null or empty, the default delimiter "," will be used. * * @param text the text to be converted * @param delim the delimiter between the number values * @return the <code>float</code> array parsed from the given text * @throws IllegalArgumentException if the text is null or cannot be converted to an array of the requested number * type */ public static float[] toFloatArray(String text, String delim) { Guardian.assertNotNull("text", text); if (delim == null || delim.length() == 0) { delim = ","; } final String[] tokens = split(text, delim.toCharArray(), true); final float[] numbers = new float[tokens.length]; for (int i = 0; i < numbers.length; i++) { numbers[i] = Float.parseFloat(tokens[i]); } return numbers; }
/** * Converts the given text into an <code>double</code> array. * <p/> * <p>The number values are expected to be separated by one of the characters given in the delimiter string. * <p/> * <p>If the delimiter string is null or empty, the default delimiter "," will be used. * * @param text the text to be converted * @param delim the delimiter between the number values * @return the <code>double</code> array parsed from the given text * @throws IllegalArgumentException if the text is null or cannot be converted to an array of the requested number * type */ public static double[] toDoubleArray(String text, String delim) { Guardian.assertNotNull("text", text); if (delim == null || delim.length() == 0) { delim = ","; } final String[] tokens = split(text, delim.toCharArray(), true); final double[] numbers = new double[tokens.length]; for (int i = 0; i < numbers.length; i++) { numbers[i] = Double.parseDouble(tokens[i]); } return numbers; }
/** * Converts the given text into an <code>int</code> array. * <p/> * <p>The number values are expected to be separated by one of the characters given in the delimiter string. * <p/> * <p>If the delimiter string is null or empty, the default delimiter "," will be used. * * @param text the text to be converted * @param delim the delimiter between the number values * @return the <code>int</code> array parsed from the given text * @throws IllegalArgumentException if the text is null or cannot be converted to an array of the requested number * type */ public static int[] toIntArray(String text, String delim) { Guardian.assertNotNull("text", text); if (delim == null || delim.length() == 0) { delim = ","; } final String[] tokens = split(text, delim.toCharArray(), true); final int[] numbers = new int[tokens.length]; for (int i = 0; i < numbers.length; i++) { numbers[i] = Integer.parseInt(tokens[i]); } return numbers; }
/** * Scans the String passed in for the b coefficient set and loads them into the coefficients passed in */ private static void load_B_ToCoefficients(String b_values, SstCoefficients coeffs) { String[] bStrings = StringUtils.split(b_values, _separators, true); // check that we have FOUR values if (bStrings.length != _numBCoeffs) { throw new OperatorException("illegal coefficient file format: b.x must have " + _numBCoeffs + " values"); } // convert the string array to float values float[] bCoeffs = new float[bStrings.length]; for (int n = 0; n < bStrings.length; n++) { bCoeffs[n] = Float.parseFloat(bStrings[n]); } // and set coeffs.set_B_Coeffs(bCoeffs); }
/** * Scans the String passed in for the d coefficient set and loads them into the coefficients passed in */ private static void load_D_ToCoefficients(String d_values, SstCoefficients coeffs) { String[] dStrings = StringUtils.split(d_values, _separators, true); // check that we have SEVEN values if (dStrings.length != _numDCoeffs) { throw new OperatorException("illegal coefficient file format: d.x must have " + _numDCoeffs + " values"); } // convert the string array to float values float[] dCoeffs = new float[dStrings.length]; for (int n = 0; n < dStrings.length; n++) { dCoeffs[n] = Float.parseFloat(dStrings[n]); } // and set coeffs.set_D_Coeffs(dCoeffs); }
/** * Scans the String passed in for the a coefficient set and loads thme into the coefficients passed in */ private static void load_A_ToCoefficients(String a_values, SstCoefficients coeffs) { String[] aStrings = StringUtils.split(a_values, _separators, true); // check that we have THREE values if (aStrings.length != _numACoeffs) { throw new OperatorException("illegal coefficient file format: a.x must have " + _numACoeffs + " values"); } // convert the string array to float values float[] aCoeffs = new float[aStrings.length]; for (int n = 0; n < aStrings.length; n++) { aCoeffs[n] = Float.parseFloat(aStrings[n]); } // and set coeffs.set_A_Coeffs(aCoeffs); }
/** * Scans the String passed in for the c coefficient set and loads them into the coefficients passed in */ private static void load_C_ToCoefficients(String c_values, SstCoefficients coeffs) { String[] cStrings = StringUtils.split(c_values, _separators, true); // check that we have FIVE values if (cStrings.length != _numCCoeffs) { throw new OperatorException("illegal coefficient file format: c.x must have " + _numCCoeffs + " values"); } // convert the string array to float values float[] cCoeffs = new float[cStrings.length]; for (int n = 0; n < cStrings.length; n++) { cCoeffs[n] = Float.parseFloat(cStrings[n]); } // and set coeffs.set_C_Coeffs(cCoeffs); }
private String[] convertStringArrayValue(String key) { Object value = getPropertyValue(key); String[] arrayValue = null; if (value != null) { if (value instanceof String[]) { arrayValue = (String[]) value; } else if (value instanceof String) { char separator = getValueSetDelim(); arrayValue = StringUtils.split(value.toString(), new char[]{separator}, true); setPropertyValue(key, arrayValue); } } return arrayValue; }
public Object parse(Parameter parameter, String text) throws ParamParseException { Debug.assertTrue(text != null); if (isAllowedNullText(parameter, text)) { // return null, since null values are allowed return null; } final ParamProperties props = parameter.getProperties(); final char[] separators = new char[]{props.getValueSetDelim()}; return StringUtils.split(text, separators, true); }
public void testSplit() { try { StringUtils.split(null, new char[]{','}, true); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { // expected Exception because the text is null } final String[] strings1 = StringUtils.split("", new char[]{','}, true); assertNotNull(strings1); assertEquals(0, strings1.length); final String[] strings2 = StringUtils.split(" ", new char[]{','}, true); assertNotNull(strings2); assertEquals(1, strings2.length); final String[] strings3 = StringUtils.split(",", new char[]{','}, true); assertNotNull(strings3); assertEquals(2, strings3.length); final String[] strings4 = StringUtils.split(" aaa , , bbb , ccc ", new char[]{','}, true); assertNotNull(strings4); assertEquals(4, strings4.length); assertEquals("aaa", strings4[0]); assertEquals("", strings4[1]); assertEquals("bbb", strings4[2]); assertEquals("ccc", strings4[3]); }
public void testJoinAndSplit() { Object[] tokensOrig = {"Fischer's", "Fritz", "fischt", "frische", "", "Fische"}; String textOrig1 = "Fischer's Fritz fischt frische Fische"; String textOrig2 = "Fischer's|Fritz|fischt|frische||Fische"; assertEquals(StringUtils.join(tokensOrig, " "), textOrig1); assertEquals(StringUtils.join(tokensOrig, "|"), textOrig2); assertEquals(ArrayUtils.equalArrays(StringUtils.split(textOrig1, new char[]{' '}, false), tokensOrig), true); assertEquals(ArrayUtils.equalArrays(StringUtils.split(textOrig2, new char[]{'|'}, false), tokensOrig), true); }
private String getSuitableBitmaskDefDescription(Term.Ref ref) { String description = null; final String symbolName = ref.getSymbol().getName(); if (isFlagSymbol(symbolName)) { final String[] strings = StringUtils.split(symbolName, new char[]{'.'}, true); final String nodeName = strings[0]; final String flagName = strings[1]; final RasterDataNode rasterDataNode = getRasterDataNode(nodeName); if (rasterDataNode instanceof Band) { final FlagCoding flagCoding = ((Band) rasterDataNode).getFlagCoding(); if (flagCoding != null) { final MetadataAttribute attribute = flagCoding.getAttribute(flagName); if (attribute != null) { description = attribute.getDescription(); } } } } else { final RasterDataNode rasterDataNode = getRasterDataNode(symbolName); if (rasterDataNode != null) { description = rasterDataNode.getDescription(); } } return description; }