FileDocCategorySizeDatePackage
Helper.javaAPI DocGlassfish v2 API72052Thu Jul 19 11:51:58 BST 2007oracle.toplink.essentials.internal.helper

Helper

public class Helper extends Object implements Serializable
INTERNAL:

Purpose: Define any usefull methods that are missing from the base Java.

Fields Summary
protected static boolean
shouldOptimizeDates
Used to configure JDBC level date optimization.
protected static final Object
nullWrapper
Used to store null values in hashtables, is helper because need to be serializable.
protected static Vector
calendarCache
PERF: Used to cache a set of calendars for conversion/printing purposes.
protected static TimeZone
defaultTimeZone
PERF: Cache default timezone for calendar conversion.
protected static String
CR
Store CR string, for some reason \n is not platform independent.
protected static String
PATH_SEPARATOR
Prime the platform-dependent path separator
protected static String
FILE_SEPARATOR
Prime the platform-dependent file separator
protected static String
CURRENT_WORKING_DIRECTORY
Prime the platform-dependent current working directory
protected static String
TEMP_DIRECTORY
Prime the platform-dependent temporary directory
Constructors Summary
Methods Summary
public static voidaddAllToVector(java.util.Vector theVector, java.util.Vector elementsToAdd)

        for (Enumeration stream = elementsToAdd.elements(); stream.hasMoreElements();) {
            theVector.addElement(stream.nextElement());
        }
    
public static voidaddAllToVector(java.util.Vector theVector, java.util.List elementsToAdd)

        theVector.addAll(elementsToAdd);
    
public static java.util.VectoraddAllUniqueToVector(java.util.Vector theVector, java.util.Vector elementsToAdd)

        for (Enumeration stream = elementsToAdd.elements(); stream.hasMoreElements();) {
            Object element = stream.nextElement();
            if (!theVector.contains(element)) {
                theVector.addElement(element);
            }
        }

        return theVector;
    
public static java.util.CalendarallocateCalendar()
PERF: This is used to optimize Calendar conversion/printing. This should only be used when a calendar is temporarily required, when finished it must be released back.

        Calendar calendar = null;
        synchronized (calendarCache) {
            if (calendarCache.size() > 0) {
                calendar = (Calendar)calendarCache.remove(calendarCache.size() - 1);
            }
        }
        if (calendar == null) {
            calendar = Calendar.getInstance();
        }
        return calendar;
    
public static booleanareTypesAssignable(java.util.Vector types1, java.util.Vector types2)
PUBLIC: Compare two vectors of types. Return true if the size of the vectors is the same and each of the types in the first Vector are assignable from the types in the corresponding objects in the second Vector.

        if ((types1 == null) || (types2 == null)) {
            return false;
        }

        if (types1.size() == types2.size()) {
            for (int i = 0; i < types1.size(); i++) {
                Class type1 = (Class)types1.elementAt(i);
                Class type2 = (Class)types2.elementAt(i);

                // if either are null then we assume assignability.
                if ((type1 != null) && (type2 != null)) {
                    if (!type1.isAssignableFrom(type2)) {
                        return false;
                    }
                }
            }
            return true;
        }

        return false;
    
public static java.lang.Object[]arrayFromVector(java.util.Vector vector)
Convert the specified vector into an array.

        Object[] result = new Object[vector.size()];
        for (int i = 0; i < vector.size(); i++) {
            result[i] = vector.elementAt(i);
        }
        return result;
    
public static byte[]buildBytesFromHexString(java.lang.String hex)
Convert the HEX string to a byte array. HEX allows for binary data to be printed.

        String tmpString = (String)hex;
        if ((tmpString.length() % 2) != 0) {
            throw ConversionException.couldNotConvertToByteArray(hex);
        }
        byte[] bytes = new byte[tmpString.length() / 2];
        int byteIndex;
        int strIndex;
        byte digit1;
        byte digit2;
        for (byteIndex = bytes.length - 1, strIndex = tmpString.length() - 2; byteIndex >= 0;
                 byteIndex--, strIndex -= 2) {
            digit1 = (byte)Character.digit(tmpString.charAt(strIndex), 16);
            digit2 = (byte)Character.digit(tmpString.charAt(strIndex + 1), 16);
            if ((digit1 == -1) || (digit2 == -1)) {
                throw ConversionException.couldNotBeConverted(hex, ClassConstants.APBYTE);
            }
            bytes[byteIndex] = (byte)((digit1 * 16) + digit2);
        }
        return bytes;
    
public static java.util.HashtablebuildHashtableFromVector(java.util.Vector theVector)
Convert the passed Vector to a Hashtable Return the Hashtable

        Hashtable toReturn = new Hashtable(theVector.size());

        Iterator iter = theVector.iterator();
        while (iter.hasNext()) {
            Object next = iter.next();
            toReturn.put(next, next);
        }
        return toReturn;
    
