org.ceryle.util
Class Utilities

java.lang.Object
  extended by org.ceryle.util.Utilities
All Implemented Interfaces:
Constants

public class Utilities
extends Object
implements Constants

Provides some general utilities for processing files, URLs, math, characters, strings, etc. All methods are static.

Since:
JDK1.3
Version:
$Id: Utilities.java,v 3.28 2007-06-20 01:28:32 altheim Exp $
Author:
Murray Altheim

Field Summary
static String EMPTY_STRING
           
static String RESOURCE_BUNDLE_CLASSNAME
          The default ResourceBundle's class name.
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Constructor Summary
Utilities()
           
 
Method Summary
static boolean arrayContains(Object[] array, Object o)
          Returns true if the array contains the Object o.
static boolean characterMatches(boolean ignoreCase, char c1, char c2)
          Returns true if the character c1 matches character c2, ignoring case (as much as is provided by Java) if the boolean ignoreCase is true.
static int charCount(String s, char c)
          Returns the number of times the provided character appears in the String.
static File chooseDirectory(File defaultDirectory)
          Displays a FileChooser dialog box and returns the selected directory (as a File), or null if no directory is chosen.
static File chooseFile(Component parent, String title, File defaultDirectory, File defaultFile, int selectionMode, int dialogType)
          Provided with a JComponent parent, displays a FileChooser dialog box and returns the selected File, or null if no file is chosen.
static File chooseFile(File defaultFile, int dialogType)
          Displays a FileChooser dialog box and returns the selected File, or null if no file is chosen.
static double computeAngle(int x1, int y1, int x2, int y2)
          Returns the angle between the points (x1,y1) and (x2,y2), in radians.
static double computeDistance(int x1, int y1, int x2, int y2)
          Returns the distance between the points (x1,y1) and (x2,y2) .
static double computePerpendicular(int x1, int y1, int x2, int y2)
          Returns an angle perpendicular to the angle between the points (x1,y1) and (x2,y2), in radians.
static boolean contains(String s1, String s2, boolean caseSensitive)
          Returns true if String s1 contains s2, using case sensitive matching when the boolean caseSensitive is true.
static String convertTildeEncoding(String s)
          Converts all vowels followed by a tilde ('~') character to its equivalent macron'd version (in UTF-8) encoding.
static int[] convertToIntArray(long[] longArray)
          This converts a long[] array to an int[] array, checking each long value to see if it exceeds Integer.MAX_VALUE before proceeding, throwing an ArithmeticException on overflow.
static List convertToList(String s, String delim)
          Converts the whitespace-delimited String s to a List of Strings.
static String[] convertToStringArray(String s, String delim)
          Converts the whitespace-delimited String s to an array of Strings.
static void delayedAction(int ms, ActionListener listener)
          After a delay of ms, fire a single ActionEvent on the supplied listener.
static void deleteAllFiles(String directory, String extension)
          Delete all files having a specific extension (e.g., all "*.html" files) from the directory dir.
static boolean deleteDir(MessageHandler mh, File dir)
          Recursively deletes all files and subdirectories under the directory dir.
static String deWikify(String text)
          Converts a WikiWord into a normal phrase by inserting spaces.
static void fileCopy(File input, File output)
          Copies File input to File output.
static File fileExtensionCheck(File file, String ext)
          Checks and potentially modifies the incoming File's extension.
static Class findClass(List packages, String className)
          Searches the provided List of package names for className.
static Class findClass(String packagename, String className)
          Calls findClass(List,String) with a single package name.
static String getAlphaByNumber(int n)
          Converts any number between 0 and 25 to its alphabetic character as a String.
static String getBoundsAsString(Window window)
          Returns the bounds of the provided Window as a String.
static String getFileExtension(File file)
          Returns the extension of File file.
static String getFileExtension(String systemId)
          Returns the file extension String provided a full system identifier.
static File getFileFromURL(URL url)
          Provided with a URL url, returns a File reference.
static String getFilenameFromURL(URL url)
          Provided with a URL url, returns the filename component.
static long getFileSize(File file, int maxfiles)
          Returns the size of indicated File (or directory) file.
static String getFormattedDecimal(double d, int decimalPlaces)
          Returns a String representing the double d appropriately formatted as a decimal in the default Locale.
