org.perf4j.helpers
Class MiscUtils

java.lang.Object
  extended by org.perf4j.helpers.MiscUtils

public class MiscUtils
extends Object

Miscellaneous static utility functions, mainly having to do with String parsing/formatting.

Author:
Alex Devine

Field Summary
static String NEWLINE
          The value of the line.separator system property.
 
Constructor Summary
MiscUtils()
           
 
Method Summary
static StringBuilder escapeStringForCsv(String string, StringBuilder toAppend)
          Escapes the specified string for use in a comma-separated values file.
static String formatDateIso8601(long timeInMillis)
          Formats the specified time in yyyy-MM-dd HH:mm:ss format.
static StringBuilder padIntToTwoDigits(int i, StringBuilder toAppend)
          Pads the specified int to two digits, prefixing with 0 if the value is less than 10.
static String[] splitAndTrim(String stringToSplit, String delimiter)
          Splits a string using the specified delimiter, and also trims all the resultant strings in the returned array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEWLINE

public static final String NEWLINE
The value of the line.separator system property.

Constructor Detail

MiscUtils

public MiscUtils()
Method Detail

escapeStringForCsv

public static StringBuilder escapeStringForCsv(String string,
                                               StringBuilder toAppend)
Escapes the specified string for use in a comma-separated values file.

Parameters:
string - The String to escape
toAppend - The StringBuilder to which the escaped String should be appended
Returns:
The StringBuilder passed in

padIntToTwoDigits

public static StringBuilder padIntToTwoDigits(int i,
                                              StringBuilder toAppend)
Pads the specified int to two digits, prefixing with 0 if the value is less than 10.

Parameters:
i - The value to pad, should be between 0 and 99
toAppend - The StringBuilder to which the padded value should be appended
Returns:
The StringBuilder passed in

formatDateIso8601

public static String formatDateIso8601(long timeInMillis)
Formats the specified time in yyyy-MM-dd HH:mm:ss format.

Parameters:
timeInMillis - The time in milliseconds since 1970.
Returns:
The formatted date/time String

splitAndTrim

public static String[] splitAndTrim(String stringToSplit,
                                    String delimiter)
Splits a string using the specified delimiter, and also trims all the resultant strings in the returned array. This is useful for setting multi-valued options on appenders.

Parameters:
stringToSplit - The String to be split, may not be null
delimiter - The delimiter to use to split the string, may not be null.
Returns:
The split and trimmed Strings


Copyright © 2008-2011 perf4j.org. All Rights Reserved.