/** * Combine the lines into a single string, using the new line character as the delimiter. This is compatible with * {@link #splitLines(String)}. * * @param lines the lines to be combined * @return the combined lines, or an empty string if there are no lines */ public static String combineLines( String[] lines ) { return combineLines(lines, '\n'); }
/** * Log a message at the TRACE level according to the specified format and (optional) parameters. The message should contain a * pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient * and avoids superfluous object creation when the logger is disabled for the TRACE level. * * @param message the message string * @param params the parameter values that are to replace the variables in the format string */ public void trace( String message, Object... params ) { if (!isTraceEnabled()) return; if (message == null) return; this.delegate.trace(StringUtil.createString(message, params)); }
/** * Set the length of the string, padding with the supplied character if the supplied string is shorter than desired, or * truncating the string if it is longer than desired. Unlike {@link #justifyLeft(String, int, char)}, this method does not * remove leading and trailing whitespace. * * @param original the string for which the length is to be set; may not be null * @param length the desired length; must be positive * @param padChar the character to use for padding, if the supplied string is not long enough * @return the string of the desired length * @see #justifyLeft(String, int, char) */ public static String setLength( String original, int length, char padChar ) { return justifyLeft(original, length, padChar, false); }
final float barLengthForHundredPercent = this.buckets.isEmpty() ? maxBarLength : 100.0f * maxBarLength / getMaximumPercentage(); final String fullLengthBar = StringUtil.createString('*', (int)barLengthForHundredPercent); List<String> result = new LinkedList<String>(); result.add(StringUtil.justifyLeft("Ranges", rangeWidth, ' ') + " Distribution"); result.add(StringUtil.createString('-', rangeWidth) + ' ' + StringUtil.createString('-', barWidth)); for (Bucket bucket : this.buckets) { float percent = bucket.getPercentageOfValues(); StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(StringUtil.justifyLeft(bucket.getLowerBound().toString(), maxLowerBoundLength, ' ')); sb.append(" - "); sb.append(StringUtil.justifyLeft(bucket.getUpperBound().toString(), maxUpperBoundLength, ' ')); sb.append("] "); int barLength = Math.max((int)(barLengthForHundredPercent * percent / 100.0f), 0);
/** * Truncate the supplied string to be no more than the specified length. This method returns an empty string if the supplied * object is null. * * @param obj the object from which the string is to be obtained using {@link Object#toString()}. * @param maxLength the maximum length of the string being returned * @return the supplied string if no longer than the maximum length, or the supplied string truncated to be no longer than the * maximum length (including the suffix) * @throws IllegalArgumentException if the maximum length is negative */ public static String truncate( Object obj, int maxLength ) { return truncate(obj, maxLength, null); }
try { String content = IoUtil.read(stream); lines = StringUtil.splitLines(content); } catch (IOException e) { I18n msg = CommonI18n.unableToAccessResourceFileFromClassLoader;
/** * Log a message at the DEBUG level according to the specified format and (optional) parameters. The message should contain a * pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient * and avoids superfluous object creation when the logger is disabled for the DEBUG level. * * @param message the message string * @param params the parameter values that are to replace the variables in the format string */ public void debug( String message, Object... params ) { if (!isDebugEnabled()) return; if (message == null) return; this.delegate.debug(StringUtil.createString(message, params)); }
protected static String justifyLeft( String str, final int width, char padWithChar, boolean trimWhitespace ) { // Trim the leading and trailing whitespace ... str = str != null ? (trimWhitespace ? str.trim() : str) : ""; int addChars = width - str.length(); if (addChars < 0) { // truncate return str.subSequence(0, width).toString(); } // Write the content ... final StringBuilder sb = new StringBuilder(); sb.append(str); // Append the whitespace ... while (addChars > 0) { sb.append(padWithChar); --addChars; } return sb.toString(); }
/** * Log an exception (throwable) at the DEBUG level with an accompanying message. If the exception is null, then this method * calls {@link #debug(String, Object...)}. * * @param t the exception (throwable) to log * @param message the message accompanying the exception * @param params the parameter values that are to replace the variables in the format string */ public void debug( Throwable t, String message, Object... params ) { if (!isDebugEnabled()) return; if (t == null) { debug(message, params); return; } if (message == null) { this.delegate.debug(null, t); return; } this.delegate.debug(StringUtil.createString(message, params), t); }
/** * Log an exception (throwable) at the TRACE level with an accompanying message. If the exception is null, then this method * calls {@link #trace(String, Object...)}. * * @param t the exception (throwable) to log * @param message the message accompanying the exception * @param params the parameter values that are to replace the variables in the format string */ public void trace( Throwable t, String message, Object... params ) { if (!isTraceEnabled()) return; if (t == null) { this.trace(message, params); return; } if (message == null) { this.delegate.trace(null, t); return; } this.delegate.trace(StringUtil.createString(message, params), t); }
@Override public String toString() { int count = this.getCount(); String samples = Inflector.getInstance().pluralize("sample", count); return StringUtil.createString("{0} {1}: min={2}; avg={3}; max={4}", count, samples, this.minimum, this.mean, this.maximum); }
/** * Get the localized text for the supplied locale, replacing the parameters in the text with those supplied. * * @param locale the locale, or <code>null</code> if the {@link Locale#getDefault() current (default) locale} should be used * @param arguments the arguments for the parameter replacement; may be <code>null</code> or empty * @return the localized text */ public String text( Locale locale, Object... arguments ) { try { String rawText = rawText(locale == null ? Locale.getDefault() : locale); return StringUtil.createString(rawText, arguments); } catch (IllegalArgumentException err) { throw new IllegalArgumentException(CommonI18n.i18nRequiredToSuppliedParameterMismatch.text(id, i18nClass, err.getMessage())); } catch (SystemFailureException err) { return '<' + err.getMessage() + '>'; } }
@Override public String toString() { int count = this.getCount(); String samples = Inflector.getInstance().pluralize("sample", count); return StringUtil.createString("{0} {1}: min={2}; avg={3}; median={4}; stddev={5}; max={6}", count, samples, this.getMinimum(), this.getMean(), this.getMedian(), this.getStandardDeviation(), this.getMaximum()); }