bodhidharma.utilities
Class StringMethods

java.lang.Object
  extended by bodhidharma.utilities.StringMethods

public class StringMethods
extends java.lang.Object

A holder class for static methods relating to manipulating strings.

See Also:
String
Author:
Cory McKay

Constructor Summary
StringMethods()
           
 
Method Summary
static java.lang.String convertFilePathToFileName(java.lang.String file_path)
          Returns the name of the file referred to by the given path.
static java.lang.String getBeginningOfString(java.lang.String string_to_shorten, int number_characters)
          Returns a copy of the given string with all but the first number_characters eliminated.
static java.lang.String getBeginningOfStringWithHyphenFiller(java.lang.String string_to_shorten, int number_characters)
          Returns a copy of the given string with all but the first number_characters eliminated.
static java.lang.String getDirectoryName(java.lang.String file_path)
          Returns the name of the directory that the given filename is found in.
static java.lang.String getExtension(java.lang.String filename)
          Returns the three letter extension of the given file name.
static int getIndexOfString(java.lang.String given_name, java.lang.String[] possible_names)
          Returns the index in the possible_names array where the given_name parameter occurs.
static java.lang.String getRoundedDouble(double number_to_round, int decimal_places)
          Returns a formatted version of number_to_round.
static java.lang.String giveStringXMLEscapeCharacters(java.lang.String data)
           
static java.lang.String removeExtension(java.lang.String filename)
          Returns a copy of the given string with the last four characters removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringMethods

public StringMethods()
Method Detail

convertFilePathToFileName

public static java.lang.String convertFilePathToFileName(java.lang.String file_path)
Returns the name of the file referred to by the given path.

Parameters:
file_path - The file path from which the file name is to be extracted.
Returns:
The name of the file referred to in the parameter.

getDirectoryName

public static java.lang.String getDirectoryName(java.lang.String file_path)
                                         throws java.lang.Exception
Returns the name of the directory that the given filename is found in. Throws an exception if no valid directory separator is present.

Throws:
java.lang.Exception

removeExtension

public static java.lang.String removeExtension(java.lang.String filename)
Returns a copy of the given string with the last four characters removed. Returns null if the fourth to last character is not a period or there are less than five characters in the string.

Parameters:
filename - The name of the file from which the extension is to be removed.
Returns:
The name of the file with the extension removed.

getExtension

public static java.lang.String getExtension(java.lang.String filename)
Returns the three letter extension of the given file name. Returns null if the fourth to last character is not a period or there are less than five characters in the string.

Parameters:
filename - The name of the file from which the extension is to be returned.
Returns:
The extension of the file.

getBeginningOfString

public static java.lang.String getBeginningOfString(java.lang.String string_to_shorten,
                                                    int number_characters)
Returns a copy of the given string with all but the first number_characters eliminated. If the given string is shorter than number_characters, then blank spaces are added to the end of the string in order to make it the full length.

Parameters:
string_to_shorten - The string to be shortened or have spaces added to its end.
number_characters - Number of characters in the new string.
Returns:
The shortened string.

getBeginningOfStringWithHyphenFiller

public static java.lang.String getBeginningOfStringWithHyphenFiller(java.lang.String string_to_shorten,
                                                                    int number_characters)
Returns a copy of the given string with all but the first number_characters eliminated. If the given string is shorter than number_characters, then hyphens are are added to the end of the string in order to make it the full length (with two blank spaces on each side.

Parameters:
string_to_shorten - The string to be shortened or have spaces added to its end.
number_characters - Number of characters in the new string.
Returns:
The shortened string.

getRoundedDouble

public static java.lang.String getRoundedDouble(double number_to_round,
                                                int decimal_places)
Returns a formatted version of number_to_round. It will always show a 0 before numbers less than one, and will only show up to decimal_places decimal places.

Values of not a number, negative infinity and positive infinity will be returned as NaN, -Infinity and Infinity respectively.

Parameters:
number_to_round - The number that is to be rounded.
decimal_places - The maximum number of decimal places that will be displayed.

getIndexOfString

public static int getIndexOfString(java.lang.String given_name,
                                   java.lang.String[] possible_names)
                            throws java.lang.Exception
Returns the index in the possible_names array where the given_name parameter occurs. Throws an exception if it is not there.

Parameters:
given_name - The string to search for in possible_names.
possible_names - The array to search for given_names in.
Returns:
The index in possible_names that contains given_name.
Throws:
java.lang.Exception

giveStringXMLEscapeCharacters

public static java.lang.String giveStringXMLEscapeCharacters(java.lang.String data)