jAudioFeatureExtractor.GeneralTools
Class StringMethods

java.lang.Object
  extended by jAudioFeatureExtractor.GeneralTools.StringMethods

public class StringMethods
extends java.lang.Object

A holder class for static methods relating to manipulating strings.

Author:
Cory McKay
See Also:
String

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 getDoubleInScientificNotation(double number_to_round, int significant_digits)
          Returns a formatted version of number_to_round that has been converted to scientific notation and includes the given number of significant_digits.
static java.lang.String getExtension(java.lang.String filename)
          Returns the 2, 3 or 4 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[] removeDoubles(java.lang.String[] strings)
          Returns a shorened copy of the given array of strings with all duplicate entries removed.
static java.lang.String removeExtension(java.lang.String filename)
          Returns a copy of the given string with the extension 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 extension removed. Returns null if there is no extension or if there are less than five characters in the string.

IMPORTANT: filename should consist of at least four characters.

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 2, 3 or 4 letter extension of the given file name. Returns null if there is no extension or if there are less than 4 characters in the string.

IMPORTANT: filename should consist of at least four characters.

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.

getDoubleInScientificNotation

public static java.lang.String getDoubleInScientificNotation(double number_to_round,
                                                             int significant_digits)
Returns a formatted version of number_to_round that has been converted to scientific notation and includes the given number of significant_digits.

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 formatted.
significant_digits - The number of significant digits to use.

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

removeDoubles

public static java.lang.String[] removeDoubles(java.lang.String[] strings)
Returns a shorened copy of the given array of strings with all duplicate entries removed. The original array of strings is not changed.

Parameters:
strings - The array of strings to remove duplicate entries from.
Returns:
A shortened copy of the given strings with duplicates removed.