This class is another collection of static utility methods.
These methods extract various elements from a path name:
public static String getFileName
(String path);
public static String getFileNameNoExtension
(String path);
public static String getFileExtension
(String name);
public static String getParentOfPath
(String path);
Returns the directory containing the specified local file.
public static String constructPath
(String parent, String path);
If path is absolute, it is returned. Otherwise, an absolute path is constructed from it and the parent. If parent is null, the current working directory is assumed.
These methods are hard to categorize, but are useful nonetheless:
public static String createWhiteSpace
(int len, int tabSize);
If tabSize is set to zero, the string will consist entirely of space characters. To get a whitespace string tuned to the current buffer's settings, call this method as follows:
myWhitespace = MiscUtilities.createWhiteSpace(myLength, buffer.getTabSize()); |
public static void compareStrings
(String str1, String str2);
Compares two strings. Returns a negative number of str1 is "before" str2, zero if they are equal, and a positive number of str1 is "after" str2. Unlike String.compareTo(), this method correctly recognizes and handles embedded numbers.
The compareStrings() method is very useful for sorting strings. The MiscUtilities class defines several java.util.Comparator implementations that use this method, useful for using with the sorting features of the Java collections API:
StringCompare
StringICaseCompare
MenuItemCompare
For example, you might call:
Arrays.sort(myListOfStrings, new MiscUtilities.StringICaseCompare()); |