public static java.lang.StringbuildHexStringFromBytes(byte[] bytes)
Convert the byte array to a HEX string. HEX allows for binary data to be printed.

        char[] hexArray = { '0", '1", '2", '3", '4", '5", '6", '7", '8", '9", 'A", 'B", 'C", 'D", 'E", 'F" };
        StringBuffer stringBuffer = new StringBuffer();
        int tempByte;
        for (int byteIndex = 0; byteIndex < ((byte[])bytes).length; byteIndex++) {
            tempByte = ((byte[])bytes)[byteIndex];
            if (tempByte < 0) {
                tempByte = tempByte + 256;//compensate for the fact that byte is signed in Java
            }
            tempByte = (byte)(tempByte / 16);//get the first digit
            if (tempByte > 16) {
                throw ConversionException.couldNotBeConverted(bytes, ClassConstants.STRING);
            }
            stringBuffer.append(hexArray[tempByte]);

            tempByte = ((byte[])bytes)[byteIndex];
            if (tempByte < 0) {
                tempByte = tempByte + 256;
            }
            tempByte = (byte)(tempByte % 16);//get the second digit
            if (tempByte > 16) {
                throw ConversionException.couldNotBeConverted(bytes, ClassConstants.STRING);
            }
            stringBuffer.append(hexArray[tempByte]);
        }
        return stringBuffer.toString();
    
public static java.util.VectorbuildVectorFromHashtableElements(java.util.Hashtable hashtable)
Create a new Vector containing all of the hashtable elements

        Vector vector = new Vector(hashtable.size());
        Enumeration enumeration = hashtable.elements();

        while (enumeration.hasMoreElements()) {
            vector.addElement(enumeration.nextElement());
        }

        return vector;
    
public static java.util.VectorbuildVectorFromHashtableElements(oracle.toplink.essentials.internal.helper.IdentityHashtable hashtable)
Create a new Vector containing all of the hashtable elements

        Vector vector = new Vector(hashtable.size());
        Enumeration enumeration = hashtable.elements();

        while (enumeration.hasMoreElements()) {
            vector.addElement(enumeration.nextElement());
        }

        return vector;
    
public static java.util.VectorbuildVectorFromMapElements(java.util.Map map)
Create a new Vector containing all of the map elements.

        Vector vector = new Vector(map.size());
        Iterator iterator = map.values().iterator();

        while (iterator.hasNext()) {
            vector.addElement(iterator.next());
        }

        return vector;
    
public static java.lang.StringbuildZeroPrefix(int number, int totalDigits)
Build a numerical string with leading 0s. number is an existing number that the new string will be built on. totalDigits is the number of the required digits of the string.

        String zeros = "000000000";
        int absValue = (number < 0) ? (-number) : number;
        String numbString = Integer.toString(absValue);

        // Add leading zeros
        numbString = zeros.substring(0, (totalDigits - numbString.length())) + numbString;

        if (number < 0) {
            numbString = "-" + numbString;
        } else {
            numbString = "+" + numbString;
        }            
        return numbString;
    
public static java.lang.StringbuildZeroPrefixAndTruncTrailZeros(int number, int totalDigits)
Build a numerical string with leading 0s and truncate trailing zeros. number is an existing number that the new string will be built on. totalDigits is the number of the required digits of the string.

        String zeros = "000000000";
        String numbString = Integer.toString(number);

        // Add leading zeros
        numbString = zeros.substring(0, (totalDigits - numbString.length())) + numbString;
        // Truncate trailing zeros
        char[] numbChar = new char[numbString.length()];
        numbString.getChars(0, numbString.length(), numbChar, 0);
        int truncIndex = totalDigits - 1;
        while (numbChar[truncIndex] == '0") {
            truncIndex--;
        }
        return new String(numbChar, 0, truncIndex + 1);
    
public static java.util.CalendarcalendarFromUtilDate(java.util.Date date)
Answer a Calendar from a date.

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //In jdk1.3, millisecond is missing
        if (date instanceof Timestamp) {
            calendar.set(Calendar.MILLISECOND, ((Timestamp)date).getNanos() / 1000000);
        }
        return calendar;
    
public static booleanclassImplementsInterface(java.lang.Class aClass, java.lang.Class anInterface)
INTERNAL: Return whether a Class implements a specific interface, either directly or indirectly (through interface or implementation inheritance).

return
boolean

        // quick check
        if (aClass == anInterface) {
            return true;
        }

        Class[] interfaces = aClass.getInterfaces();

        // loop through the "directly declared" interfaces
        for (int i = 0; i < interfaces.length; i++) {
            if (interfaces[i] == anInterface) {
                return true;
            }
        }

        // recurse through the interfaces
        for (int i = 0; i < interfaces.length; i++) {
            if (classImplementsInterface(interfaces[i], anInterface)) {
                return true;
            }
        }

        // finally, recurse up through the superclasses to Object
        Class superClass = aClass.getSuperclass();
        if (superClass == null) {
            return false;
        }
        return classImplementsInterface(superClass, anInterface);
    
public static booleanclassIsSubclass(java.lang.Class subClass, java.lang.Class superClass)
INTERNAL: Return whether a Class is a subclass of, or the same as, another Class.

return
boolean

        Class temp = subClass;

        if (superClass == null) {
            return false;
        }

        while (temp != null) {
            if (temp == superClass) {
                return true;
            }
            temp = temp.getSuperclass();
        }
        return false;
    
public static booleancompareArrays(java.lang.Object[] array1, java.lang.Object[] array2)

        if (array1.length != array2.length) {
            return false;
        }
        for (int index = 0; index < array1.length; index++) {
            //Related to Bug#3128838 fix.  ! is added to correct the logic.
            if (!array1[index].equals(array2[index])) {
                return false;
            }
        }
        return true;
    
public static booleancompareBigDecimals(java.math.BigDecimal one, java.math.BigDecimal two)
Compare two BigDecimals. This is required because the .equals method of java.math.BigDecimal ensures that the scale of the two numbers are equal. Therefore 0.0 != 0.00.

see
java.math.BigDecimal#equals(Object)

        if (one.scale() != two.scale()) {
            double doubleOne = ((java.math.BigDecimal)one).doubleValue();
            double doubleTwo = ((java.math.BigDecimal)two).doubleValue();
            if ((doubleOne != Double.POSITIVE_INFINITY) && (doubleOne != Double.NEGATIVE_INFINITY) && (doubleTwo != Double.POSITIVE_INFINITY) && (doubleTwo != Double.NEGATIVE_INFINITY)) {
                return doubleOne == doubleTwo;
            }
        }
        return one.equals(two);
    
public static booleancompareByteArrays(byte[] array1, byte[] array2)

        if (array1.length != array2.length) {
            return false;
        }
        for (int index = 0; index < array1.length; index++) {
            if (array1[index] != array2[index]) {
                return false;
            }
        }
        return true;
    
public static booleancompareCharArrays(char[] array1, char[] array2)

        if (array1.length != array2.length) {
            return false;
        }
        for (int index = 0; index < array1.length; index++) {
            if (array1[index] != array2[index]) {
                return false;
            }
        }
        return true;
    
public static booleancompareHashtables(java.util.Hashtable hashtable1, java.util.Hashtable hashtable2)
PUBLIC: Compare the elements in 2 hashtables to see if they are equal Added Nov 9, 2000 JED Patch 2.5.1.8

        Enumeration enumtr;
        Object element;
        Hashtable clonedHashtable;

        if (hashtable1.size() != hashtable2.size()) {
            return false;
        }

        clonedHashtable = (Hashtable)hashtable2.clone();

        enumtr = hashtable1.elements();
        while (enumtr.hasMoreElements()) {
            element = enumtr.nextElement();
            if (clonedHashtable.remove(element) == null) {
                return false;
            }
        }

        return clonedHashtable.isEmpty();
    
public static booleancompareOrderedVectors(java.util.Vector vector1, java.util.Vector vector2)
Compare the elements in two Vectors to see if they are equal. The order of the elements is significant.

return
whether the two vectors are equal

        if (vector1 == vector2) {
            return true;
        }
        if (vector1.size() != vector2.size()) {
            return false;
        }
        for (int index = 0; index < vector1.size(); index++) {
            Object element1 = vector1.elementAt(index);
            Object element2 = vector2.elementAt(index);
            if (element1 == null) {// avoid null pointer exception
                if (element2 != null) {
                    return false;
                }
            } else {
                if (!element1.equals(element2)) {
                    return false;
                }
            }
        }
        return true;
    
public static booleancompareUnorderedVectors(java.util.Vector v1, java.util.Vector v2)
Compare the elements in two Vectors to see if they are equal. The order of the elements is ignored.

param
v1 a vector
param
v2 a vector
return
whether the two vectors contain the same elements

        if (v1 == v2) {
            return true;
        }
        if (v1.size() != v2.size()) {
            return false;
        }

        // One of the Vectors must be cloned so we don't miscompare
        // vectors with the same elements but in different quantities.
        // e.g. [fred, sam, sam] != [fred, sam, fred]
        Vector v3 = (Vector)v2.clone();
        for (int i = 0; i < v1.size(); i++) {
            Object e1 = v1.elementAt(i);
            if (e1 == null) {// avoid null pointer exception
                // Helper.removeNullElement() will return false if the element was not present to begin with
                if (!removeNullElement(v3)) {
                    return false;
                }
            } else {
                // Vector.removeElement() will return false if the element was not present to begin with
                if (!v3.removeElement(e1)) {
                    return false;
                }
            }
        }
        return true;
    
public static java.util.HashtableconcatenateHashtables(java.util.Hashtable first, java.util.Hashtable second)

        Hashtable concatenation;
        Object key;
        Object value;

        concatenation = new Hashtable(first.size() + second.size() + 4);

        for (Enumeration keys = first.keys(); keys.hasMoreElements();) {
            key = keys.nextElement();
            value = first.get(key);
            concatenation.put(key, value);
        }

        for (Enumeration keys = second.keys(); keys.hasMoreElements();) {
            key = keys.nextElement();
            value = second.get(key);
            concatenation.put(key, value);
        }

        return concatenation;
    
public static java.util.MapconcatenateMaps(java.util.Map first, java.util.Map second)
Merge the two Maps into a new HashMap.

        Map concatenation = new HashMap(first.size() + second.size() + 4);

        for (Iterator keys = first.keySet().iterator(); keys.hasNext();) {
            Object key = keys.next();
            Object value = first.get(key);
            concatenation.put(key, value);
        }

        for (Iterator keys = second.keySet().iterator(); keys.hasNext();) {
            Object key = keys.next();
            Object value = second.get(key);
            concatenation.put(key, value);
        }

        return concatenation;
    
public static java.util.VectorconcatenateUniqueVectors(java.util.Vector first, java.util.Vector second)
Return a new vector with no duplicated values

        Vector concatenation;
        Object element;

        concatenation = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();

        for (Enumeration stream = first.elements(); stream.hasMoreElements();) {
            concatenation.addElement(stream.nextElement());
        }

        for (Enumeration stream = second.elements(); stream.hasMoreElements();) {
            element = stream.nextElement();
            if (!concatenation.contains(element)) {
                concatenation.addElement(element);
            }
        }

        return concatenation;

    
public static java.util.VectorconcatenateVectors(java.util.Vector first, java.util.Vector second)

        Vector concatenation;

        concatenation = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();

        for (Enumeration stream = first.elements(); stream.hasMoreElements();) {
            concatenation.addElement(stream.nextElement());
        }

        for (Enumeration stream = second.elements(); stream.hasMoreElements();) {
            concatenation.addElement(stream.nextElement());
        }

        return concatenation;

    
public static booleancontainsNull(java.util.Vector v, int index)
Returns whether the given Vector contains a null element Return true if the Vector contains a null element Return false otherwise. This is needed in jdk1.1, where Vector.contains(Object) for a null element will result in a NullPointerException....

        return indexOfNullElement(v, 0) != -1;
    
public static java.util.VectorcopyVector(java.util.Vector originalVector, int startIndex, int stopIndex)
Return a copy of the vector containing a subset starting at startIndex and ending at stopIndex.

param
vector - original vector
param
startIndex - starting position in vector
param
stopIndex - ending position in vector
exception
TopLinkException

        Vector newVector;

        if (stopIndex < startIndex) {
            return oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        }

        if ((startIndex < 0) || (startIndex > originalVector.size())) {
            throw ValidationException.startIndexOutOfRange();
        }

        if ((stopIndex < 0) || (stopIndex > originalVector.size())) {
            throw ValidationException.stopIndexOutOfRange();
        }

        newVector = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();

        for (int index = startIndex; index < stopIndex; index++) {
            newVector.addElement(originalVector.elementAt(index));
        }

        return newVector;
    
public static java.lang.Stringcr()
Return a string containing the platform-appropriate characters for carriage return.

        // bug 2756643
        if (CR == null) {
            CR = System.getProperty("line.separator");
        }
        return CR;
    
public static java.lang.StringcurrentWorkingDirectory()
Return the name of the "current working directory".

        // bug 2756643
        if (CURRENT_WORKING_DIRECTORY == null) {
            CURRENT_WORKING_DIRECTORY = System.getProperty("user.dir");
        }
        return CURRENT_WORKING_DIRECTORY;
    
public static java.sql.DatedateFromCalendar(java.util.Calendar calendar)
Answer a sql.Date from a Calendar.

        if (!defaultTimeZone.equals(calendar.getTimeZone())) {
            // Must convert the calendar to the local timezone if different, as dates have no timezone (always local).
            Calendar localCalendar = allocateCalendar();
            JavaPlatform.setTimeInMillis(localCalendar, JavaPlatform.getTimeInMillis(calendar));
            java.sql.Date date = dateFromYearMonthDate(localCalendar.get(Calendar.YEAR), localCalendar.get(Calendar.MONTH), localCalendar.get(Calendar.DATE));
            releaseCalendar(localCalendar);
            return date;
        }
        return dateFromYearMonthDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
    
public static java.sql.DatedateFromLong(java.lang.Long longObject)
Answer a Date from a long This implementation is based on the java.sql.Date class, not java.util.Date.

param
longObject - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

        return new java.sql.Date(longObject.longValue());
    
public static java.sql.DatedateFromString(java.lang.String dateString)
Answer a Date from a string representation. The string MUST be a valid date and in one of the following formats: YYYY/MM/DD, YYYY-MM-DD, YY/MM/DD, YY-MM-DD. This implementation is based on the java.sql.Date class, not java.util.Date. The Date class contains some minor gotchas that you have to watch out for.

param
dateString - string representation of date
return
- date representation of string

        int year;
        int month;
        int day;
        StringTokenizer dateStringTokenizer;

        if (dateString.indexOf('/") != -1) {
            dateStringTokenizer = new StringTokenizer(dateString, "/");
        } else if (dateString.indexOf('-") != -1) {
            dateStringTokenizer = new StringTokenizer(dateString, "- ");
        } else {
            throw ConversionException.incorrectDateFormat(dateString);
        }

        try {
            year = Integer.parseInt(dateStringTokenizer.nextToken());
            month = Integer.parseInt(dateStringTokenizer.nextToken());
            day = Integer.parseInt(dateStringTokenizer.nextToken());
        } catch (NumberFormatException exception) {
            throw ConversionException.incorrectDateFormat(dateString);
        }

        // Java returns the month in terms of 0 - 11 instead of 1 - 12. 
        month = month - 1;

        return dateFromYearMonthDate(year, month, day);
    
public static java.sql.DatedateFromTimestamp(java.sql.Timestamp timestamp)
Answer a Date from a timestamp This implementation is based on the java.sql.Date class, not java.util.Date.

param
timestampObject - timestamp representation of date
return
- date representation of timestampObject

        return sqlDateFromUtilDate(timestamp);
    
public static java.sql.DatedateFromYearMonthDate(int year, int month, int day)
Answer a Date with the year, month, date. This builds a date avoiding the deprecated, inefficient and concurrency bottleneck date constructors. This implementation is based on the java.sql.Date class, not java.util.Date. The year, month, day are the values calendar uses, i.e. year is from 0, month is 0-11, date is 1-31.

        // Use a calendar to compute the correct millis for the date.
        Calendar localCalendar = allocateCalendar();
        localCalendar.clear();
        localCalendar.set(year, month, day, 0, 0, 0);
        long millis = JavaPlatform.getTimeInMillis(localCalendar);
        java.sql.Date date = new java.sql.Date(millis);
        releaseCalendar(localCalendar);
        return date;
    
public static booleandoesFileExist(java.lang.String fileName)
Returns true if the file of this name does indeed exist

        try {
            new FileReader(fileName);
        } catch (FileNotFoundException fnfException) {
            return false;
        }

        return true;

    
public static java.lang.StringdoubleSlashes(java.lang.String path)
Double up \ to allow printing of directories for source code generation.

        StringBuffer buffer = new StringBuffer(path.length() + 5);
        for (int index = 0; index < path.length(); index++) {
            char charater = path.charAt(index);
            buffer.append(charater);
            if (charater == '\\") {
                buffer.append('\\");
            }
        }

        return buffer.toString();
    
public static java.lang.StringextractJarNameFromURL(java.net.URL url)
Extracts the actual path to the jar file.

        String tempName = url.getFile();
        int start = tempName.indexOf("file:") + 5;
        int end = tempName.indexOf("!/");
        return tempName.substring(start, end);
    
public static java.lang.StringfileSeparator()
Return a string containing the platform-appropriate characters for separating directory and file names.

        //Bug 2756643
        if (FILE_SEPARATOR == null) {
            FILE_SEPARATOR = System.getProperty("file.separator");
        }
        return FILE_SEPARATOR;
    
public static java.lang.reflect.MethodgetDeclaredMethod(java.lang.Class javaClass, java.lang.String methodName, java.lang.Class[] methodParameterTypes)
INTERNAL: Returns a Method for the specified Class, method name, and formal parameter types. Uses Class.getDeclaredMethod(String Class[]) to find the method. If the method is not found on the specified class the superclass is checked, and so on, recursively. Set accessible to true, so we can access private/package/protected methods.

        if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
            try {
                return (Method)AccessController.doPrivileged(new PrivilegedGetMethod(javaClass, methodName, methodParameterTypes, true));
            } catch (PrivilegedActionException exception) {
                return null;
            }
        } else {
            return PrivilegedAccessHelper.getMethod(javaClass, methodName, methodParameterTypes, true);
        }
    
public static java.util.TimeZonegetDefaultTimeZone()
PERF: Return the cached default platform. Used for ensuring Calendar are in the local timezone. The JDK method clones the timezone, so cache it locally.

        return defaultTimeZone;
    
public static java.lang.reflect.FieldgetField(java.lang.Class javaClass, java.lang.String fieldName)
INTERNAL: Returns a Field for the specified Class and field name. Uses Class.getDeclaredField(String) to find the field. If the field is not found on the specified class the superclass is checked, and so on, recursively. Set accessible to true, so we can access private/package/protected fields.

        if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
            try {
                return (Field)AccessController.doPrivileged(new PrivilegedGetField(javaClass, fieldName, true));
            } catch (PrivilegedActionException exception) {
                throw (NoSuchFieldException)exception.getException();
            }
        } else {
            return PrivilegedAccessHelper.getField(javaClass, fieldName, true);
        }
    
public static java.lang.ObjectgetInstanceFromClass(java.lang.Class classFullName)
Return the class instance from the class

        if (classFullName == null) {
            return null;
        }

        try {
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    return AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(classFullName));
                } catch (PrivilegedActionException exception) {
                    Exception throwableException = exception.getException();
                    if (throwableException instanceof InstantiationException) {
                        ValidationException exc = new ValidationException();
                        exc.setInternalException(throwableException);
                        throw exc;
                    } else {
                        ValidationException exc = new ValidationException();
                        exc.setInternalException(throwableException);
                        throw exc;
                    }
                }
            } else {
                return PrivilegedAccessHelper.newInstanceFromClass(classFullName);
            }
        } catch (InstantiationException notInstantiatedException) {
            ValidationException exception = new ValidationException();
            exception.setInternalException(notInstantiatedException);
            throw exception;
        } catch (IllegalAccessException notAccessedException) {
            ValidationException exception = new ValidationException();
            exception.setInternalException(notAccessedException);
            throw exception;
        }
    
