|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmckay.utilities.staticlibraries.StringMethods
public class StringMethods
A holder class for static methods relating to strings.
Constructor Summary | |
---|---|
StringMethods()
|
Method Summary | |
---|---|
static boolean |
areAllEntriesIdentical(java.lang.String[] test_array)
Checks the given array of strings to see if all of the contents are identical. |
static java.lang.String[] |
breakIntoTokens(java.lang.String input,
java.lang.String delimiter)
Breaks the given input string into tokens based on the given delimiter, and returns an array where each entry is a token. |
static int |
calculateLevenshteinDistance(java.lang.String first_string,
java.lang.String second_string)
Calculates the Levenshtein Distance (edit distance) between the two given strings. |
static int[][] |
calculateLevenshteinDistances(java.lang.String[] strings)
Calculates the Levenshtein Distance (edit distance) between each pair of strings in the given array. |
static java.lang.String |
concatenateArrayOfStrings(java.lang.String[] words)
Combines all the Strings of the given array into one String. |
static java.lang.String |
convertFilePathToFileName(java.lang.String file_path)
Returns the name of the file referred to by the given path. |
static boolean |
doStringArraysMatch(java.lang.String[] array1,
java.lang.String[] array2)
Returns true if the two given arrays contain exactly the same strings, but in any order in the array. |
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 |
getIndexOfLongestString(java.lang.String[] to_check)
Return the index of the longest string in the given array. |
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 int |
getIntInLimits(java.lang.String test_string,
int min,
int max)
Tests if the given string is an integer within the given bounds, and returns it as an integer if it is. |
static int |
getLengthOfLongerString(java.lang.String first,
java.lang.String second)
Returns the length of the longer of the two given strings. |
static int |
getLengthOfShorterString(java.lang.String first,
java.lang.String second)
Returns the length of the shorter of the two given strings. |
static java.lang.String |
getNumberFormattedWithCommas(int number)
Formats the given number with a comma every three digits. |
static java.lang.String |
getNumberFormattedWithCommas(long number)
Formats the given number with a comma every three digits. |
static int |
getNumberOccurencesOfSubString(java.lang.String given_string,
java.lang.String substring)
Returns the number of times that the given substring occurs in the given_string. |
static java.lang.String |
getRoundedDouble(double number_to_round,
int decimal_places)
Returns a formatted version of number_to_round. |
static java.lang.String |
getRoundedDoubleWithCommas(double number_to_round,
int decimal_places)
Returns a formatted version of number_to_round. |
static boolean |
isStringInArray(java.lang.String test_string,
java.lang.String[] array_to_check)
Checks to see if a given string is the same as an entry in the given array. |
static java.lang.String |
nullifyStringIfEmpty(java.lang.String given_string)
Returns null if the given string is empty and returns the original string if it is not empty. |
static void |
printDoubleArray(java.lang.String[][] test_strings,
int number_tabs,
java.lang.String open_marker,
java.lang.String close_marker)
Prints each outer entry of the given string array to standard out on a different line and each inner entry on the same line. |
static void |
printStringArrayContents(java.lang.String[] test_strings)
Prints each entry of the given string array to standard out on a different line. |
static void |
printStringArrayContentsOnOneLine(java.lang.String[] test_strings,
int number_tabs,
java.lang.String open_marker,
java.lang.String close_marker)
Prints each entry of the given string array to standard out on the same line. |
static java.lang.String[] |
removeDoubles(java.lang.String[] strings)
Returns a shortened copy of the given array of strings with all duplicate entries removed. |
static java.lang.String[] |
removeEmptyStringsFromArray(java.lang.String[] array)
Given an array of Strings, this method removes empty cells from the array. |
static java.lang.String |
removeExtension(java.lang.String filename)
Returns a copy of the given string with the extension removed. |
static java.lang.String |
replaceExtension(java.lang.String filename,
java.lang.String new_extension)
Returns a copy of the given file name with its original extension stripped away and replaced by the new specified extension. |
static void |
reportStringDifferences(java.lang.String key,
java.lang.String first,
java.lang.String second,
java.util.Vector<java.lang.String[]> to_update)
Compares two strings to see if they are the same, taking into account the possibility that they may be null. |
static boolean |
testIfStringIsAnInt(java.lang.String test_string)
Tests if the given string is an integer (e.g. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringMethods()
Method Detail |
---|
public static void printDoubleArray(java.lang.String[][] test_strings, int number_tabs, java.lang.String open_marker, java.lang.String close_marker)
test_strings
- The array to print.number_tabs
- The number of tabs to start the line with.open_marker
- The marker denoting the start of an element.close_marker
- The marker denoting the end of an element.public static void printStringArrayContentsOnOneLine(java.lang.String[] test_strings, int number_tabs, java.lang.String open_marker, java.lang.String close_marker)
test_strings
- The array to print.number_tabs
- The number of tabs to start the line with.open_marker
- The marker denoting the start of an element.close_marker
- The marker denoting the end of an element.public static void printStringArrayContents(java.lang.String[] test_strings)
test_strings
- The array of strings to pring.public static java.lang.String[] breakIntoTokens(java.lang.String input, java.lang.String delimiter)
input
- The string to break into tokens.delimiter
- The string that must occur wherever tokens are to
be separated.
public static boolean isStringInArray(java.lang.String test_string, java.lang.String[] array_to_check)
test_string
- The string to search the array_to_check array
for.array_to_check
- The array to search to see if test_string is an
entry.
public static boolean areAllEntriesIdentical(java.lang.String[] test_array)
test_array
- The array of strings to test.
public static int getIndexOfString(java.lang.String given_name, java.lang.String[] possible_names) throws java.lang.Exception
given_name
- The string to search for in possible_names.possible_names
- The array to search for given_names in.
java.lang.Exception
- Throws an exception if if given_name is not
in the possible_names array.public static int getIndexOfLongestString(java.lang.String[] to_check)
to_check
- The strings to check.
public static int getLengthOfLongerString(java.lang.String first, java.lang.String second)
first
- One string to compare.second
- The other string to compare.
public static int getLengthOfShorterString(java.lang.String first, java.lang.String second)
first
- One string to compare.second
- The other string to compare.
public static boolean doStringArraysMatch(java.lang.String[] array1, java.lang.String[] array2)
array1
- The array to compare with array2.array2
- The array to compare with array1.
public static java.lang.String[] removeDoubles(java.lang.String[] strings)
strings
- The array of strings to remove duplicate entries from.
public static int getNumberOccurencesOfSubString(java.lang.String given_string, java.lang.String substring)
given_string
- The string to search.substring
- The string to search given_string for.
public static java.lang.String concatenateArrayOfStrings(java.lang.String[] words)
words
- The Strings to be concatenated.
public static java.lang.String[] removeEmptyStringsFromArray(java.lang.String[] array)
array
- Array from which to remove empty cells.
public static int calculateLevenshteinDistance(java.lang.String first_string, java.lang.String second_string)
first_string
- A string to compare to second_string.second_string
- A string to compare to first_string.
public static int[][] calculateLevenshteinDistances(java.lang.String[] strings)
strings
- The strings to compare.
public static void reportStringDifferences(java.lang.String key, java.lang.String first, java.lang.String second, java.util.Vector<java.lang.String[]> to_update)
key
- A description of the strings being compared.first
- The first string to comare.second
- The second string to compare.to_update
- The Vector to add the difference report to. Nothing
is added if first and second are the same. If they
are different, then a String array of size 3 is
added to to_update. The first entry is key, the second
is first and the third is second.public static java.lang.String getBeginningOfString(java.lang.String string_to_shorten, int number_characters)
string_to_shorten
- The string to be shortened or have spaces
added to its end.number_characters
- Number of characters in the new string.
public static java.lang.String getBeginningOfStringWithHyphenFiller(java.lang.String string_to_shorten, int number_characters)
string_to_shorten
- The string to be shortened or have spaces
added to its end.number_characters
- Number of characters in the new string.
public static java.lang.String nullifyStringIfEmpty(java.lang.String given_string)
given_string
- The string to examine.
public static java.lang.String convertFilePathToFileName(java.lang.String file_path)
file_path
- The file path from which the file name is to be
extracted.
public static java.lang.String getDirectoryName(java.lang.String file_path) throws java.lang.Exception
file_path
- The path to extract the directory from.
java.lang.Exception
- Throws an exception if no valid directory
separator is present.public static java.lang.String removeExtension(java.lang.String filename)
IMPORTANT: filename should consist of at least four characters.
filename
- The name of the file from which the extension is to be
removed.
public static java.lang.String getExtension(java.lang.String filename)
IMPORTANT: filename should consist of at least four characters.
filename
- The name of the file from which the extension is to be
returned.
public static java.lang.String replaceExtension(java.lang.String filename, java.lang.String new_extension)
filename
- The name of the file that is to have its extension
replaced.new_extension
- The replacement extension, NOT including the
period.
public static java.lang.String getRoundedDouble(double number_to_round, int decimal_places)
Values of not a number, negative infinity and positive infinity will be returned as NaN, -Infinity and Infinity respectively.
number_to_round
- The number that is to be rounded.decimal_places
- The maximum number of decimal places that will
be displayed.
public static java.lang.String getRoundedDoubleWithCommas(double number_to_round, int decimal_places)
Values of not a number, negative infinity and positive infinity will be returned as NaN, -Infinity and Infinity respectively.
number_to_round
- The number that is to be rounded.decimal_places
- The maximum number of decimal places that will
be displayed.
public static java.lang.String getDoubleInScientificNotation(double number_to_round, int significant_digits)
Values of not a number, negative infinity and positive infinity will be returned as NaN, -Infinity and Infinity respectively.
number_to_round
- The number that is to be formatted.significant_digits
- The number of significant digits to use.
public static java.lang.String getNumberFormattedWithCommas(int number)
number
- The number to format.
public static java.lang.String getNumberFormattedWithCommas(long number)
number
- The number to format.
public static boolean testIfStringIsAnInt(java.lang.String test_string)
test_string
- The string to test.
public static int getIntInLimits(java.lang.String test_string, int min, int max) throws java.lang.Exception
test_string
- The string to convert to an integer.min
- The minimum acceptable integer value.max
- The maximum acceptable integer value.
java.lang.Exception
- An informative exception is thrown if test_string
is not an integer or does not fall between min
and max.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |