planetj.common
Class CMUtility

java.lang.Object
  extended byplanetj.common.BusinessObject
      extended byplanetj.common.CMUtility
All Implemented Interfaces:
Invokeable, java.io.Serializable

public class CMUtility
extends BusinessObject

This type was created in VisualAge.

See Also:
Serialized Form

Nested Class Summary
static class CMUtility.OverwriteOption
           
 
Field Summary
static java.lang.Class[] EMPTY_CLASS_ARRAY
           
static java.lang.Object[] EMPTY_OBJECT_ARRAY
           
static CMUtility.OverwriteOption OVERWRITE_ALWAYS
          Always overwrite files when copying
static CMUtility.OverwriteOption OVERWRITE_BY_TIMESTAMP
          Overwrite files when copying if and only if the file being copied has a later timestamp than the one that would be overwritten
static CMUtility.OverwriteOption OVERWRITE_NEVER
          Never overwrite files when copying
 
Fields inherited from class planetj.common.BusinessObject
methodHashTable
 
Constructor Summary
CMUtility()
           
 
Method Summary
static java.util.Vector arrayToVector(java.lang.Object[] array)
          Insert the method's description here.
static java.lang.String backslashApostrophes(java.lang.String s)
          Inserts a backslash before any apostrophes in the String
static int copy(java.io.File source, java.io.File destination)
          Copies a file or directory.
static int copy(java.io.File source, java.io.File destination, java.util.List extensions, CMUtility.OverwriteOption overwrite)
          Copies a file or directory.
static int copy(java.lang.String source, java.lang.String destination)
          Copies a file or directory.
static int copy(java.lang.String source, java.lang.String destination, java.util.List extensions, CMUtility.OverwriteOption overwrite)
          Copies a file or directory.
static boolean deleteFile(java.io.File pFile)
          Removes the specified file or directory, and all subdirectories
static boolean deleteFile(java.lang.String pFilePath)
          Removes the specified file or directory, and all subdirectories
static long endSystemTimer()
          endSystemTimer method records the currentTimeMillis and computes the time elapsed since the call to startSystemTimer().
static boolean equals(java.lang.Object o1, java.lang.Object o2)
          Tests two Objects for equality
static boolean equalsIgnoreCase(java.lang.String s1, java.lang.String s2)
          Tests two Strings for equality, ignoring case
static java.math.BigDecimal getBigDecimal(int i)
          Gets an BigDecimal object for the specified int, possibly from a cache
static java.math.BigInteger getBigInteger(int i)
          Gets an BigInteger object for the specified int, possibly from a cache
static int getDifferenceInDays(java.util.Date from, java.util.Date to)
          Get the number of days between the two given dates (regardless of hours).
static java.lang.reflect.Method getGetterMethod(java.lang.Class c, MethodProperties mp)
          Gets the Method from the Class with the name specified in the MethodProperties object along with a String[] parameter containing all the Strings[] in the method properties object.
static int getHashCode(java.lang.Object o)
          Gets an object's hashcode
static java.lang.Integer getInteger(int i)
          Gets an Integer object for the specified int, possibly from a cache
static int getNumberOfDigits(int number)
          Get the number of digits for the given int.
static double getPercentage(java.lang.Number val1, java.lang.Number val2)
          Gets the percentage difference between the two numbers.
static java.lang.reflect.Method getSetterMethod(java.lang.Class c, MethodProperties mp)
          Gets the Method from the Class with the name specified in the MethodProperties object along with a String[] parameter containing all the Strings[] in the method properties object.
static java.lang.String getString(int i)
          Gets a String representation for the given int, possibly from a cache.
static double getVariancePercentage(java.lang.Number val1, java.lang.Number val2)
          Gets the percentage difference between the two numbers.
static java.lang.Object invokeMethod(java.lang.Class targetObjectClass, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] params)
          Invokes the specified method via reflection.
static java.lang.Object invokeMethod(java.lang.Class targetObjectClass, java.lang.String methodName, java.lang.Object[] params)
          Invokes the specified method via reflection.
static java.lang.Object invokeMethod(java.lang.Object targetObject, java.lang.Class targetObjectClass, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] parameters)
          Invokes the specified method via reflection.
static java.lang.Object invokeMethod(java.lang.Object targetObject, java.lang.Class targetObjectClass, java.lang.String methodName, java.lang.Object[] params)
          Invokes the specified method via reflection.
static java.lang.String ipAddressToString(byte[] ipAddress)
          Converts an IP address into a String
