String[] toStringArray(long totalNettoTime) { String[] strings = new String[7]; strings[0] = opAlias; strings[1] = opClass; strings[2] = opType; strings[3] = String.format("%d", asMillis(bruttoNanos)); strings[4] = String.format("%d", asMillis(nettoNanos)); strings[5] = String.format("%.2f", 100.0f * nettoNanos / totalNettoTime); ArrayList<String> nameList = new ArrayList<>(bandNameSet); Collections.sort(nameList); strings[6] = StringUtils.join(nameList, ","); return strings; } }
/** * Joins the given array of tokens to a new text string. The given separator string is put between each of the * tokens. If a token in the array is <code>null</code> or empty, an empty string string is appended to the * resulting text. The resulting text string will always contain <code>tokens.length - 1</code> separators, if the * separator is not part of one of the tokens itself. * * @param tokens the list of tokens to join, must not be null * @param separator the separator string, must not be null * @return the list of tokens as a text string * @throws IllegalArgumentException if one of the arguments was null * @see #join(Object[], String) */ public static String join(List tokens, String separator) { if (tokens == null) { throw new IllegalArgumentException(UtilConstants.MSG_NULL_TOKEN); } return join(tokens.toArray(), separator); }
private void updateAutoGrouping() { tsProduct.setAutoGrouping(StringUtils.join(getEoVariables(), ":")); }
private String getAutoGrouping(ProfileReadContext ctx) { ArrayList<String> bandNames = new ArrayList<String>(); for (final Variable variable : ctx.getRasterDigest().getRasterVariables()) { final List<Dimension> dimensions = variable.getDimensions(); int rank = dimensions.size(); for (int i = 0; i < rank - 2; i++) { Dimension dim = dimensions.get(i); if (dim.getLength() > 1) { bandNames.add(variable.getFullName()); break; } } } return StringUtils.join(bandNames, ":"); }
/** * Returns the given {@link String string array} value as a string, according to the rules of the {@link Parameter parameter}. * If the value is <code>null</code> and {@link #isAllowedNullValue null value is allowed}, * this method returns an empty string, otherwise a {@link ParamFormatException} will be thrown. * * @param parameter the parameter which contains the rules to format * @param value the value to format * * @return the value as string or an empty string. * * @throws ParamFormatException if the value is <code>null</code> and * {@link #isAllowedNullValue null value is not allowed} * or the value is not an instance of {@link String String[]}. */ public String format(Parameter parameter, Object value) throws ParamFormatException { if (isAllowedNullValue(parameter, value)) { return ""; } String[] sa = castToStringArray(value); if (sa == null) { throw new ParamFormatException(parameter, ParamConstants.ERR_MSG_NOT_STRINGARRAY); } final ParamProperties props = parameter.getProperties(); final String separator = new String(new char[]{props.getValueSetDelim()}); return StringUtils.join((Object[]) value, separator); }
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); }