public static java.lang.ObjectgetNullWrapper()
Used to store null values in hashtables, is helper because need to be serializable.

        return nullWrapper;
    
public static java.lang.ClassgetObjectClass(java.lang.Class javaClass)
Returns the object class. If a class is primitive return its non primitive class

        return ConversionManager.getObjectClass(javaClass);
    
public static java.lang.StringgetPackageName(java.lang.Class javaClass)
return a package name for the specified class.

        String className = Helper.getShortClassName(javaClass);
        return javaClass.getName().substring(0, (javaClass.getName().length() - (className.length() + 1)));
    
public static java.lang.StringgetShortClassName(java.lang.Class javaClass)
Answers the unqualified class name for the provided class.

        return getShortClassName(javaClass.getName());
    
public static java.lang.StringgetShortClassName(java.lang.String javaClassName)
Answers the unqualified class name from the specified String.

        return javaClassName.substring(javaClassName.lastIndexOf('.") + 1);
    
public static java.lang.StringgetShortClassName(java.lang.Object object)
Answers the unqualified class name for the specified object.

        return getShortClassName(object.getClass());
    
public static java.lang.StringgetTabs(int noOfTabs)
Return a string containing the specified number of tabs.

        StringWriter writer = new StringWriter();
        for (int index = 0; index < noOfTabs; index++) {
            writer.write("\t");
        }
        return writer.toString();
    
public static intindexOfNullElement(java.util.Vector v, int index)
Returns the index of the the first null element found in the specified Vector starting the search at the starting index specified. Return an int >= 0 and less than size if a null element was found. Return -1 if a null element was not found. This is needed in jdk1.1, where Vector.contains(Object) for a null element will result in a NullPointerException....

        for (int i = index; i < v.size(); i++) {
            if (v.elementAt(i) == null) {
                return i;
            }
        }
        return -1;
    
public static booleanisCollection(java.lang.Object testObject)
Return true if the object implements the Collection interface Creation date: (9/7/00 1:59:51 PM)

return
boolean
param
testObject java.lang.Object

        // Does it implement the Collection interface
        if (testObject instanceof Collection) {
            return true;
        }

        // It's not a collection
        return false;
    
public static booleanisPrimitiveWrapper(java.lang.Class classInQuestion)
ADVANCED returns true if the class in question is a primitive wrapper

        return classInQuestion.equals(Character.class) || classInQuestion.equals(Boolean.class) || classInQuestion.equals(Byte.class) || classInQuestion.equals(Short.class) || classInQuestion.equals(Integer.class) || classInQuestion.equals(Long.class) || classInQuestion.equals(Float.class) || classInQuestion.equals(Double.class);
    
public static booleanisUpperCaseString(java.lang.String s)
Returns true if the string given is an all upper case string

        char[] c = s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            if (Character.isLowerCase(c[i])) {
                return false;
            }
        }
        return true;
    
public static booleanisVowel(char c)
Returns true if the character given is a vowel. I.e. one of a,e,i,o,u,A,E,I,O,U.

        return (c == 'A") || (c == 'a") || (c == 'e") || (c == 'E") || (c == 'i") || (c == 'I") || (c == 'o") || (c == 'O") || (c == 'u") || (c == 'U");
    
public static java.io.File[]listFilesIn(java.io.File directory)
Return an array of the files in the specified directory. This allows us to simplify jdk1.1 code a bit.

        if (directory.isDirectory()) {
            return directory.listFiles();
        } else {
            return new File[0];
        }
    
public static java.util.VectormakeVectorFromObject(java.lang.Object theObject)
Make a Vector from the passed object. If it's a Collection, iterate over the collection and add each item to the Vector. If it's not a collection create a Vector and add the object to it.

        if (theObject instanceof Vector) {
            return ((Vector)theObject);
        }
        if (theObject instanceof Collection) {
            Vector returnVector = new Vector(((Collection)theObject).size());
            Iterator iterator = ((Collection)theObject).iterator();
            while (iterator.hasNext()) {
                returnVector.add(iterator.next());
            }
            return returnVector;
        }

        Vector returnVector = new Vector();
        returnVector.addElement(theObject);
        return returnVector;
    
public static java.lang.StringpathSeparator()
Return a string containing the platform-appropriate characters for separating entries in a path (e.g. the classpath)

        // Bug 2756643
        if (PATH_SEPARATOR == null) {
            PATH_SEPARATOR = System.getProperty("path.separator");
        }
        return PATH_SEPARATOR;
    
public static java.lang.StringprintCalendar(java.util.Calendar calendar)
Print the Calendar.

        return printCalendar(calendar, true);
    
public static java.lang.StringprintCalendar(java.util.Calendar calendar, boolean useLocalTime)
Print the Calendar. Normally the calendar must be printed in the local time, but if the timezone is printed, it must be printing in its timezone.

        String millisString;

        //	String zeros = "000000000";
        if (calendar.get(Calendar.MILLISECOND) == 0) {
            millisString = "0";
        } else {
            millisString = buildZeroPrefixAndTruncTrailZeros(calendar.get(Calendar.MILLISECOND), 3);
        }

        StringBuffer timestampBuf = new StringBuffer();
        timestampBuf.append(printDate(calendar, useLocalTime));
        timestampBuf.append(" ");
        timestampBuf.append(printTime(calendar, useLocalTime));
        timestampBuf.append(".");
        timestampBuf.append(millisString);

        return timestampBuf.toString();
    
public static java.lang.StringprintCalendarWithoutNanos(java.util.Calendar calendar)
Print the Calendar without the nanos portion.

        StringBuffer timestampBuf = new StringBuffer();
        timestampBuf.append(printDate(calendar));
        timestampBuf.append(" ");
        timestampBuf.append(printTime(calendar));
        return timestampBuf.toString();
    
public static java.lang.StringprintDate(java.sql.Date date)
Print the sql.Date.

        // PERF: Avoid deprecated get methods, that are now very inefficient and used from toString.
        Calendar calendar = allocateCalendar();
        calendar.setTime(date);
        String string = printDate(calendar);
        releaseCalendar(calendar);
        return string;
    
public static java.lang.StringprintDate(java.util.Calendar calendar)
Print the date part of the calendar.

        return printDate(calendar, true);
    
public static java.lang.StringprintDate(java.util.Calendar calendar, boolean useLocalTime)
Print the date part of the calendar. Normally the calendar must be printed in the local time, but if the timezone is printed, it must be printing in its timezone.

        int year;
        int month;
        int day;
        if (useLocalTime && (!defaultTimeZone.equals(calendar.getTimeZone()))) {
            // Must convert the calendar to the local timezone if different, as dates have no timezone (always local).
            Calendar localCalendar = allocateCalendar();
            JavaPlatform.setTimeInMillis(localCalendar, JavaPlatform.getTimeInMillis(calendar));
            year = localCalendar.get(Calendar.YEAR);
            month = localCalendar.get(Calendar.MONTH) + 1;
            day = localCalendar.get(Calendar.DATE);
            releaseCalendar(localCalendar);
        } else {
            year = calendar.get(Calendar.YEAR);
            month = calendar.get(Calendar.MONTH) + 1;
            day = calendar.get(Calendar.DATE);
        }

        char[] buf = "2000-00-00".toCharArray();
        buf[0] = Character.forDigit(year / 1000, 10);
        buf[1] = Character.forDigit((year / 100) % 10, 10);
        buf[2] = Character.forDigit((year / 10) % 10, 10);
        buf[3] = Character.forDigit(year % 10, 10);
        buf[5] = Character.forDigit(month / 10, 10);
        buf[6] = Character.forDigit(month % 10, 10);
        buf[8] = Character.forDigit(day / 10, 10);
        buf[9] = Character.forDigit(day % 10, 10);

        return new String(buf);
    
public static java.lang.StringprintStackTraceToString(java.lang.Throwable aThrowable)
Return a String containing the printed stacktrace of an exception.

        StringWriter swriter = new StringWriter();
        PrintWriter writer = new PrintWriter(swriter, true);
        aThrowable.printStackTrace(writer);
        writer.close();
        return swriter.toString();
    
public static java.lang.StringprintTime(java.sql.Time time)
Print the sql.Time.

        // PERF: Avoid deprecated get methods, that are now very inefficient and used from toString.
        Calendar calendar = allocateCalendar();
        calendar.setTime(time);
        String string = printTime(calendar);
        releaseCalendar(calendar);
        return string;
    
public static java.lang.StringprintTime(java.util.Calendar calendar)
Print the time part of the calendar.

        return printTime(calendar, true);
    
public static java.lang.StringprintTime(java.util.Calendar calendar, boolean useLocalTime)
Print the time part of the calendar. Normally the calendar must be printed in the local time, but if the timezone is printed, it must be printing in its timezone.

        int hour;
        int minute;
        int second;
        if (useLocalTime && (!defaultTimeZone.equals(calendar.getTimeZone()))) {
            // Must convert the calendar to the local timezone if different, as dates have no timezone (always local).
            Calendar localCalendar = allocateCalendar();
            JavaPlatform.setTimeInMillis(localCalendar, JavaPlatform.getTimeInMillis(calendar));
            hour = localCalendar.get(Calendar.HOUR_OF_DAY);
            minute = localCalendar.get(Calendar.MINUTE);
            second = localCalendar.get(Calendar.SECOND);
            releaseCalendar(localCalendar);
        } else {
            hour = calendar.get(Calendar.HOUR_OF_DAY);
            minute = calendar.get(Calendar.MINUTE);
            second = calendar.get(Calendar.SECOND);
        }
        String hourString;
        String minuteString;
        String secondString;
        if (hour < 10) {
            hourString = "0" + hour;
        } else {
            hourString = Integer.toString(hour);
        }
        if (minute < 10) {
            minuteString = "0" + minute;
        } else {
            minuteString = Integer.toString(minute);
        }
        if (second < 10) {
            secondString = "0" + second;
        } else {
            secondString = Integer.toString(second);
        }
        return (hourString + ":" + minuteString + ":" + secondString);
    
public static java.lang.StringprintTimeFromMilliseconds(long milliseconds)

        if ((milliseconds > 1000) && (milliseconds < 60000)) {
            return (milliseconds / 1000) + "s";
        }
        if (milliseconds > 60000) {
            return (milliseconds / 60000) + "min " + printTimeFromMilliseconds(milliseconds % 60000);
        }
        return milliseconds + "ms";
    
public static java.lang.StringprintTimestamp(java.sql.Timestamp timestamp)
Print the sql.Timestamp.

        // PERF: Avoid deprecated get methods, that are now very inefficient and used from toString.
        Calendar calendar = allocateCalendar();
        calendar.setTime(timestamp);

        String nanosString;

        //	String zeros = "000000000";
        String yearZeros = "0000";

        if (timestamp.getNanos() == 0) {
            nanosString = "0";
        } else {
            nanosString = buildZeroPrefixAndTruncTrailZeros(timestamp.getNanos(), 9);
        }

        StringBuffer timestampBuf = new StringBuffer();
        timestampBuf.append(printDate(calendar));
        timestampBuf.append(" ");
        timestampBuf.append(printTime(calendar));
        timestampBuf.append(".");
        timestampBuf.append(nanosString);

        releaseCalendar(calendar);

        return (timestampBuf.toString());
    
public static java.lang.StringprintTimestampWithoutNanos(java.sql.Timestamp timestamp)
Print the sql.Timestamp without the nanos portion.

        // PERF: Avoid deprecated get methods, that are now very inefficient and used from toString.
        Calendar calendar = allocateCalendar();
        calendar.setTime(timestamp);
        String string = printCalendarWithoutNanos(calendar);
        releaseCalendar(calendar);
        return string;
    
public static java.lang.StringprintVector(java.util.Vector vector)
Given a Vector, print it, even if there is a null in it

        StringWriter stringWriter = new StringWriter();
        stringWriter.write("[");
        Enumeration enumtr = vector.elements();
        stringWriter.write(String.valueOf(enumtr.nextElement()));
        while (enumtr.hasMoreElements()) {
            stringWriter.write(" ");
            stringWriter.write(String.valueOf(enumtr.nextElement()));
        }
        stringWriter.write("]");
        return stringWriter.toString();

    
public static java.util.HashtablerehashHashtable(java.util.Hashtable table)

        Hashtable rehashedTable = new Hashtable(table.size() + 2);

        Enumeration values = table.elements();
        for (Enumeration keys = table.keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = values.nextElement();
            rehashedTable.put(key, value);
        }

        return rehashedTable;
    
public static java.util.MaprehashMap(java.util.Map table)

        HashMap rehashedTable = new HashMap(table.size() + 2);

        Iterator values = table.values().iterator();
        for (Iterator keys = table.keySet().iterator(); keys.hasNext();) {
            Object key = keys.next();
            Object value = values.next();
            rehashedTable.put(key, value);
        }

        return rehashedTable;
    
public static voidreleaseCalendar(java.util.Calendar calendar)
PERF: This is used to optimize Calendar conversion/printing. This should only be used when a calendar is temporarily required, when finished it must be released back.

        if (calendarCache.size() < 10) {
            calendarCache.add(calendar);
        }
    
public static java.lang.StringremoveAllButAlphaNumericToFit(java.lang.String s1, int maximumStringLength)
Returns a String which has had enough non-alphanumeric characters removed to be equal to the maximumStringLength.

        int s1Size = s1.length();
        if (s1Size <= maximumStringLength) {
            return s1;
        }

        // Remove the necessary number of characters	
        StringBuffer buf = new StringBuffer();
        int numberOfCharsToBeRemoved = s1.length() - maximumStringLength;
        int s1Index = 0;
        while ((numberOfCharsToBeRemoved > 0) && (s1Index < s1Size)) {
            char currentChar = s1.charAt(s1Index);
            if (Character.isLetterOrDigit(currentChar)) {
                buf.append(currentChar);
            } else {
                numberOfCharsToBeRemoved--;
            }
            s1Index++;
        }

        // Append the rest of the character that were not parsed through.
        // Is it quicker to build a substring and append that?
        while (s1Index < s1Size) {
            buf.append(s1.charAt(s1Index));
            s1Index++;
        }

        //
        return buf.toString();
    
public static java.lang.StringremoveCharacterToFit(java.lang.String s1, char aChar, int maximumStringLength)
Returns a String which has had enough of the specified character removed to be equal to the maximumStringLength.

        int s1Size = s1.length();
        if (s1Size <= maximumStringLength) {
            return s1;
        }

        // Remove the necessary number of characters	
        StringBuffer buf = new StringBuffer();
        int numberOfCharsToBeRemoved = s1.length() - maximumStringLength;
        int s1Index = 0;
        while ((numberOfCharsToBeRemoved > 0) && (s1Index < s1Size)) {
            char currentChar = s1.charAt(s1Index);
            if (currentChar == aChar) {
                numberOfCharsToBeRemoved--;
            } else {
                buf.append(currentChar);
            }
            s1Index++;
        }

        // Append the rest of the character that were not parsed through.
        // Is it quicker to build a substring and append that?
        while (s1Index < s1Size) {
            buf.append(s1.charAt(s1Index));
            s1Index++;
        }

        //
        return buf.toString();
    
public static booleanremoveNullElement(java.util.Vector v)
Remove the first null element found in the specified Vector. Return true if a null element was found and removed. Return false if a null element was not found. This is needed in jdk1.1, where Vector.removeElement(Object) for a null element will result in a NullPointerException....

        int indexOfNull = indexOfNullElement(v, 0);
        if (indexOfNull != -1) {
            v.removeElementAt(indexOfNull);
            return true;
        }
        return false;
    
public static java.lang.StringremoveVowels(java.lang.String s1)
Returns a String which has had enough of the specified character removed to be equal to the maximumStringLength.

        // Remove the vowels
        StringBuffer buf = new StringBuffer();
        int s1Size = s1.length();
        int s1Index = 0;
        while (s1Index < s1Size) {
            char currentChar = s1.charAt(s1Index);
            if (!isVowel(currentChar)) {
                buf.append(currentChar);
            }
            s1Index++;
        }

        //
        return buf.toString();
    
public static java.lang.StringreplaceFirstSubString(java.lang.String source, java.lang.String subString, java.lang.String replacement)
Replaces the first subString of the source with the replacement.

        int index = source.indexOf(subString);

        if (index >= 0) {
            return source.substring(0, index) + replacement + source.substring(index + subString.length());
        }
        return null;
    
public static java.util.VectorreverseVector(java.util.Vector theVector)

        Vector tempVector = new Vector(theVector.size());
        Object currentElement;

        for (int i = theVector.size() - 1; i > -1; i--) {
            currentElement = theVector.elementAt(i);
            tempVector.addElement(currentElement);
        }

        return tempVector;
    
public static java.lang.StringrightTrimString(java.lang.String originalString)
Returns a new string with all space characters removed from the right

param
originalString - timestamp representation of date
return
- String

        int len = originalString.length();
        while ((len > 0) && (originalString.charAt(len - 1) <= ' ")) {
            len--;
        }
        return originalString.substring(0, len);
    
public static voidsetShouldOptimizeDates(boolean value)
Return if JDBC date access should be optimized.

        shouldOptimizeDates = value;
    
public static java.lang.StringshortenStringsByRemovingVowelsToFit(java.lang.String s1, java.lang.String s2, int maximumStringLength)
Returns a String which is a concatenation of two string which have had enough vowels removed from them so that the sum of the sized of the two strings is less than or equal to the specified size.

        int size = s1.length() + s2.length();
        if (size <= maximumStringLength) {
            return s1 + s2;
        }

        // Remove the necessary number of characters
        int s1Size = s1.length();
        int s2Size = s2.length();
        StringBuffer buf1 = new StringBuffer();
        StringBuffer buf2 = new StringBuffer();
        int numberOfCharsToBeRemoved = size - maximumStringLength;
        int s1Index = 0;
        int s2Index = 0;
        int modulo2 = 0;

        // While we still want to remove characters, and not both string are done.
        while ((numberOfCharsToBeRemoved > 0) && !((s1Index >= s1Size) && (s2Index >= s2Size))) {
            if ((modulo2 % 2) == 0) {
                // Remove from s1
                if (s1Index < s1Size) {
                    if (isVowel(s1.charAt(s1Index))) {
                        numberOfCharsToBeRemoved--;
                    } else {
                        buf1.append(s1.charAt(s1Index));
                    }
                    s1Index++;
                }
            } else {
                // Remove from s2
                if (s2Index < s2Size) {
                    if (isVowel(s2.charAt(s2Index))) {
                        numberOfCharsToBeRemoved--;
                    } else {
                        buf2.append(s2.charAt(s2Index));
                    }
                    s2Index++;
                }
            }
            modulo2++;
        }

        // Append the rest of the character that were not parsed through.
        // Is it quicker to build a substring and append that?
        while (s1Index < s1Size) {
            buf1.append(s1.charAt(s1Index));
            s1Index++;
        }
        while (s2Index < s2Size) {
            buf2.append(s2.charAt(s2Index));
            s2Index++;
        }

        //
        return buf1.toString() + buf2.toString();
    
public static booleanshouldOptimizeDates()
Return if JDBC date access should be optimized.


                 
        
        return shouldOptimizeDates;
    
public static java.sql.DatesqlDateFromUtilDate(java.util.Date utilDate)
Answer a sql.Date from a timestamp.

        // PERF: Avoid deprecated get methods, that are now very inefficient.
        Calendar calendar = allocateCalendar();
        calendar.setTime(utilDate);
        java.sql.Date date = dateFromCalendar(calendar);
        releaseCalendar(calendar);
        return date;
    
public static voidsystemBug(java.lang.String description)
Can be used to mark code if a workaround is added for a JDBC driver or other bug.

        // Use sender to find what is needy.
    
public static java.lang.StringtempDirectory()
Return the name of the "temporary directory".

        // Bug 2756643
        if (TEMP_DIRECTORY == null) {
            TEMP_DIRECTORY = System.getProperty("java.io.tmpdir");
        }
        return TEMP_DIRECTORY;
    
public static java.sql.TimetimeFromCalendar(java.util.Calendar calendar)
Answer a sql.Time from a Calendar.

        if (!defaultTimeZone.equals(calendar.getTimeZone())) {
            // Must convert the calendar to the local timezone if different, as dates have no timezone (always local).
            Calendar localCalendar = allocateCalendar();
            JavaPlatform.setTimeInMillis(localCalendar, JavaPlatform.getTimeInMillis(calendar));
            java.sql.Time date = timeFromHourMinuteSecond(localCalendar.get(Calendar.HOUR_OF_DAY), localCalendar.get(Calendar.MINUTE), localCalendar.get(Calendar.SECOND));
            releaseCalendar(localCalendar);
            return date;
        }
        return timeFromHourMinuteSecond(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
    
public static java.sql.TimetimeFromDate(java.util.Date date)
Answer a Time from a Date This implementation is based on the java.sql.Date class, not java.util.Date.

param
timestampObject - time representation of date
return
- time representation of dateObject

        // PERF: Avoid deprecated get methods, that are now very inefficient.
        Calendar calendar = allocateCalendar();
        calendar.setTime(date);
        java.sql.Time time = timeFromCalendar(calendar);
        releaseCalendar(calendar);
        return time;
    
public static java.sql.TimetimeFromHourMinuteSecond(int hour, int minute, int second)
Answer a Time with the hour, minute, second. This builds a time avoiding the deprecated, inefficient and concurrency bottleneck date constructors. The hour, minute, second are the values calendar uses, i.e. year is from 0, month is 0-11, date is 1-31.

        // Use a calendar to compute the correct millis for the date.
        Calendar localCalendar = allocateCalendar();
        localCalendar.clear();
        localCalendar.set(1970, 0, 1, hour, minute, second);
        long millis = JavaPlatform.getTimeInMillis(localCalendar);
        java.sql.Time time = new java.sql.Time(millis);
        releaseCalendar(localCalendar);
        return time;
    
public static java.sql.TimetimeFromLong(java.lang.Long longObject)
Answer a Time from a long

param
longObject - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

        return new java.sql.Time(longObject.longValue());
    
public static java.sql.TimetimeFromString(java.lang.String timeString)
Answer a Time from a string representation. This method will accept times in the following formats: HH-MM-SS, HH:MM:SS

param
timeString - string representation of time
return
- time representation of string

        int hour;
        int minute;
        int second;
        String timePortion = timeString;

        if (timeString.length() > 12) {
            // Longer strings are Timestamp format (ie. Sybase & Oracle)
            timePortion = timeString.substring(11, 19);
        }

        if ((timePortion.indexOf('-") == -1) && (timePortion.indexOf('/") == -1) && (timePortion.indexOf('.") == -1) && (timePortion.indexOf(':") == -1)) {
            throw ConversionException.incorrectTimeFormat(timePortion);
        }
        StringTokenizer timeStringTokenizer = new StringTokenizer(timePortion, " /:.-");

        try {
            hour = Integer.parseInt(timeStringTokenizer.nextToken());
            minute = Integer.parseInt(timeStringTokenizer.nextToken());
            second = Integer.parseInt(timeStringTokenizer.nextToken());
        } catch (NumberFormatException exception) {
            throw ConversionException.incorrectTimeFormat(timeString);
        }

        return timeFromHourMinuteSecond(hour, minute, second);
    
public static java.sql.TimetimeFromTimestamp(java.sql.Timestamp timestamp)
Answer a Time from a Timestamp Usus the Hours, Minutes, Seconds instead of getTime() ms value.

        return timeFromDate(timestamp);
    
public static java.sql.TimestamptimestampFromCalendar(java.util.Calendar calendar)
Answer a Timestamp from a Calendar.

        return timestampFromLong(JavaPlatform.getTimeInMillis(calendar));
    
public static java.sql.TimestamptimestampFromDate(java.util.Date date)
Answer a Timestamp from a java.util.Date.

        return timestampFromLong(date.getTime());
    
public static java.sql.TimestamptimestampFromLong(long millis)
Answer a Time from a long

param
longObject - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

        java.sql.Timestamp timestamp = new java.sql.Timestamp(millis);

        // P2.0.1.3: Didn't account for negative millis < 1970
        // Must account for the jdk millis bug where it does not set the nanos.
        if ((millis % 1000) > 0) {
            timestamp.setNanos((int)(millis % 1000) * 1000000);
        } else if ((millis % 1000) < 0) {
            timestamp.setNanos((int)(1000000000 - (Math.abs((millis % 1000) * 1000000))));
        }
        return timestamp;
    
public static java.sql.TimestamptimestampFromLong(java.lang.Long millis)
Answer a Time from a long

param
longObject - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

        return timestampFromLong(millis.longValue());
    
public static java.sql.TimestamptimestampFromString(java.lang.String timestampString)
Answer a Timestamp from a string representation. This method will accept strings in the following formats: YYYY/MM/DD HH:MM:SS, YY/MM/DD HH:MM:SS, YYYY-MM-DD HH:MM:SS, YY-MM-DD HH:MM:SS

param
timestampString - string representation of timestamp
return
- timestamp representation of string

        if ((timestampString.indexOf('-") == -1) && (timestampString.indexOf('/") == -1) && (timestampString.indexOf('.") == -1) && (timestampString.indexOf(':") == -1)) {
            throw ConversionException.incorrectTimestampFormat(timestampString);
        }
        StringTokenizer timestampStringTokenizer = new StringTokenizer(timestampString, " /:.-");

        int year;
        int month;
        int day;
        int hour;
        int minute;
        int second;
        int nanos;
        try {
            year = Integer.parseInt(timestampStringTokenizer.nextToken());
            month = Integer.parseInt(timestampStringTokenizer.nextToken());
            day = Integer.parseInt(timestampStringTokenizer.nextToken());
            try {
                hour = Integer.parseInt(timestampStringTokenizer.nextToken());
                minute = Integer.parseInt(timestampStringTokenizer.nextToken());
                second = Integer.parseInt(timestampStringTokenizer.nextToken());
            } catch (java.util.NoSuchElementException endOfStringException) {
                // May be only a date string desired to be used as a timestamp.
                hour = 0;
                minute = 0;
                second = 0;
            }
        } catch (NumberFormatException exception) {
            throw ConversionException.incorrectTimestampFormat(timestampString);
        }

        try {
            String nanoToken = timestampStringTokenizer.nextToken();
            nanos = Integer.parseInt(nanoToken);
            for (int times = 0; times < (9 - nanoToken.length()); times++) {
                nanos = nanos * 10;
            }
        } catch (java.util.NoSuchElementException endOfStringException) {
            nanos = 0;
        } catch (NumberFormatException exception) {
            throw ConversionException.incorrectTimestampFormat(timestampString);
        }

        // Java dates are based on year after 1900 so I need to delete it.
        year = year - 1900;

        // Java returns the month in terms of 0 - 11 instead of 1 - 12. 
        month = month - 1;

        java.sql.Timestamp timestamp;
        // This was not converted to use Calendar for the conversion because calendars do not take nanos.
        // but it should be, and then just call setNanos.
        timestamp = new java.sql.Timestamp(year, month, day, hour, minute, second, nanos);
        return timestamp;
    
public static java.sql.TimestamptimestampFromYearMonthDateHourMinuteSecondNanos(int year, int month, int date, int hour, int minute, int second, int nanos)
Answer a Timestamp with the year, month, day, hour, minute, second. The hour, minute, second are the values calendar uses, i.e. year is from 0, month is 0-11, date is 1-31, time is 0-23/59.

        // This was not converted to use Calendar for the conversion because calendars do not take nanos.
        // but it should be, and then just call setNanos.
        return new java.sql.Timestamp(year - 1900, month, date, hour, minute, second, nanos);
    
public static voidtoDo(java.lang.String description)
Can be used to mark code as need if something strange is seen.

        // Use sender to find what is needy.
    
public static java.lang.Stringtruncate(java.lang.String originalString, int size)
If the size of the original string is larger than the passed in size, this method will remove the vowels from the original string. The removal starts backward from the end of original string, and stops if the resulting string size is equal to the passed in size. If the resulting string is still larger than the passed in size after removing all vowels, the end of the resulting string will be truncated.

        if (originalString.length() <= size) {
            //no removal and truncation needed
            return originalString;
        }
        String vowels = "AaEeIiOoUu";
        StringBuffer newStringBufferTmp = new StringBuffer(originalString.length());

        //need to remove the extra characters
        int counter = originalString.length() - size;
        for (int index = (originalString.length() - 1); index >= 0; index--) {
            //search from the back to the front, if vowel found, do not append it to the resulting (temp) string! 
            //i.e. if vowel not found, append the chararcter to the new string buffer.
            if (vowels.indexOf(originalString.charAt(index)) == -1) {
                newStringBufferTmp.append(originalString.charAt(index));
            } else {
                //vowel found! do NOT append it to the temp buffer, and decrease the counter
                counter--;
                if (counter == 0) {
                    //if the exceeded characters (counter) of vowel haven been removed, the total 
                    //string size should be equal to the limits, so append the reversed remaining string
                    //to the new string, break the loop and return the shrunk string.
                    StringBuffer newStringBuffer = new StringBuffer(size);
                    newStringBuffer.append(originalString.substring(0, index));
                    //need to reverse the string
                    //bug fix: 3016423. append(BunfferString) is jdk1.4 version api. Use append(String) instead
                    //in order to support jdk1.3.
                    newStringBuffer.append(newStringBufferTmp.reverse().toString());
                    return newStringBuffer.toString();
                }
            }
        }

        //the shrunk string still too long, revrese the order back and truncate it!
        return newStringBufferTmp.reverse().toString().substring(0, size);
    
public static java.util.DateutilDateFromLong(java.lang.Long longObject)
Answer a Date from a long This implementation is based on the java.sql.Date class, not java.util.Date.

param
longObject - milliseconds from the epoch (00:00:00 GMT Jan 1, 1970). Negative values represent dates prior to the epoch.

        return new java.util.Date(longObject.longValue());
    
public static java.util.DateutilDateFromSQLDate(java.sql.Date sqlDate)
Answer a java.util.Date from a sql.date

param
sqlDate - sql.date representation of date
return
- java.util.Date representation of the sql.date

        return new java.util.Date(sqlDate.getTime());
    
public static java.util.DateutilDateFromTime(java.sql.Time time)
Answer a java.util.Date from a sql.Time

param
time - time representation of util date
return
- java.util.Date representation of the time

        return new java.util.Date(time.getTime());
    
public static java.util.DateutilDateFromTimestamp(java.sql.Timestamp timestampObject)
Answer a java.util.Date from a timestamp

param
timestampObject - timestamp representation of date
return
- java.util.Date representation of timestampObject

        // Bug 2719624 - Conditionally remove workaround for java bug which truncated
        // nanoseconds from timestamp.getTime().  We will now only recalculate the nanoseconds
        // When timestamp.getTime() results in nanoseconds == 0;
        long time = timestampObject.getTime();
        boolean appendNanos = ((time % 1000) == 0);
        if (appendNanos) {
            return new java.util.Date(time + (timestampObject.getNanos() / 1000000));
        } else {
            return new java.util.Date(time);
        }
    
public static java.util.VectorvectorFromArray(java.lang.Object[] array)
Convert the specified array into a vector.

        Vector result = new Vector(array.length);
        for (int i = 0; i < array.length; i++) {
            result.addElement(array[i]);
        }
        return result;
    
public static voidwriteHexString(byte[] bytes, java.io.Writer writer)
Convert the byte array to a HEX string. HEX allows for binary data to be printed.

        writer.write(buildHexStringFromBytes(bytes));