static boolean isBeginsWith(java.lang.String mainString, java.lang.String startingString)
          Tests if the first String begins with the second one
static boolean isRunningInDevelopment()
          Deprecated. - Replaced by CMUtility.isRunningInVA()
static boolean isRunningInTomcat()
          Test if this java program is running in Visual Age
static boolean isRunningInVA()
          Test if this java program is running in Visual Age
static boolean isRunningInWAS()
          If we are running in WAS or not
static boolean isRunningInWASExpress()
          If we are running in WAS Express or not
static boolean isRunningInWindows()
          Test if this java program is running on a Windows system
static boolean isRunningInWSAD()
          If we are running in Studio Application Developer
static boolean isRunningInWSSDExpress()
          If we are running in Studio Site Developer or not
static boolean isStringContainNumeric(java.lang.String value)
          Returns true if the any char in the String is numeric
static boolean isStringNumeric(java.lang.String value)
          Test if the given String contains all digits/numbers.
static java.lang.StringBuffer mergeStrings(java.lang.StringBuffer pBuffer, java.lang.String pString)
          This will merge pString into pBuffer
static int moveElementDownOne(java.util.List l, int index)
          Takes a ltor and the index and moves the element up one position
static int moveElementUpOne(java.util.List l, int index)
          Takes a ltor and the index and moves the element up one position
static MethodProperties parseMethod(java.lang.String method)
          Takes the given String representing a Method, parses it into its method name and parameters, and then stores them in a MethodProperties object which can later be used to retrieve the different parts.
static void runClientSideApplication(java.lang.String path)
          executes the given path and file EXAMPLE Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe c:\\jmagic\\cave.htm");
static void startSystemTimer()
          startSystemTime method records the currentTimeMillis of the system to be used for later calculation.
static java.lang.String stripOffAllNonNumericCharacters(java.lang.String alphaChars)
          stripOffAllNonNumericCharacters() will return a string of all intergers and strip off all values that are non-numeric
static int sum(int[] numbers)
          Sums up an array of integers
static float[] toFloatArray(java.util.List strings)
          Converts the values in a List with to float values.
static java.util.List toList(java.util.Enumeration e)
          Adds all elements in the Enumeration to a new List
static java.util.List toList(java.util.Iterator i)
          Adds all elements in the Iterator to a new List
static java.util.List toLowerCase(java.util.List l)
          Lowercases a List of String objects.
static java.util.List toUpperCase(java.util.List l)
          Uppercases a List of String objects.
static java.util.List trim(java.util.List pStrings)
          Trims a List of Strings
static java.lang.String trim(java.lang.String inpString)
          trim String object and ensure nulls are not returned
static java.util.List trimNulls(java.util.List pList)
          Removes all null references from the end of the List
static java.lang.String trimTo(java.lang.String string, int x)
          trim String object to x characters in length and ensure nulls are not returned
static java.lang.String trimTrailing(java.lang.String pString)
          Returns a String with all trailing white spaces removed.
static boolean validateAS400Name(java.lang.String name)
          Test the name String for AS400 naming compliance
 
Methods inherited from class planetj.common.BusinessObject
generateException, generateException, generateException, generateException, generateException, getTranslation, invoke, toBoolean, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OVERWRITE_ALWAYS

public static CMUtility.OverwriteOption OVERWRITE_ALWAYS
Always overwrite files when copying


OVERWRITE_NEVER

public static CMUtility.OverwriteOption OVERWRITE_NEVER
Never overwrite files when copying


OVERWRITE_BY_TIMESTAMP

public static CMUtility.OverwriteOption OVERWRITE_BY_TIMESTAMP
Overwrite files when copying if and only if the file being copied has a later timestamp than the one that would be overwritten


EMPTY_CLASS_ARRAY

public static final java.lang.Class[] EMPTY_CLASS_ARRAY

EMPTY_OBJECT_ARRAY

public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
Constructor Detail

CMUtility

public CMUtility()
Method Detail

arrayToVector

public static java.util.Vector arrayToVector(java.lang.Object[] array)
Insert the method's description here. Creation date: (9/24/00 3:07:12 PM)

Parameters:
array - java.lang.Object[]
Returns:
java.util.Vector

backslashApostrophes

public static final java.lang.String backslashApostrophes(java.lang.String s)
Inserts a backslash before any apostrophes in the String


copy

public static int copy(java.io.File source,
                       java.io.File destination)
                throws java.io.IOException
