edu.duke.cs.banjo.utility
Class StringUtil

java.lang.Object
  extended byedu.duke.cs.banjo.utility.StringUtil

public class StringUtil
extends java.lang.Object

Contains a collection of general purpose string-related code.

Details:

Change History:
Created on Apr 2, 2004

10/13/2005 (v2.0) hjs Added formatDecimalDisplay method for more robust display of decimal numbers (formatting)

hjs (v2.1) Add methods for generating "subordinate" file names when dealing with output from multiple threads.

Author:
Jurgen Sladeczek (hjs)
For the latest info, please visit www.cs.duke.edu.

Field Summary
private static java.lang.String cachedTimeStamp
           
private static int MILLISECSPERDAY
           
private static int MILLISECSPERHOUR
           
private static int MILLISECSPERMINUTE
           
private static int MILLISECSPERSECOND
           
private static Settings processData
           
 
Constructor Summary
(package private) StringUtil()
          (Empty) constructor for static StringUtil class.
 
Method Summary
static java.lang.String arrayAsString(int[] _intArray)
          Utility method (debug/test): Trivial helper function for quick trace output.
static java.lang.String compileMemoryInfo(java.lang.String _info)
          Composes a basic string that details the memory use of the application at the current moment.
static java.lang.String composeErrorMessage(SettingItem _settingItem1, SettingItem _settingItem2, java.lang.String _strCondition)
          Composes an error message that resulted from a comparison between 2 setting items.
static java.lang.String composeErrorMessage(SettingItem _settingItem, java.lang.String _strCondition)
          Composes an error message that resulted from a comparison between 2 setting items.
static java.lang.String fillSpaces(java.lang.String _startString, int _fillLength)
          Utility method: Fills in blank spaces for creating formatted output.
static java.lang.String fillSpacesLeft(java.lang.String _startString, int _fillLength)
          Utility method: Fills in blank spaces for creating formatted output, to the left of the supplied string.
static java.lang.String formatDecimalDisplay(double _numberToFormat, java.lang.String _formatToApply)
          Utility function for applying formatting to numbers.
static java.lang.StringBuffer formatElapsedTime(double _elapsedTime, int _decimalsToDisplay, int _formatFlag)
          Applies formatting to the elapsed time, based on supplied parameters.
static java.lang.StringBuffer formatRightLeftJustified(java.lang.String _prefix, java.lang.String _displayItem, java.lang.String _displayItemValue, java.lang.String _separator, int _lineLength)
          Utility method: Creates a line of text that is both left and right justified.
static java.lang.StringBuffer getBanjoSignature()
          Compiles the setting values that we group as the "Banjo signature".
static java.lang.String getClassName(java.lang.Object _someObj)
          Utility method: Returns the name of the class where this method is called from.
static java.lang.StringBuffer getJobSignature(Settings _processData)
          Compiles the setting values that we group as the "job signature".
static java.lang.String getReportFileNameMT(java.lang.String _reportFileName, java.lang.String _prefix, int _threadIndex)
          Generates the report file name for a given thread in the multi-threaded scenario.
static java.lang.String listNodes(int[][] _nodeList)
          Utility function for listing a node list (parent list), in the form array[variableIndex][lagIndex].
static java.lang.StringBuffer listSettings(java.util.Properties _settingsToList)
          Utility method (debug/test): Compiles a list of the supplied properties.
static java.lang.String removeTrailingComment(java.lang.String _stringToProcess)
          Utility method: Removes comments at the end of a line of text.
static void setProcessData(Settings _processData)
          Provides access to the (main) settings.
static java.lang.String timeStamp(Settings _processData, java.lang.String _settingName, java.lang.String _timeStampFormat, java.lang.String _defaultTimeStampFormat)
          Composes a basic string that is a time stamp based on the supplied format.
private static boolean validateRequiredData()
          Validates the settings values required for the string util.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MILLISECSPERSECOND

private static final int MILLISECSPERSECOND
See Also:
Constant Field Values

MILLISECSPERMINUTE

private static final int MILLISECSPERMINUTE
See Also:
Constant Field Values

MILLISECSPERHOUR

private static final int MILLISECSPERHOUR
See Also:
Constant Field Values

MILLISECSPERDAY

private static final int MILLISECSPERDAY
See Also:
Constant Field Values

processData

private static Settings processData

cachedTimeStamp

private static java.lang.String cachedTimeStamp
Constructor Detail

StringUtil

StringUtil()
(Empty) constructor for static StringUtil class.

Method Detail

setProcessData

public static void setProcessData(Settings _processData)
                           throws java.lang.Exception
Provides access to the (main) settings.

Parameters:
_processData - The settings.
Throws:
java.lang.Exception

validateRequiredData

private static boolean validateRequiredData()
                                     throws java.lang.Exception
Validates the settings values required for the string util.

Returns:
Returns a boolean flag that indicates whether any crucial setting could not be validated.
Throws:
java.lang.Exception

fillSpaces

public static java.lang.String fillSpaces(java.lang.String _startString,
                                          int _fillLength)
Utility method: Fills in blank spaces for creating formatted output.

Parameters:
_startString - The string that is to be filled up with spaces, up to the specified length.
_fillLength - The length to which the string is to be filled.
Returns:
Returns the string with the appended spaces.

fillSpacesLeft

public static java.lang.String fillSpacesLeft(java.lang.String _startString,
                                              int _fillLength)
Utility method: Fills in blank spaces for creating formatted output, to the left of the supplied string.

Parameters:
_startString - The string that is to be filled up with spaces, up to the specified length.
_fillLength - The length to which the string is to be filled.
Returns:
Returns the string with the prepended spaces.