static String getFormattedDecimal(float f, int decimalPlaces)
          Returns a String representing the float f appropriately formatted as a decimal in the default Locale.
static int getOS()
          Returns an int representing the installed operating system.
static String getStackTraceAsString(Throwable t)
          Returns the stack trace from Throwable t as a single String.
static URL getURLFromFile(File file)
          Provided with a File file, returns a file-based URL.
static URL getURLFromFilepath(String filepath)
          Provided with a String filepath, returns a file-based URL.
static String gsub(String src, String srch, String repl, boolean ignoreCase)
          Replace all (non-overlapping) occurrences of a String srch in String src by replacement repl.
static boolean hasFragmentID(String systemId)
          Returns true if the provided system ID has a fragment ID.
static String indent(int nest)
          Returns a String indent composed of space characters given the indent nest.
static int indexOf(boolean ignoreCase, String source, String substring, int fromIndex)
          Returns the index within String source of the first occurrence of the specified substring, starting at the specified index.
static int indexOfIgnoreCase(String str, String substring)
          Returns the index within String str of the first occurrence of the specified substring, ignoring case.
static int indexOfIgnoreCase(String str, String substring, int fromIndex)
          Returns the index within String str of the first occurrence of the specified substring, ignoring case, and starting at the specified index.
static int initialBucketSize(int n)
          Returns an initial bucket size provided a rough estimate of a HashMap's size n.
static Set intersection(Collection c1, Collection c2)
          Returns the intersection of the two Collections as a new Set.
static boolean isURL(String sysid)
          Returns true if the supplied sysid can be made into URL.
static boolean isWS(char c)
          Returns true if char c is a member of S (space) [XML 1.1 production 3].
static boolean listsAreEquivalent(List a, List b)
          Returns true if the two lists contain the same objects in the same order.
static String localize(String messageId)
          Return a String representing the localized message, provided the unique message identifier messageId.
static String localize(String messageId, String arg1)
          Return a String representing the localized message, provided the unique message identifier messageId and one parameter arg1.
static String localize(String messageId, String arg1, String arg2)
          Return a String representing the localized message, provided the unique message identifier messageId and two parameters arg1 and arg2.
static String localize(String messageId, String arg1, String arg2, String arg3)
          Return a String representing the localized message, provided the unique message identifier messageId and three parameters arg1, arg2, and arg3.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4)
          Return a String representing the localized message, provided the unique message identifier messageId and four parameters arg1, arg2, arg3, and arg4.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4, String arg5)
          Return a String representing the localized message, provided the unique message identifier messageId and five parameters arg1, arg2, arg3, arg4, and arg5.
static String localize(String messageId, String arg1, String arg2, String arg3, String arg4, String arg5, String arg6)
          Return a String representing the localized message, provided the unique message identifier messageId and six parameters arg1, arg2, arg3, arg4, arg5, and arg6.
static boolean matches(String s1, String s2, boolean caseSensitive)
          Returns true if String s1 exactly matches s2, using case sensitive matching when the boolean caseSensitive is true.
static String normalize(String s)
          Normalizes the whitespace of the given String.
static void normalize(StringBuffer sb)
          Normalizes the whitespace of the given StringBuffer.
static String oldGsub(String src, String srch, String repl, boolean ignoreCase)
          Replace all (non-overlapping) occurrences of a String srch in String src by replacement repl.
static Point parsePoint(String s)
          Provided a String s containing a comma delimited x,y coordinate (eg., "210,336"), returns a Point.
static Rectangle parseRectangle(String s)
          Parses the provided String, returning a Rectangle.
static String processMessage(String id, Object[] args)
          Get message text from the default, localized ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.
static String processMessage(String id, Object[] args, ResourceBundle bundle)
          Get message text from the supplied ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.
static String readFile(File file)
          A simple reader method to import the contents of a File file.
static String repeatString(String s, int n)
          Returns a String composed of n repetitions of the provided String s.
static String resolvePath(File rootDir, String pathname)
          Shortcut for resolvePath(String,String)
static String resolvePath(String rootDir, String pathname)
          Given a String pathname, return as canonical pathname based on the supplied root path and content of supplied pathname.
static String rsoundex(String s)
          Returns a refined soundex encoding of the String s.
static String[] separateFragmentID(String systemId)
          Returns the system ID and fragment ID of the provided system ID as separate Strings.
