Package connector.common
Class Util
java.lang.Object
connector.common.Util
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>arrayToList(T[] array) Given an array, returns a list.static ListReturn a List with the given object.static booleanConvert a string to a boolean.static intConvert a String value into a primitive integer value.static intConvert a String value into a primitive integer value.static longConvert a string to a long.static Stringcapitalize(String str) Capitalize the first character of a string.static StringcomputeDifference(Date start, Date end) static longcomputeDifferenceMilli(Date start, Date end) convertStringToList(String value, String delimiter) convertStringToSet(String value, String delimiter) static StringdateToString(Date src) static StringdateToString(Date src, String format) static StringdateToString(Date src, String format, TimeZone tz) static Stringdtoa(double d) Convert a double to a string.static StringescapeMetaCharacters(String inputString) Escapes the following metaCharacters String[] metaCharacters = new String[]{"\\", "^", "$", "{", "}", "[", "]", "(", ")", ".", "*", "+", "?", "|", "<", ">", "-", "&", "%"};static StringescapeXmlSpecialChar(String inputString) static StringexpandVariables(String src, Map<String, Object> variables) static <T> List<T>filterNulls(List<T> src) Remove nulls from a list.static Stringftoa(float f) Convert a float to a string.static Objectstatic booleangetBoolean(Map map, String name) static Datestatic Stringstatic intgetJarDetails(String jarClass, List<String> attributes) static Stringstatic Stringstatic longgetTimeDiff(Instant start) static ObjectgetValueFromMap(Map map, String name) static booleanisAnyNullOrEmpty(String... vals) static booleanisBooleanOrNumberOrList(Object attributeValue) static booleanisEmpty(int[] args) static booleanstatic booleanstatic booleanisEmpty(Collection collection) static booleanReturn true if the specified Iterator is empty.static booleanstatic booleanstatic booleanstatic booleanstatic booleanisNotNullOrEmpty(String str) static booleanisNullOrEmpty(String str) static <T> Iterable<T>static Stringitoa(int i) Convert an integer to a string.static Stringstatic Stringstatic Mapstatic StringlistToQuotedCsv(List list, Character quoteChar, boolean filterEmpty) static StringlistToQuotedCsv(List list, Character quoteChar, boolean filterEmpty, boolean conditionallyQuote) static StringlistToQuotedCsv(List list, Character quoteChar, boolean filterEmpty, boolean conditionallyQuote, boolean conditionallyAddSpace) static Stringltoa(long l) Convert a long to a string.static booleannullSafeCaseInsensitiveEq(String o1, String o2) This method performs a null-safe equality comparison between the two strings.static <T extends Comparable>
intnullSafeCompareTo(T o1, T o2) Return the compareTo() value for two objects that may be null.static booleannullSafeContains(List list, Object o) Check a list for the given object, checking for null on the list.static booleannullSafeEq(Object o1, Object o2) This method performs a null-safe equality comparison between the two given objects.static booleannullSafeEq(Object o1, Object o2, boolean nullsEq) This method performs a null-safe equality comparison between the two given objects.static booleannullSafeEq(Object o1, Object o2, boolean nullsEq, boolean emptyStringToNull) This method performs a null-safe equality comparison between the two given objects.static booleannullSafeEq(String s1, String s2) static booleannullSafeEq(String s1, String s2, boolean nullsEq) static booleanConvert an object to a boolean.static intConvert an object to a Integer.Convert an object to a List of Strings.Convert an object to a Map.static StringConvert an object to its string representation.partition(Collection<T> members, int maxSize) static StringquoteNameSQLObject(String sqlParam) static StringquoteSQLPassword(String passwordToQuote) static <T> voidremoveDuplicates(List<T> list) static StringreplaceCharacter(String toReplace, String replaceWith, String str) static <T> Iterable<T>safeIterable(Iterable<T> iterable) static Stringstatic intsize(Collection c) Return the size of the given collection.static Stringstatic DatestringToDate(String src) static ListstringToList(String value) static StringtrimWhitespace(String src) static Stringuuid()
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
uuid
-
partition
-
capitalize
Capitalize the first character of a string. -
atoi
Convert a String value into a primitive integer value. -
atoi
Convert a String value into a primitive integer value. If the string is invalid, the value of the "def" argument is returned. -
otoi
Convert an object to a Integer. -
atol
Convert a string to a long. -
itoa
Convert an integer to a string. -
ltoa
Convert a long to a string. -
ftoa
Convert a float to a string. -
dtoa
Convert a double to a string. -
otob
Convert an object to a boolean. -
otos
Convert an object to its string representation. This will convert Lists and Collections to comma-separated lists. Any other object is simply returned as its toString() representation.- Parameters:
o- The object to convert to a string.- Returns:
- The string representation of the given object, or null if the given object is null.
-
otol
Convert an object to a List of Strings. This is useful when contending with arguments that may be coming in as CSVs or as Lists.- Parameters:
o- Either a Listor a CSV list - Returns:
- A new List containing all the elements in the specified object. Note that if the specified object is a List this method returns a new List containing all the elements of the one that was passed in.
-
otom
Convert an object to a Map. -
otolForNonCSVList
-
getValueFromMap
-
csvToList
-
csvToList
-
escapeMetaCharacters
Escapes the following metaCharacters String[] metaCharacters = new String[]{"\\", "^", "$", "{", "}", "[", "]", "(", ")", ".", "*", "+", "?", "|", "<", ">", "-", "&", "%"}; -
listToCsv
-
listToCsv
-
setToCsv
-
listToQuotedCsv
-
listToQuotedCsv
-
listToQuotedCsv
-
size
Return the size of the given collection.- Parameters:
c- The possibly-null collection to get the size of.
-
isNullOrEmpty
-
isNotNullOrEmpty
-
isEmpty
-
isEmpty
Return true if the specified Iterator is empty.- Parameters:
i- Iterator being checked- Returns:
- true of the given Iterator is empty
-
isEmpty
-
isEmpty
-
isEmpty
-
isNothing
-
isInt
-
asList
Return a List with the given object. If the object is a List, it is returned. If the object is a collection, a List with all of the elements of the collection is returned. If the object is a non-collection, a new List containing the given object is returned. If the object is null, null is returned.- Parameters:
o- The object to return as a list.
-
getString
-
getString
-
convertStringToList
-
stringToList
-
convertStringToSet
-
replaceCharacter
-
readFile
public static List<String[]> readFile(String fileNameWithPath, String delimiter, boolean skipHeaderOnFirstLine) throws Exception - Throws:
Exception
-
isBooleanOrNumberOrList
-
quoteSQLPassword
-
quoteNameSQLObject
-
iterate
-
safeIterable
-
stackToString
-
atob
Convert a string to a boolean. -
listToMap
-
isAnyNullOrEmpty
-
get
-
getInt
-
getBoolean
-
trimWhitespace
-
nullSafeCaseInsensitiveEq
This method performs a null-safe equality comparison between the two strings. This will return true if both objects are null and nullsEq is true. Empty or "null" strings will be converted to null before checking if emptyStringToNull is true. -
nullSafeCompareTo
Return the compareTo() value for two objects that may be null. Nulls are considered equal, and null is greater than non-null. -
getHostName
-
nullSafeEq
-
nullSafeEq
-
nullSafeContains
Check a list for the given object, checking for null on the list.- Parameters:
list-o-- Returns:
- true if value is found in the list
-
nullSafeEq
This method performs a null-safe equality comparison between the two given objects. If both objects are null, this returns false.- Parameters:
o1- The first object to compare.o2- The second object to compare.- Returns:
- True if both objects are non-null and equal.
-
nullSafeEq
This method performs a null-safe equality comparison between the two given objects. This will return true if both objects are null and nullsEq is true.- Parameters:
o1- The first object to compare.o2- The second object to compare.nullsEq- Whether two null objects should be considered equal.- Returns:
- True if both objects equal, or both objects are null and nullsEq is true.
-
nullSafeEq
This method performs a null-safe equality comparison between the two given objects. This will return true if both objects are null and nullsEq is true. Empty or "null" strings will be converted to null before checking if emptyStringToNull is true. -
getDate
-
dateToString
-
dateToString
-
dateToString
-
stringToDate
- Throws:
ParseException
-
computeDifferenceMilli
- Throws:
Exception
-
computeDifference
- Throws:
Exception
-
isIdentityNow
public static boolean isIdentityNow() -
expandVariables
-
removeDuplicates
-
filterNulls
Remove nulls from a list. Added as a temporary kludge for some obscure Hibernate crap that adds phantom null's to Lists under some conditions. Do not collapse empty lists to null, some object constructors set the list before they begin populating it. This obviously still has the potental for nulls, but at least Hibernate doesn't appear to follow that pattern. -
getJarDetails
public static Map<String,String> getJarDetails(String jarClass, List<String> attributes) throws Exception - Throws:
Exception
-
arrayToList
Given an array, returns a list.- Parameters:
array- Array to copy to a list- Returns:
- New List, empty list if array is null.
-
isEmpty
public static boolean isEmpty(int[] args) -
escapeXmlSpecialChar
-
getTimeDiff
-