public class Helper extends CoreHelper implements Serializable
Purpose: Define any useful methods that are missing from the base Java.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DATABASE_DELIMITER |
static String |
GET_PROPERTY_METHOD_PREFIX |
static String |
INDENT |
static String |
IS_PROPERTY_METHOD_PREFIX |
static boolean |
isZeroValidPrimaryKey
Deprecated.
Instead of setting the flag to true use:
session.getProject().setDefaultIdValidation(IdValidation.NULL)
|
static String |
NL
Store newline string
|
static Object |
NULL_VALUE
Used to store null values in hashtables, is helper because need to be serializable.
|
static String |
PERSISTENCE_FIELDNAME_POSTFIX |
static String |
PERSISTENCE_FIELDNAME_PREFIX |
static String |
PERSISTENCE_GET |
static String |
PERSISTENCE_SET |
static int |
POSITION_AFTER_GET_PREFIX |
static int |
POSITION_AFTER_IS_PREFIX |
static String |
SET_IS_PROPERTY_METHOD_PREFIX |
static String |
SET_PROPERTY_METHOD_PREFIX |
static boolean |
shouldOptimizeDates
Used to configure JDBC level date optimization.
|
static String |
SPACE
formatting strings for indenting
|
Constructor and Description |
---|
Helper() |
Modifier and Type | Method and Description |
---|---|
static void |
addAllToVector(Vector theVector,
Vector elementsToAdd) |
static List |
addAllUniqueToList(List objects,
List objectsToAdd) |
static Vector |
addAllUniqueToVector(Vector objects,
List objectsToAdd) |
static Calendar |
allocateCalendar()
PERF: This is used to optimize Calendar conversion/printing.
|
static boolean |
areTypesAssignable(List types1,
List types2)
PUBLIC:
Compare two vectors of types.
|
static Object[] |
arrayFromVector(Vector vector)
Convert the specified vector into an array.
|
static byte[] |
buildBytesFromHexString(String hex)
Convert the HEX string to a byte array.
|
static String |
buildHexStringFromBytes(byte[] bytes)
Convert the byte array to a HEX string.
|
static Vector |
buildVectorFromMapElements(Map map)
Create a new Vector containing all of the map elements.
|
static String |
buildZeroPrefix(int number,
int totalDigits)
Build a numerical string with leading 0s.
|
static String |
buildZeroPrefixAndTruncTrailZeros(int number,
int totalDigits)
Build a numerical string with leading 0s and truncate trailing zeros.
|
static String |
buildZeroPrefixWithoutSign(int number,
int totalDigits)
Build a numerical string with leading 0s.
|
static Calendar |
calendarFromUtilDate(Date date)
Answer a Calendar from a date.
|
static boolean |
classImplementsInterface(Class aClass,
Class anInterface)
INTERNAL:
Return whether a Class implements a specific interface, either directly or indirectly
(through interface or implementation inheritance).
|
static boolean |
classIsSubclass(Class subClass,
Class superClass)
INTERNAL:
Return whether a Class is a subclass of, or the same as, another Class.
|
static void |
close(Closeable c)
Close a closeable object, eating the exception
|
static boolean |
compareArrays(Object[] array1,
Object[] array2) |
static boolean |
compareBigDecimals(BigDecimal one,
BigDecimal two)
Compare two BigDecimals.
|
static boolean |
compareByteArrays(byte[] array1,
byte[] array2) |
static boolean |
compareCharArrays(char[] array1,
char[] array2) |
static boolean |
compareHashtables(Hashtable hashtable1,
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
|
static boolean |
comparePotentialArrays(Object firstValue,
Object secondValue)
Compare two potential arrays and return true if they are the same.
|
static int |
compareVersions(String version1,
String version2)
INTERNAL:
Compares two version in num.num.num.num.num*** format.
|
static Map |
concatenateMaps(Map first,
Map second)
Merge the two Maps into a new HashMap.
|
static List |
concatenateUniqueLists(List first,
List second)
Return a new List with no duplicated values.
|
static Vector |
concatenateUniqueVectors(Vector first,
Vector second)
Return a new vector with no duplicated values.
|
static Vector |
concatenateVectors(Vector first,
Vector second) |
static String |
convertLikeToRegex(String like)
Convert the SQL like pattern to a regex pattern.
|
static int[] |
copyIntArray(int[] original)
Copy an array of int to a new array
avoids the use of Arrays.copy() because it is not supported in JDK 1.5
|
static String[] |
copyStringArray(String[] original)
Copy an array of strings to a new array
avoids the use of Arrays.copy() because it is not supported in JDK 1.5
|
static Vector |
copyVector(List originalVector,
int startIndex,
int stopIndex)
Return a copy of the vector containing a subset starting at startIndex
and ending at stopIndex.
|
static int |
countOccurrencesOf(Object comparisonObject,
List list)
Return an integer representing the number of occurrences (using equals()) of the
specified object in the specified list.
|
static String |
cr()
Return a string containing the platform-appropriate
characters for carriage return.
|
static String |
currentWorkingDirectory()
Return the name of the "current working directory".
|
static Date |
dateFromCalendar(Calendar calendar)
Answer a sql.Date from a Calendar.
|
static Date |
dateFromLong(Long longObject)
Answer a Date from a long
This implementation is based on the java.sql.Date class, not java.util.Date.
|
static Date |
dateFromString(String dateString)
Answer a Date from a string representation.
|
static Date |
dateFromTimestamp(Timestamp timestamp)
Answer a Date from a timestamp
This implementation is based on the java.sql.Date class, not java.util.Date.
|
static Date |
dateFromYearMonthDate(int year,
int month,
int day)
Answer a Date with the year, month, date.
|
static boolean |
doesFileExist(String fileName)
Returns true if the file of this name does indeed exist
|
static String |
doubleSlashes(String path)
Double up \ to allow printing of directories for source code generation.
|
static String |
extractJarNameFromURL(URL url)
Extracts the actual path to the jar file.
|
static String |
fileSeparator()
Return a string containing the platform-appropriate
characters for separating directory and file names.
|
static String |
getAttributeNameFromMethodName(String methodName)
INTERNAL:
Method to convert a getXyz or isXyz method name to an xyz attribute name.
|
static Queue<Calendar> |
getCalendarCache()
PERF:
Return the calendar cache use to avoid calendar creation for processing java.sql/util.Date/Time/Timestamp objects.
|
static Class |
getClassFromClasseName(String className,
ClassLoader classLoader) |
static String |
getComponentTypeNameFromArrayString(String aString) |
static Method |
getDeclaredMethod(Class javaClass,
String methodName)
INTERNAL:
Returns a Method for the specified Class, method name, and that has no
parameters.
|
static Method |
getDeclaredMethod(Class javaClass,
String methodName,
Class[] methodParameterTypes)
INTERNAL:
Returns a Method for the specified Class, method name, and formal
parameter types.
|
static String |
getDefaultEndDatabaseDelimiter() |
static String |
getDefaultStartDatabaseDelimiter() |
static TimeZone |
getDefaultTimeZone()
PERF: Return the cached default platform.
|
static Field |
getField(Class javaClass,
String fieldName)
INTERNAL:
Returns a Field for the specified Class and field name.
|
static Object |
getInstanceFromClass(Class classFullName)
Return the class instance from the class
|
static Class |
getObjectClass(Class javaClass)
Returns the object class.
|
static String |
getPackageName(Class javaClass)
return a package name for the specified class.
|
static String |
getShortClassName(Class javaClass)
Answers the unqualified class name for the provided class.
|
static String |
getShortClassName(Object object)
Answers the unqualified class name for the specified object.
|
static String |
getShortClassName(String javaClassName)
Answers the unqualified class name from the specified String.
|
static String |
getTabs(int noOfTabs)
Return a string containing the specified number of tabs.
|
static String |
getWeavedGetMethodName(String attributeName)
Return the set method name weaved for getting attribute value.
|
static String |
getWeavedSetMethodName(String attributeName)
Return the set method name weaved for setting attribute value.
|
static String |
getWeavedValueHolderGetMethodName(String attributeName)
Return the get method name weaved for a value-holder attribute.
|
static String |
getWeavedValueHolderSetMethodName(String attributeName)
Return the set method name weaved for a value-holder attribute.
|
static boolean |
hasLob(Collection<DatabaseField> fields) |
static int |
indexOfNullElement(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. |
static Queue |
initCalendarCache()
PERF:
Init the calendar cache use to avoid calendar creation for processing java.sql/util.Date/Time/Timestamp objects.
|
static boolean |
isEquivalentToNull(Object value)
Check if the value is 0 (int/long) for primitive ids.
|
static boolean |
isLob(DatabaseField field) |
static boolean |
isNumberNegativeOrZero(Object value)
Returns true if the passed value is Number that is negative or equals to zero.
|
static boolean |
isPrimitiveWrapper(Class classInQuestion)
ADVANCED
returns true if the class in question is a primitive wrapper
|
static boolean |
isUpperCaseString(String s)
Returns true if the string given is an all upper case string
|
static boolean |
isVowel(char c)
Returns true if the character given is a vowel.
|
static File[] |
listFilesIn(File directory)
Return an array of the files in the specified directory.
|
static Vector |
makeVectorFromObject(Object theObject)
Make a Vector from the passed object.
|
static void |
outputClassFile(String className,
byte[] classBytes,
String outputPath)
Used by our byte code weaving to enable users who are debugging to output
the generated class to a file
|
static String |
pathSeparator()
Return a string containing the platform-appropriate
characters for separating entries in a path (e.g.
|
static String |
printCalendar(Calendar calendar)
Print the Calendar.
|
static String |
printCalendar(Calendar calendar,
boolean useLocalTime)
Print the Calendar.
|
static String |
printCalendarWithoutNanos(Calendar calendar)
Print the Calendar without the nanos portion.
|
static String |
printDate(Calendar calendar)
Print the date part of the calendar.
|
static String |
printDate(Calendar calendar,
boolean useLocalTime)
Print the date part of the calendar.
|
static String |
printDate(Date date)
Print the sql.Date.
|
static String |
printStackTraceToString(Throwable aThrowable)
Return a String containing the printed stacktrace of an exception.
|
static String |
printTime(Calendar calendar)
Print the time part of the calendar.
|
static String |
printTime(Calendar calendar,
boolean useLocalTime)
Print the time part of the calendar.
|
static String |
printTime(Time time)
Print the sql.Time.
|
static String |
printTimeFromMilliseconds(long milliseconds) |
static String |
printTimestamp(Timestamp timestamp)
Print the sql.Timestamp.
|
static String |
printTimestampWithoutNanos(Timestamp timestamp)
Print the sql.Timestamp without the nanos portion.
|
static String |
printVector(Vector vector)
Given a Vector, print it, even if there is a null in it
|
static Hashtable |
rehashHashtable(Hashtable table) |
static Map |
rehashMap(Map table) |
static void |
releaseCalendar(Calendar calendar)
PERF: This is used to optimize Calendar conversion/printing.
|
static String |
removeAllButAlphaNumericToFit(String s1,
int maximumStringLength)
Returns a String which has had enough non-alphanumeric characters removed to be equal to
the maximumStringLength.
|
static String |
removeCharacterToFit(String s1,
char aChar,
int maximumStringLength)
Returns a String which has had enough of the specified character removed to be equal to
the maximumStringLength.
|
static String |
removeVowels(String s1)
Returns a String which has had enough of the specified character removed to be equal to
the maximumStringLength.
|
static String |
replaceFirstSubString(String source,
String subString,
String replacement)
Replaces the first subString of the source with the replacement.
|
static Vector |
reverseVector(Vector theVector) |
static String |
rightTrimString(String originalString)
Returns a new string with all space characters removed from the right
|
static void |
setDefaultEndDatabaseDelimiter(String delimiter) |
static void |
setDefaultStartDatabaseDelimiter(String delimiter) |
static void |
setShouldOptimizeDates(boolean value)
Return if JDBC date access should be optimized.
|
static String |
shortenStringsByRemovingVowelsToFit(String s1,
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.
|
static boolean |
shouldOptimizeDates()
Return if JDBC date access should be optimized.
|
static Date |
sqlDateFromUtilDate(Date utilDate)
Answer a sql.Date from a timestamp.
|
static void |
systemBug(String description)
Can be used to mark code if a workaround is added for a JDBC driver or other bug.
|
static String |
tempDirectory()
Return the name of the "temporary directory".
|
static Time |
timeFromCalendar(Calendar calendar)
Answer a sql.Time from a Calendar.
|
static Time |
timeFromDate(Date date)
Answer a Time from a Date
This implementation is based on the java.sql.Date class, not java.util.Date.
|
static Time |
timeFromHourMinuteSecond(int hour,
int minute,
int second)
Answer a Time with the hour, minute, second.
|
static Time |
timeFromLong(Long longObject)
Answer a Time from a long
|
static Time |
timeFromString(String timeString)
Answer a Time from a string representation.
|
static Time |
timeFromTimestamp(Timestamp timestamp)
Answer a Time from a Timestamp
Usus the Hours, Minutes, Seconds instead of getTime() ms value.
|
static Timestamp |
timestampFromCalendar(Calendar calendar)
Answer a Timestamp from a Calendar.
|
static Timestamp |
timestampFromDate(Date date)
Answer a Timestamp from a java.util.Date.
|
static Timestamp |
timestampFromLong(long millis)
Answer a Time from a long
|
static Timestamp |
timestampFromLong(Long millis)
Answer a Time from a long
|
static Timestamp |
timestampFromString(String timestampString)
Answer a Timestamp from a string representation.
|
static Timestamp |
timestampFromYearMonthDateHourMinuteSecondNanos(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.
|
static void |
toDo(String description)
Can be used to mark code as need if something strange is seen.
|
static String |
toSlashedClassName(String dottedClassName)
Convert dotted format class name to slashed format class name.
|
static URI |
toURI(URL url)
Convert the URL into a URI allowing for special chars.
|
static String |
truncate(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.
|
static Date |
truncateDate(Date date)
Return a sql.Date with time component zeroed out.
|
static Date |
truncateDateIgnoreMilliseconds(Date date)
Return a sql.Date with time component zeroed out (with possible exception of milliseconds).
|
static Date |
utilDateFromLong(Long longObject)
Answer a Date from a long
This implementation is based on the java.sql.Date class, not java.util.Date.
|
static Date |
utilDateFromSQLDate(Date sqlDate)
Answer a java.util.Date from a sql.date
|
static Date |
utilDateFromTime(Time time)
Answer a java.util.Date from a sql.Time
|
static Date |
utilDateFromTimestamp(Timestamp timestampObject)
Answer a java.util.Date from a timestamp
|
static Vector |
vectorFromArray(Object[] array)
Convert the specified array into a vector.
|
static void |
writeHexString(byte[] bytes,
Writer writer)
Convert the byte array to a HEX string.
|
public static boolean shouldOptimizeDates
public static final Object NULL_VALUE
public static String SPACE
public static String INDENT
public static String NL
public static boolean isZeroValidPrimaryKey
public static final String IS_PROPERTY_METHOD_PREFIX
public static final String GET_PROPERTY_METHOD_PREFIX
public static final String SET_PROPERTY_METHOD_PREFIX
public static final String SET_IS_PROPERTY_METHOD_PREFIX
public static final int POSITION_AFTER_IS_PREFIX
public static final int POSITION_AFTER_GET_PREFIX
public static final String DEFAULT_DATABASE_DELIMITER
public static final String PERSISTENCE_SET
public static final String PERSISTENCE_GET
public static final String PERSISTENCE_FIELDNAME_PREFIX
public static final String PERSISTENCE_FIELDNAME_POSTFIX
public static boolean shouldOptimizeDates()
public static void setShouldOptimizeDates(boolean value)
public static Queue<Calendar> getCalendarCache()
public static Queue initCalendarCache()
public static Calendar allocateCalendar()
public static TimeZone getDefaultTimeZone()
public static void releaseCalendar(Calendar calendar)
public static Object[] arrayFromVector(Vector vector)
public static byte[] buildBytesFromHexString(String hex)
public static String buildHexStringFromBytes(byte[] bytes)
public static Vector buildVectorFromMapElements(Map map)
public static Calendar calendarFromUtilDate(Date date)
public static boolean classImplementsInterface(Class aClass, Class anInterface)
public static boolean classIsSubclass(Class subClass, Class superClass)
public static int compareVersions(String version1, String version2)
public static Class getClassFromClasseName(String className, ClassLoader classLoader)
public static String getComponentTypeNameFromArrayString(String aString)
public static boolean compareBigDecimals(BigDecimal one, BigDecimal two)
BigDecimal.equals(Object)
public static boolean compareByteArrays(byte[] array1, byte[] array2)
public static boolean compareCharArrays(char[] array1, char[] array2)
public static boolean areTypesAssignable(List types1, List types2)
public static boolean compareHashtables(Hashtable hashtable1, Hashtable hashtable2)
public static boolean comparePotentialArrays(Object firstValue, Object secondValue)
public static Map concatenateMaps(Map first, Map second)
public static Vector concatenateUniqueVectors(Vector first, Vector second)
public static List concatenateUniqueLists(List first, List second)
public static Vector copyVector(List originalVector, int startIndex, int stopIndex) throws ValidationException
vector
- - original vectorstartIndex
- - starting position in vectorstopIndex
- - ending position in vectorEclipseLinkException
ValidationException
public static String[] copyStringArray(String[] original)
original
- public static int[] copyIntArray(int[] original)
original
- public static String cr()
public static String currentWorkingDirectory()
public static String tempDirectory()
public static Date dateFromLong(Long longObject)
longObject
- - milliseconds from the epoch (00:00:00 GMT
Jan 1, 1970). Negative values represent dates prior to the epoch.public static Date dateFromYearMonthDate(int year, int month, int day)
public static Date dateFromString(String dateString) throws ConversionException
dateString
- - string representation of dateConversionException
public static Date dateFromTimestamp(Timestamp timestamp)
timestampObject
- - timestamp representation of datepublic static boolean doesFileExist(String fileName)
public static String doubleSlashes(String path)
public static String extractJarNameFromURL(URL url)
public static String fileSeparator()
public static Field getField(Class javaClass, String fieldName) throws NoSuchFieldException
NoSuchFieldException
public static Method getDeclaredMethod(Class javaClass, String methodName) throws NoSuchMethodException
NoSuchMethodException
public static Method getDeclaredMethod(Class javaClass, String methodName, Class[] methodParameterTypes) throws NoSuchMethodException
NoSuchMethodException
public static Object getInstanceFromClass(Class classFullName)
public static Class getObjectClass(Class javaClass)
public static String getShortClassName(Class javaClass)
public static String getShortClassName(String javaClassName)
public static String getShortClassName(Object object)
public static String getPackageName(Class javaClass)
public static String getTabs(int noOfTabs)
public static int indexOfNullElement(Vector v, int index)
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
....public static boolean isPrimitiveWrapper(Class classInQuestion)
public static boolean isUpperCaseString(String s)
public static boolean isVowel(char c)
public static File[] listFilesIn(File directory)
public static Vector makeVectorFromObject(Object theObject)
public static void outputClassFile(String className, byte[] classBytes, String outputPath)
className
- classBytes
- outputPath
- public static String pathSeparator()
public static String printStackTraceToString(Throwable aThrowable)
public static String printTimeFromMilliseconds(long milliseconds)
public static String printVector(Vector vector)
public static String removeAllButAlphaNumericToFit(String s1, int maximumStringLength)
public static String removeCharacterToFit(String s1, char aChar, int maximumStringLength)
public static String removeVowels(String s1)
public static String replaceFirstSubString(String source, String subString, String replacement)
public static String rightTrimString(String originalString)
originalString
- - timestamp representation of datepublic static String shortenStringsByRemovingVowelsToFit(String s1, String s2, int maximumStringLength)
public static Date sqlDateFromUtilDate(Date utilDate)
public static String printDate(Calendar calendar, boolean useLocalTime)
public static String printTime(Calendar calendar, boolean useLocalTime)
public static String printCalendar(Calendar calendar, boolean useLocalTime)
public static String buildZeroPrefix(int number, int totalDigits)
public static String buildZeroPrefixWithoutSign(int number, int totalDigits)
public static String buildZeroPrefixAndTruncTrailZeros(int number, int totalDigits)
public static String printTimestampWithoutNanos(Timestamp timestamp)
public static String printCalendarWithoutNanos(Calendar calendar)
public static Date dateFromCalendar(Calendar calendar)
public static Date truncateDate(Date date)
public static Date truncateDateIgnoreMilliseconds(Date date)
public static void systemBug(String description)
public static Time timeFromDate(Date date)
timestampObject
- - time representation of datepublic static Time timeFromLong(Long longObject)
longObject
- - milliseconds from the epoch (00:00:00 GMT
Jan 1, 1970). Negative values represent dates prior to the epoch.public static Time timeFromHourMinuteSecond(int hour, int minute, int second)
public static Time timeFromString(String timeString) throws ConversionException
timeString
- - string representation of timeConversionException
public static Time timeFromTimestamp(Timestamp timestamp)
public static Time timeFromCalendar(Calendar calendar)
public static Timestamp timestampFromCalendar(Calendar calendar)
public static Timestamp timestampFromDate(Date date)
public static Timestamp timestampFromLong(Long millis)
longObject
- - milliseconds from the epoch (00:00:00 GMT
Jan 1, 1970). Negative values represent dates prior to the epoch.public static Timestamp timestampFromLong(long millis)
longObject
- - milliseconds from the epoch (00:00:00 GMT
Jan 1, 1970). Negative values represent dates prior to the epoch.public static Timestamp timestampFromString(String timestampString) throws ConversionException
timestampString
- - string representation of timestampConversionException
public static Timestamp timestampFromYearMonthDateHourMinuteSecondNanos(int year, int month, int date, int hour, int minute, int second, int nanos)
public static void toDo(String description)
public static String toSlashedClassName(String dottedClassName)
dottedClassName
- public static String truncate(String originalString, int size)
public static Date utilDateFromLong(Long longObject)
longObject
- - milliseconds from the epoch (00:00:00 GMT
Jan 1, 1970). Negative values represent dates prior to the epoch.public static Date utilDateFromSQLDate(Date sqlDate)
sqlDate
- - sql.date representation of datepublic static Date utilDateFromTime(Time time)
time
- - time representation of util datepublic static Date utilDateFromTimestamp(Timestamp timestampObject)
timestampObject
- - timestamp representation of datepublic static Vector vectorFromArray(Object[] array)
public static void writeHexString(byte[] bytes, Writer writer) throws IOException
IOException
public static boolean isEquivalentToNull(Object value)
public static boolean isNumberNegativeOrZero(Object value)
public static int countOccurrencesOf(Object comparisonObject, List list)
public static URI toURI(URL url) throws URISyntaxException
URISyntaxException
public static String getWeavedValueHolderGetMethodName(String attributeName)
public static String getWeavedValueHolderSetMethodName(String attributeName)
public static String getWeavedGetMethodName(String attributeName)
public static String getWeavedSetMethodName(String attributeName)
public static void close(Closeable c)
public static String getAttributeNameFromMethodName(String methodName)
public static String getDefaultStartDatabaseDelimiter()
public static String getDefaultEndDatabaseDelimiter()
public static void setDefaultStartDatabaseDelimiter(String delimiter)
public static void setDefaultEndDatabaseDelimiter(String delimiter)
public static String convertLikeToRegex(String like)
public static boolean isLob(DatabaseField field)
public static boolean hasLob(Collection<DatabaseField> fields)
EclipseLink 2.5.2, "build v20140319-9ad6abd" API Reference