static String soundex(String s)
          Returns a soundex encoding of the String s.
static HashSet stringToSet(String s)
          Processes the String s to provide a HashSet of Strings, using whitespace as the delimiter.
static String sub(String src, String srch, String repl, boolean ignoreCase)
          Replace the first occurrence of a String srch in String src by replacement repl.
static void testAngles()
          TEMP test angle methods
static String toHexColor(Color color)
          Converts a Color to an HTML-style hex color String.
static Color toOpaqueColor(Color color)
          Returns an opaque Color adjusted to roughly compensate for any transparency (alpha value), as against a white background.
static Set union(Collection c1, Collection c2)
          Returns the union of the two Collections as a new Set.
static void writeFile(File file, String content)
          A writer method to export a String to a File file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_BUNDLE_CLASSNAME

public static final String RESOURCE_BUNDLE_CLASSNAME
The default ResourceBundle's class name. The value is "org.ceryle.util.Msg".

See Also:
Constant Field Values

EMPTY_STRING

public static final String EMPTY_STRING
Constructor Detail

Utilities

public Utilities()
Method Detail

getOS

public static int getOS()
Returns an int representing the installed operating system. The returned values are 1 for Windows, 2 for Macintosh, 3 for linux, and -1 for unrecognized.


getURLFromFile

public static URL getURLFromFile(File file)
                          throws MalformedURLException
Provided with a File file, returns a file-based URL. If this can't be determined or some error occurs during the creation of the URL, returns null. If the file can be determined to be a directory and is missing its ending slash, this will be added to the URL.

Throws:
MalformedURLException - if the URL cannot be created.

getURLFromFilepath

public static URL getURLFromFilepath(String filepath)
                              throws MalformedURLException
Provided with a String filepath, returns a file-based URL. If this can't be determined or some error occurs during the creation of the URL, throws a MalformedURLException.

Throws:
MalformedURLException - if the URL cannot be created.

getFilenameFromURL

public static String getFilenameFromURL(URL url)
Provided with a URL url, returns the filename component. If this can't be determined, returns an empty String. If the last character is a slash, an empty String is returned.


getFileFromURL

public static File getFileFromURL(URL url)
Provided with a URL url, returns a File reference. If this can't be determined or the URL does not use a file: protocol, returns null.


fileExtensionCheck

public static File fileExtensionCheck(File file,
                                      String ext)
Checks and potentially modifies the incoming File's extension. If it matches ext, the File is returned unchanged. If there is no file extension (i.e., no dots in the file name) an ext extension is added. If there is a different extension it is replaced with ext. The value of the parameter should include the initial dot (e.g., ".xtm").


getFileExtension

public static String getFileExtension(String systemId)
Returns the file extension String provided a full system identifier. This will strip off fragment identifiers from URLs as well. This will return null if unable to determine the extension.


getFileExtension

public static String getFileExtension(File file)
Returns the extension of File file.


getFileSize

public static long getFileSize(File file,
                               int maxfiles)
                        throws IOException
Returns the size of indicated File (or directory) file. This is recursive so any loops in the structure will cause a continuous loop. To keep this from happening infinitely, if the file count reaches the limit set by maxfiles it will throw an exception to exit. This is admittedly a more primitive solution than checking for previous access.

Throws:
IOException - if the File reference is null, does not exist, or can't be read.

hasFragmentID

public static boolean hasFragmentID(String systemId)
Returns true if the provided system ID has a fragment ID.


separateFragmentID

public static String[] separateFragmentID(String systemId)
Returns the system ID and fragment ID of the provided system ID as separate Strings. If there is no fragment ID, null is returned as the second array member.


chooseFile

public static File chooseFile(File defaultFile,
                              int dialogType)
Displays a FileChooser dialog box and returns the selected File, or null if no file is chosen. If defaultFile is non-null, it is set as the default File. This defaults to selecting only files.

Parameters:
defaultFile - optional default File.
dialogType - dialog type: JFileChooser.OPEN_DIALOG or JFileChooser.SAVE_DIALOG.

chooseDirectory

public static File chooseDirectory(File defaultDirectory)
Displays a FileChooser dialog box and returns the selected directory (as a File), or null if no directory is chosen. If defaultDirectory is non-null, it is set as the default directory. This defaults to selecting only directories.

Parameters:
defaultDirectory - optional default directory (as a File).

chooseFile

public static File chooseFile(Component parent,
                              String title,
                              File defaultDirectory,
                              File defaultFile,
                              int selectionMode,
                              int dialogType)
Provided with a JComponent parent, displays a FileChooser dialog box and returns the selected File, or null if no file is chosen. If defaultDirectory is non-null, it is set as the current directory. Otherwise, the current default directory is used. If the user accepts the dialog, the default directory is set to the selected directory. If defaultFile is non-null, it is set as the selected file. The dialog type can be JFileChooser.OPEN_DIALOG, JFileChooser.SAVE_DIALOG, or JFileChooser.CUSTOM_DIALOG.

If a custom dialog is specified, title will be used for the dialog title; if a null value, the word "Select" will be used.

Parameters:
parent - parent view or window (can be null)
title - optional dialog title (only used if the type is a CUSTOM_DIALOG).
defaultDirectory - optional default directory
defaultFile - optional default File
selectionMode - selection mode: JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, or JFileChooser.FILES_AND_DIRECTORIES.
dialogType - dialog type: JFileChooser.OPEN_DIALOG, JFileChooser.SAVE_DIALOG. or JFileChooser.CUSTOM_DIALOG. If the latter, a dialog title must be supplied.

readFile

public static String readFile(File file)
                       throws IOException
A simple reader method to import the contents of a File file. returned as a single String (this is perhaps not a good idea for large files). Reading occurs line-by-line. It is assumed that the default character encoding is acceptable.

Throws:
IOException

writeFile

public static void writeFile(File file,
                             String content)
                      throws IOException
A writer method to export a String to a File file. This is a convenience method made available mostly for symmetry with readFile(File); processing is actually via a FileExporter thread. No checking for overwrite or anything else is done. It is assumed that the default character encoding is acceptable.

Throws:
IOException

resolvePath

public static String resolvePath(File rootDir,
                                 String pathname)
                          throws IOException
Shortcut for resolvePath(String,String)

Throws:
IOException

resolvePath

public static final String resolvePath(String rootDir,
                                       String pathname)
Given a String pathname, return as canonical pathname based on the supplied root path and content of supplied pathname.


fileCopy

public static void fileCopy(File input,
                            File output)
                     throws IOException
Copies File input to File output.

Throws:
IOException

deleteDir

public static boolean deleteDir(MessageHandler mh,
                                File dir)
Recursively deletes all files and subdirectories under the directory dir.

Parameters:
dir - the directory to be deleted
mh - the optional MessageHandler to receive notification
Returns:
true if all deletions were successful. If a deletion fails, the method aborts, returning false.

deleteAllFiles

public static void deleteAllFiles(String directory,
                                  String extension)
                           throws IOException
Delete all files having a specific extension (e.g., all "*.html" files) from the directory dir. If the supplied pathname is not a directory, nothing happens.

Throws:
IOException

isURL

public static final boolean isURL(String sysid)
Returns true if the supplied sysid can be made into URL.


findClass

public static Class findClass(String packagename,
                              String className)
                       throws ClassNotFoundException
Calls findClass(List,String) with a single package name.

Throws:
ClassNotFoundException

findClass

public static Class findClass(List packages,
                              String className)
                       throws ClassNotFoundException
Searches the provided List of package names for className. If a direct match doesn't exist, this will iterate through the List, prepending each to className until a match is found, throwing a ClassNotFoundException if unsuccessful.

Parameters:
packages - a List of Strings containing one or more package names.
className - the name of the class to find.
Returns:
the Class.
Throws:
ClassNotFoundException - if unsuccessful in finding the Class.

intersection

public static Set intersection(Collection c1,
                               Collection c2)
Returns the intersection of the two Collections as a new Set. Returns an empty Set if there is no intersection.


union

public static Set union(Collection c1,
                        Collection c2)
Returns the union of the two Collections as a new Set. (Any Objects common to both are only represented once in the result.)


initialBucketSize

public static int initialBucketSize(int n)
Returns an initial bucket size provided a rough estimate of a HashMap's size n.


soundex

public static String soundex(String s)
Returns a soundex encoding of the String s. This will be a four character String. If the encoding fails, null is returned.


rsoundex

public static String rsoundex(String s)
Returns a refined soundex encoding of the String s. This will be a six character String. If the encoding fails, null is returned.


toHexColor

public static String toHexColor(Color color)
Converts a Color to an HTML-style hex color String.


toOpaqueColor

public static Color toOpaqueColor(Color color)
Returns an opaque Color adjusted to roughly compensate for any transparency (alpha value), as against a white background. If the provided color is opaque, it is returned unchanged.


arrayContains

public static boolean arrayContains(Object[] array,
                                    Object o)
Returns true if the array contains the Object o.


convertToStringArray

public static String[] convertToStringArray(String s,
                                            String delim)
Converts the whitespace-delimited String s to an array of Strings. If the delimiter set is not provided (ie., the parameter is null), this uses the default StringTokenizer set of delimiters, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Returns an empty array rather than null. This will process the special case of a token matchin "_EMPTY_STRING_" as an empty String.


convertToList

public static List convertToList(String s,
                                 String delim)
Converts the whitespace-delimited String s to a List of Strings. If the delimiter set is not provided (ie., the parameter is null), this uses the default StringTokenizer set of delimiters, which is " \t\n\r\f": the space character, the tab character, the newline character, the carriage-return character, and the form-feed character. Returns an empty array rather than null. This will process the special case of "_EMPTY_STRING_" as an empty String.


listsAreEquivalent

public static boolean listsAreEquivalent(List a,
                                         List b)
Returns true if the two lists contain the same objects in the same order. This performs a String comparison when the objects are Strings, otherwise this uses Object's equals() method. Nulls are permitted.


convertToIntArray

public static int[] convertToIntArray(long[] longArray)
                               throws ArithmeticException
This converts a long[] array to an int[] array, checking each long value to see if it exceeds Integer.MAX_VALUE before proceeding, throwing an ArithmeticException on overflow.

Throws:
ArithmeticException

testAngles

public static void testAngles()
TEMP test angle methods


computeDistance

public static double computeDistance(int x1,
                                     int y1,
                                     int x2,
                                     int y2)
Returns the distance between the points (x1,y1) and (x2,y2) .


computeAngle

public static double computeAngle(int x1,
                                  int y1,
                                  int x2,
                                  int y2)
Returns the angle between the points (x1,y1) and (x2,y2), in radians.


computePerpendicular

public static double computePerpendicular(int x1,
                                          int y1,
                                          int x2,
                                          int y2)
Returns an angle perpendicular to the angle between the points (x1,y1) and (x2,y2), in radians.


delayedAction

public static void delayedAction(int ms,
                                 ActionListener listener)
After a delay of ms, fire a single ActionEvent on the supplied listener. This line must be included in the actionPerformed(ActionEvent) method:
    ((Timer)event.getSource()).stop();
  
This is very much a convenience method.


deWikify

public static String deWikify(String text)
Converts a WikiWord into a normal phrase by inserting spaces. This is the same basic algorithm as JSPWiki's TextUtils.beautifyString(s), but uses a StringCharacterIterator.

Parameters:
text - the String to be deWikified.
Returns:
the deWikified String.

normalize

public static String normalize(String s)
Normalizes the whitespace of the given String. All whitespace runs are converted to a single space.


normalize

public static void normalize(StringBuffer sb)
Normalizes the whitespace of the given StringBuffer. All whitespace runs are converted to a single space. This operates upon the supplied StringBuffer, it does not return any value. Note that this does not trim pre- or post- whitespace, just normalizes it.


isWS

public static boolean isWS(char c)
Returns true if char c is a member of S (space) [XML 1.1 production 3].


getBoundsAsString

public static String getBoundsAsString(Window window)
Returns the bounds of the provided Window as a String.


parseRectangle

public static Rectangle parseRectangle(String s)
                                throws NumberFormatException
Parses the provided String, returning a Rectangle. If any error occurs during parsing, throws a java.lang.NumberFormatException. If there are more than four comma-separated tokens in the provided String, they are ignored. The format should be x,y,width,height.

Throws:
NumberFormatException

parsePoint

public static Point parsePoint(String s)
                        throws NumberFormatException
Provided a String s containing a comma delimited x,y coordinate (eg., "210,336"), returns a Point. If this fails for any reason, throws a NumberFormatException.

Throws:
NumberFormatException

getFormattedDecimal

public static String getFormattedDecimal(double d,
                                         int decimalPlaces)
Returns a String representing the double d appropriately formatted as a decimal in the default Locale. This uses a minimum of 1 integer digit, a minimum of 1 and maximum of decimalPlaces fraction digits (decimal places), e.g., "3.714" where decimalPlaces equals 3.


getFormattedDecimal

public static String getFormattedDecimal(float f,
                                         int decimalPlaces)
Returns a String representing the float f appropriately formatted as a decimal in the default Locale. This uses a minimum of 1 integer digit, a minimum of 1 and maximum of decimalPlaces fraction digits (decimal places), e.g., "3.714" where decimalPlaces equals 3.

This is identical to getFormattedDecimal(double,int) except for handling floats rather than doubles.


repeatString

public static String repeatString(String s,
                                  int n)
Returns a String composed of n repetitions of the provided String s. When n is zero, returns an empty String.


stringToSet

public static HashSet stringToSet(String s)
Processes the String s to provide a HashSet of Strings, using whitespace as the delimiter.


indent

public static String indent(int nest)
Returns a String indent composed of space characters given the indent nest. Each nesting level is represented by two spaces. Yes, this could be done with a function, but this approach does not result in so many String creations, and indents are so common in pretty-printed XML files. After n == 10, returns n == 10.


indexOfIgnoreCase

public static final int indexOfIgnoreCase(String str,
                                          String substring)
Returns the index within String str of the first occurrence of the specified substring, ignoring case. This is accomplished by uppercasing the entire source String, not very efficient for large Strings.

(This will likely be rewritten at some point with an actual character-by-character implementation; due to internationalization considerations this is quite a bit more difficult than a simple character match so we're currently just relying on Java's i18n features.)

Parameters:
str - the source String.
substring - the substring to search for.
Returns:
if the String argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.

indexOfIgnoreCase

public static final int indexOfIgnoreCase(String str,
                                          String substring,
                                          int fromIndex)
Returns the index within String str of the first occurrence of the specified substring, ignoring case, and starting at the specified index. This is accomplished by uppercasing the entire source String, not very efficient for large Strings.

Parameters:
str - any String.
substring - the substring to search for.
fromIndex - the index to start the search from.
Returns:
If the String argument occurs as a substring within this object at a starting index no smaller than fromIndex, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at fromIndex or beyond, -1 is returned.

indexOf

public static int indexOf(boolean ignoreCase,
                          String source,
                          String substring,
                          int fromIndex)
Returns the index within String source of the first occurrence of the specified substring, starting at the specified index. If the boolean ignoreCase is false, this performs the same as the java.lang.String method of similar ilk. This method is suitable for large source strings.

Also, as with java.lang.String's indexOf() method, there is no restriction on the value of fromIndex: if it exceeds either start or end boundary, it is set to that boundary.

Parameters:
source - the String to search within.
substring - the substring to search for.
fromIndex - the index to start the search from.
Returns:
the index of the first matching character of the substring within the source String, or -1 if no match.
Throws:
NullPointerException - if source is null

characterMatches

public static boolean characterMatches(boolean ignoreCase,
                                       char c1,
                                       char c2)
Returns true if the character c1 matches character c2, ignoring case (as much as is provided by Java) if the boolean ignoreCase is true.


contains

public static boolean contains(String s1,
                               String s2,
                               boolean caseSensitive)
Returns true if String s1 contains s2, using case sensitive matching when the boolean caseSensitive is true. Case sensitive matching is done by converting both strings to both uppercase and lowercase and comparing each pair.


matches

public static boolean matches(String s1,
                              String s2,
                              boolean caseSensitive)
Returns true if String s1 exactly matches s2, using case sensitive matching when the boolean caseSensitive is true. Case insensitive matching is done by converting both strings to both uppercase and lowercase and comparing each pair. Prior to this a length test is done, returning false if the lengths mismatch (saving the trouble of a String comparison).


getAlphaByNumber

public static String getAlphaByNumber(int n)
Converts any number between 0 and 25 to its alphabetic character as a String. If the value is out of range, the number is returned as a String.


localize

public static String localize(String messageId)
Return a String representing the localized message, provided the unique message identifier messageId.

Parameters:
messageId - the unique message identifier.
Returns:
the localized String.
See Also:
MessageHandler.localize(String)

localize

public static String localize(String messageId,
                              String arg1)