Copies a file or directory. Existing files are overwritten without warning.

Parameters:
source - The file or directory to copy. If this is a directory, then the directory itself (and not just the directory's contents) will be copied
destination - The directory to copy to. This directory must exist already.
Returns:
The total number of files (not including directories) that were copied
Throws:
java.io.IOException

copy

public static int copy(java.io.File source,
                       java.io.File destination,
                       java.util.List extensions,
                       CMUtility.OverwriteOption overwrite)
                throws java.io.IOException
Copies a file or directory. Existing files are overwritten without warning.

Parameters:
source - The file or directory to copy. If this is a directory, then the directory itself (and not just the directory's contents) will be copied
destination - The directory to copy to. This directory must exist already.
extensions - A list of the case sensitive file extensions that should be copied. (The file extension is everything after the last period in the file name.) Files specified by source which end in extensions other than those specified in the list will not be copied. If the extension list is null, then all files will be copied. The extension list has no effect on whether directories are copied or not
overwrite - Constant describing how to handle cases where the file to be written to already exists
Returns:
The total number of files (not including directories) that were copied
Throws:
java.io.IOException

copy

public static int copy(java.lang.String source,
                       java.lang.String destination)
                throws java.io.IOException
Copies a file or directory. Existing files are overwritten without warning.

Parameters:
source - The file or directory to copy
destination - The directory to copy to. This directory must exist already.
Returns:
The total number of files (not including directories) that were copied
Throws:
java.io.IOException

copy

public static int copy(java.lang.String source,
                       java.lang.String destination,
                       java.util.List extensions,
                       CMUtility.OverwriteOption overwrite)
                throws java.io.IOException
Copies a file or directory.

Parameters:
source - The file or directory to copy
destination - The directory to copy to. This directory must exist already.
extensions - A list of the case sensitive file extensions that should be copied. (The file extension is everything after the last period in the file name.) Files specified by source which end in extensions other than those specified in the list will not be copied. If the extension list is null, then all files will be copied. The extension list has no effect on whether directories are copied or not
overwrite - Constant describing how to handle cases where the file to be written to already exists
Returns:
The total number of files (not including directories) that were copied
Throws:
java.io.IOException

deleteFile

public static boolean deleteFile(java.io.File pFile)
Removes the specified file or directory, and all subdirectories

Parameters:
pFile - The file or directory that you wish to delete

deleteFile

public static boolean deleteFile(java.lang.String pFilePath)
Removes the specified file or directory, and all subdirectories

Parameters:
pFilePath - The Absolute Path to a file or directory that you wish to delete

endSystemTimer

public static final long endSystemTimer()
endSystemTimer method records the currentTimeMillis and computes the time elapsed since the call to startSystemTimer(). A return value of -1 is given if no time has elapsed or no call to startSystemTimer has been made.

Returns:
long
See Also:
startSystemTimer

equals

public static final boolean equals(java.lang.Object o1,
                                   java.lang.Object o2)
Tests two Objects for equality


equalsIgnoreCase

public static final boolean equalsIgnoreCase(java.lang.String s1,
                                             java.lang.String s2)
Tests two Strings for equality, ignoring case


getBigDecimal

public static final java.math.BigDecimal getBigDecimal(int i)
Gets an BigDecimal object for the specified int, possibly from a cache


getDifferenceInDays

public static final int getDifferenceInDays(java.util.Date from,
                                            java.util.Date to)
Get the number of days between the two given dates (regardless of hours). If the from date is greater than the to date, a negative number will be returned.


getBigInteger

public static final java.math.BigInteger getBigInteger(int i)
Gets an BigInteger object for the specified int, possibly from a cache


getGetterMethod

public static java.lang.reflect.Method getGetterMethod(java.lang.Class c,
                                                       MethodProperties mp)
                                                throws java.lang.NoSuchMethodException
Gets the Method from the Class with the name specified in the MethodProperties object along with a String[] parameter containing all the Strings[] in the method properties object.

Note: this method is only used for retrieving methods with a String[] paramter.

Parameters:
c - Class
mp - MethodProperties
Returns:
Method
Throws:
java.lang.NoSuchMethodException

getHashCode

public static final int getHashCode(java.lang.Object o)
Gets an object's hashcode


getInteger

public static final java.lang.Integer getInteger(int i)
Gets an Integer object for the specified int, possibly from a cache


getNumberOfDigits

public static int getNumberOfDigits(int number)
Get the number of digits for the given int.


getPercentage

public static double getPercentage(java.lang.Number val1,
                                   java.lang.Number val2)
Gets the percentage difference between the two numbers. For example... getPercentage(1, 2) = .5


getSetterMethod

public static java.lang.reflect.Method getSetterMethod(java.lang.Class c,
                                                       MethodProperties mp)
                                                throws java.lang.NoSuchMethodException
Gets the Method from the Class with the name specified in the MethodProperties object along with a String[] parameter containing all the Strings[] in the method properties object.

Note: this method is only used for retrieving methods with a String[] paramter.

Parameters:
c - Class
mp - MethodProperties
Returns:
Method
Throws:
java.lang.NoSuchMethodException

getString

public static final java.lang.String getString(int i)
Gets a String representation for the given int, possibly from a cache.


getVariancePercentage

public static double getVariancePercentage(java.lang.Number val1,
                                           java.lang.Number val2)
Gets the percentage difference between the two numbers. Checks to see how much different the first value is from the second. e.g. val1 = 50 and val2 = 10, then the percentage returned is 500.


invokeMethod

public static final java.lang.Object invokeMethod(java.lang.Class targetObjectClass,
                                                  java.lang.String methodName,
                                                  java.lang.Class[] parameterTypes,
                                                  java.lang.Object[] params)
                                           throws java.lang.Exception
Invokes the specified method via reflection. You must provide the fully qualified class name, as well as the parameters for the method. This method assumes that the method you are trying to invoke is a static method. Creation date: (1/27/2003 10:42:56 AM)

Parameters:
targetObjectClass - java.lang.Class
methodName - java.lang.String
parameterTypes - java.Class[]
params - java.util.Object[]
Returns:
java.lang.Object
Throws:
java.lang.Exception

invokeMethod

public static final java.lang.Object invokeMethod(java.lang.Class targetObjectClass,
                                                  java.lang.String methodName,
                                                  java.lang.Object[] params)
                                           throws java.lang.Exception
Invokes the specified method via reflection. You must provide the fully qualified class name, as well as the parameters for the method. This method assumes that the method you are trying to invoke is a static method. Creation date: (1/27/2003 10:42:56 AM)

Parameters:
targetObjectClass - java.lang.Class
methodName - java.lang.String
params - java.util.Object[]
Returns:
java.lang.Object
Throws:
java.lang.Exception

invokeMethod

public static final java.lang.Object invokeMethod(java.lang.Object targetObject,
                                                  java.lang.Class targetObjectClass,
                                                  java.lang.String methodName,
                                                  java.lang.Class[] parameterTypes,
                                                  java.lang.Object[] parameters)
                                           throws java.lang.Exception
Invokes the specified method via reflection. You must provide the fully qualified class name, as well as the parameters for the method. Creation date: (1/27/2003 10:42:56 AM)

Parameters:
targetObject - java.lang.Object The object the underlying method is invoked from. If the underlying method is static, then pass null
targetObjectClass - java.lang.String
methodName - java.lang.String
parameterTypes - java.lang.Class[]
Returns:
java.lang.Object
Throws:
java.lang.Exception

invokeMethod

public static final java.lang.Object invokeMethod(java.lang.Object targetObject,
                                                  java.lang.Class targetObjectClass,
                                                  java.lang.String methodName,
                                                  java.lang.Object[] params)
                                           throws java.lang.Exception
Invokes the specified method via reflection. Does not require the Class array argument, so they class types for the arguments will be assumed to be the same as the arguments Creation date: (1/27/2003 10:42:56 AM)

Parameters:
targetObject - java.lang.Object
targetObjectClass - java.lang.Class
methodName - java.lang.String
params - java.util.Object[]
Returns:
java.lang.Object
Throws:
java.lang.Exception

ipAddressToString

public static final java.lang.String ipAddressToString(byte[] ipAddress)
Converts an IP address into a String


isBeginsWith

public static final boolean isBeginsWith(java.lang.String mainString,
                                         java.lang.String startingString)
Tests if the first String begins with the second one


isRunningInDevelopment

public static final boolean isRunningInDevelopment()
Deprecated. - Replaced by CMUtility.isRunningInVA()

Test if this java program is running in the developement environment


isRunningInTomcat

public static final boolean isRunningInTomcat()
Test if this java program is running in Visual Age


isRunningInVA

public static final boolean isRunningInVA()
Test if this java program is running in Visual Age


isRunningInWAS

public static final boolean isRunningInWAS()
If we are running in WAS or not


isRunningInWASExpress

public static final boolean isRunningInWASExpress()
If we are running in WAS Express or not


isRunningInWindows

public static final boolean isRunningInWindows()
Test if this java program is running on a Windows system


isRunningInWSSDExpress

public static final boolean isRunningInWSSDExpress()
If we are running in Studio Site Developer or not


isRunningInWSAD

public static final boolean isRunningInWSAD()
If we are running in Studio Application Developer


isStringContainNumeric

public static boolean isStringContainNumeric(java.lang.String value)
Returns true if the any char in the String is numeric

Returns:
boolean

isStringNumeric

public static boolean isStringNumeric(java.lang.String value)
Test if the given String contains all digits/numbers.

Returns:
true if the given string is all digits/numbers.

mergeStrings

public static final java.lang.StringBuffer mergeStrings(java.lang.StringBuffer pBuffer,
                                                        java.lang.String pString)
This will merge pString into pBuffer

Example: pBuffer.toString() = I the in hat pString = love cat the . Return value of pBuffer = I love the cat in the hat.

The text in the StringBuffer pBuffer will never be overriden by pString unless the value for that char is a blank ' '. Example: pBuffer.toString() = I love the in hat pString = hate cat the . Return value of pBuffer = I love the cat in the hat.

Creation date: (7/30/2002 3:08:17 PM)


moveElementDownOne

public static final int moveElementDownOne(java.util.List l,
                                           int index)
Takes a ltor and the index and moves the element up one position


moveElementUpOne

public static final int moveElementUpOne(java.util.List l,
                                         int index)
Takes a ltor and the index and moves the element up one position


parseMethod

public static MethodProperties parseMethod(java.lang.String method)
Takes the given String representing a Method, parses it into its method name and parameters, and then stores them in a MethodProperties object which can later be used to retrieve the different parts.

Parameters:
method - String
Returns:
MethodProperties
See Also:
MethodProperties

runClientSideApplication

public static void runClientSideApplication(java.lang.String path)
                                     throws java.lang.Exception
executes the given path and file EXAMPLE Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore.exe c:\\jmagic\\cave.htm");

Throws:
java.lang.Exception

startSystemTimer

public static final void startSystemTimer()
startSystemTime method records the currentTimeMillis of the system to be used for later calculation.


stripOffAllNonNumericCharacters

public static final java.lang.String stripOffAllNonNumericCharacters(java.lang.String alphaChars)
stripOffAllNonNumericCharacters() will return a string of all intergers and strip off all values that are non-numeric


sum

public static final int sum(int[] numbers)
Sums up an array of integers


toFloatArray

public static float[] toFloatArray(java.util.List strings)
Converts the values in a List with to float values. The toString() method of each of the List's values is used to convert to a String, which is then converted into a float. Null values in the List are converted to Float.NaN


toList

public static java.util.List toList(java.util.Enumeration e)
Adds all elements in the Enumeration to a new List


toList

public static java.util.List toList(java.util.Iterator i)
Adds all elements in the Iterator to a new List


toLowerCase

public static java.util.List toLowerCase(java.util.List l)
Lowercases a List of String objects. All the objects in the List must be Strings; they will be replaced with uppercase String objects. The same List is returned.


toUpperCase

public static java.util.List toUpperCase(java.util.List l)
Uppercases a List of String objects. All the objects in the List must be Strings; they will be replaced with uppercase String objects. The same List is returned.


trim

public static final java.util.List trim(java.util.List pStrings)
Trims a List of Strings


trim

public static final java.lang.String trim(java.lang.String inpString)
trim String object and ensure nulls are not returned


trimNulls

public static final java.util.List trimNulls(java.util.List pList)
Removes all null references from the end of the List


trimTo

public static final java.lang.String trimTo(java.lang.String string,
                                            int x)
trim String object to x characters in length and ensure nulls are not returned


trimTrailing

public static final java.lang.String trimTrailing(java.lang.String pString)
Returns a String with all trailing white spaces removed. Example if a String "Tyler is cool. " comes in at pString, the string "Tyler is cool." will be returned. The 3 spaces at the end will be removed. Unlike String.trim() no leading spaces will be trimmed off. Example if a String " Tyler's a hunk." comes in at pString The exact string " Tyler's a hunk." will be returned. Creation date: (4/17/2002 1:27:08 PM)


validateAS400Name

public static final boolean validateAS400Name(java.lang.String name)
Test the name String for AS400 naming compliance

Returns:
a boolean that indicates if naming conventions are followed correctly.