removeTrailingComment

public static java.lang.String removeTrailingComment(java.lang.String _stringToProcess)
Utility method: Removes comments at the end of a line of text.

Parameters:
_stringToProcess - The string that may contain a comment at the end (comments are indicated by a # symbol)
Returns:
Returns the string without the comment.

formatRightLeftJustified

public static java.lang.StringBuffer formatRightLeftJustified(java.lang.String _prefix,
                                                              java.lang.String _displayItem,
                                                              java.lang.String _displayItemValue,
                                                              java.lang.String _separator,
                                                              int _lineLength)
Utility method: Creates a line of text that is both left and right justified.

Parameters:
_prefix - An optional prefix to the display Item.
_displayItem - The display Item to be left-hand justified.
_displayItemValue - The display Item value that is to be left-hand justified.
_separator - A optional separator string for splitting the text.
_lineLength - The length of the text line to be returned.
Returns:
Returns the text line.

listSettings

public static java.lang.StringBuffer listSettings(java.util.Properties _settingsToList)
Utility method (debug/test): Compiles a list of the supplied properties.

Parameters:
_settingsToList - Properties to be listed.
Returns:
Returns the listing of the properties.

getClassName

public static java.lang.String getClassName(java.lang.Object _someObj)
Utility method: Returns the name of the class where this method is called from.

Parameters:
_someObj - Object for which we want its class name.
Returns:
Returns the class name.

arrayAsString

public static java.lang.String arrayAsString(int[] _intArray)
Utility method (debug/test): Trivial helper function for quick trace output.

Parameters:
_intArray - An array of integers.
Returns:
Returns a string compiled from the array elements.

getBanjoSignature

public static java.lang.StringBuffer getBanjoSignature()
Compiles the setting values that we group as the "Banjo signature".

Returns:
StringBuffer The collect "job signature".

getJobSignature

public static java.lang.StringBuffer getJobSignature(Settings _processData)
Compiles the setting values that we group as the "job signature".

Parameters:
_processData - The (main) settings, giving access to the settings and their values that make up the "job signature' (project, user, dataset, notes).
Returns:
StringBuffer The collect "job signature".

getReportFileNameMT

public static java.lang.String getReportFileNameMT(java.lang.String _reportFileName,
                                                   java.lang.String _prefix,
                                                   int _threadIndex)
Generates the report file name for a given thread in the multi-threaded scenario.

Parameters:
_reportFileName - The base part of the report file name (i.e., the one used by the main thread
_prefix - The prefix to add to file name. In case this string contains a token for the thread index (ID), we replace the token with the supplied ID.
_threadIndex - The index of the thread that makes the request
Returns:
String The name of the report file for the specified thread.

formatElapsedTime

public static java.lang.StringBuffer formatElapsedTime(double _elapsedTime,
                                                       int _decimalsToDisplay,
                                                       int _formatFlag)
Applies formatting to the elapsed time, based on supplied parameters.

Parameters:
_elapsedTime - The time to format (expected to be in milliseconds).
_decimalsToDisplay - The number of decimals to format the time with.
_formatFlag - The format to apply to the supplied time (plain number with qualifier, or in special d:h:m:s format).
Returns:
StringBuffer The time in the specified format.

formatDecimalDisplay

public static java.lang.String formatDecimalDisplay(double _numberToFormat,
                                                    java.lang.String _formatToApply)
Utility function for applying formatting to numbers.

Parameters:
_numberToFormat - The number to format with the _formatToApply.
_formatToApply - The format to apply to the supplied number
Returns:
The formatted number as a string.

listNodes

public static java.lang.String listNodes(int[][] _nodeList)
Utility function for listing a node list (parent list), in the form array[variableIndex][lagIndex]. Useful for testing/debugging.

Parameters:
_nodeList - The list of nodes to be listed.
Returns:
The string describing the list of nodes.

composeErrorMessage

public static java.lang.String composeErrorMessage(SettingItem _settingItem,
                                                   java.lang.String _strCondition)
Composes an error message that resulted from a comparison between 2 setting items.

Parameters:
_settingItem - The setting item.
_strCondition - The condition string that the setting item needs to satisfy.
Returns:
The string consisting of the error message.

composeErrorMessage

public static java.lang.String composeErrorMessage(SettingItem _settingItem1,
                                                   SettingItem _settingItem2,
                                                   java.lang.String _strCondition)
Composes an error message that resulted from a comparison between 2 setting items.

Parameters:
_settingItem1 - The first setting item.
_settingItem2 - The second setting item.
_strCondition - The condition string that the second setting item needs to satisfy in relation to the first setting item.
Returns:
The string consisting of the error message.

timeStamp

public static java.lang.String timeStamp(Settings _processData,
                                         java.lang.String _settingName,
                                         java.lang.String _timeStampFormat,
                                         java.lang.String _defaultTimeStampFormat)
Composes a basic string that is a time stamp based on the supplied format. If the suplied format is not usable, the code uses a default format, so it always returns a valid time stamp. Note that the first computed time stamp is cached for later re-use, i.e., the time stamp computation is only done once.

Parameters:
_processData - The underlying (main) settings object, for placing any errorItems.
_settingName - The name of the setting.
_timeStampFormat - The time stamp format to be applied in creating a time stamp.
_defaultTimeStampFormat - The default time stamp format to be used if the supplie _timeStampFormat is not a valid one.
Returns:
The string consisting of the created time stamp.

compileMemoryInfo

public static java.lang.String compileMemoryInfo(java.lang.String _info)
Composes a basic string that details the memory use of the application at the current moment.

Returns:
The string containing the memory use information.