Return a String representing the localized message, provided the unique message identifier messageId and one parameter arg1.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2)
Return a String representing the localized message, provided the unique message identifier messageId and two parameters arg1 and arg2.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
arg2 - A parameter String to be inserted at %2.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3)
Return a String representing the localized message, provided the unique message identifier messageId and three parameters arg1, arg2, and arg3.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
arg2 - A parameter String to be inserted at %2.
arg3 - A parameter String to be inserted at %3.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4)
Return a String representing the localized message, provided the unique message identifier messageId and four parameters arg1, arg2, arg3, and arg4.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
arg2 - A parameter String to be inserted at %2.
arg3 - A parameter String to be inserted at %3.
arg4 - A parameter String to be inserted at %4.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4,
                              String arg5)
Return a String representing the localized message, provided the unique message identifier messageId and five parameters arg1, arg2, arg3, arg4, and arg5.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
arg2 - A parameter String to be inserted at %2.
arg3 - A parameter String to be inserted at %3.
arg4 - A parameter String to be inserted at %4.
arg5 - A parameter String to be inserted at %5.
Returns:
The localized String.

localize

public static String localize(String messageId,
                              String arg1,
                              String arg2,
                              String arg3,
                              String arg4,
                              String arg5,
                              String arg6)
Return a String representing the localized message, provided the unique message identifier messageId and six parameters arg1, arg2, arg3, arg4, arg5, and arg6.

Parameters:
messageId - The unique message identifier.
arg1 - A parameter String to be inserted at %1.
arg2 - A parameter String to be inserted at %2.
arg3 - A parameter String to be inserted at %3.
arg4 - A parameter String to be inserted at %4.
arg5 - A parameter String to be inserted at %5.
arg6 - A parameter String to be inserted at %6.
Returns:
The localized String.

sub

public static final String sub(String src,
                               String srch,
                               String repl,
                               boolean ignoreCase)
Replace the first occurrence of a String srch in String src by replacement repl. If the pattern isn't found, the String is returned unchanged.

Parameters:
src - any String.
srch - the String to search for.
repl - the replacement String.
ignoreCase - a boolean determining case sensitivity of matches.
Returns:
Returns the String with the first instance of the search pattern replaced by the replacement String. If no occurrences of the search pattern are found, returns the String unchanged.

convertTildeEncoding

public static String convertTildeEncoding(String s)
Converts all vowels followed by a tilde ('~') character to its equivalent macron'd version (in UTF-8) encoding. This does not use character entities, but UTF-8 characters.


gsub

public static final String gsub(String src,
                                String srch,
                                String repl,
                                boolean ignoreCase)
Replace all (non-overlapping) occurrences of a String srch in String src by replacement repl. If the pattern isn't found, the String is returned unchanged. A null source String returns null.

Parameters:
src - any String.
srch - the String to search for.
repl - the replacement String.
ignoreCase - a boolean determining case sensitivity of matches.
Returns:
Returns the String with all instances of the search pattern replaced by the replacement String. If no occurrences of the search pattern are found, returns the String unchanged.

oldGsub

public static final String oldGsub(String src,
                                   String srch,
                                   String repl,
                                   boolean ignoreCase)
Replace all (non-overlapping) occurrences of a String srch in String src by replacement repl. If the pattern isn't found, the String is returned unchanged.

Parameters:
src - any String.
srch - the String to search for.
repl - the replacement String.
ignoreCase - a boolean determining case sensitivity of matches.
Returns:
Returns the String with all instances of the search pattern replaced by the replacement String. If no occurrences of the search pattern are found, returns the String unchanged.

charCount

public static int charCount(String s,
                            char c)
Returns the number of times the provided character appears in the String.


getStackTraceAsString

public static String getStackTraceAsString(Throwable t)
Returns the stack trace from Throwable t as a single String.


processMessage

public static String processMessage(String id,
                                    Object[] args)
Get message text from the default, localized ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text. This uses the org.ceryle.util.Msg ResourceBundle if the ID is null or starts with an underscore character, org.ceryle.util.Messages otherwise. If the inferred ResourceBundle is not found the method fails silently, simply returning the unprocessed ID String.


processMessage

public static String processMessage(String id,
                                    Object[] args,
                                    ResourceBundle bundle)
Get message text from the supplied ResourceBundle using id as key, then substitute arguments into (%1, %2, %3, etc.) placeholders in text.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.