Class Util

java.lang.Object
connector.common.Util

public class Util extends Object
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • uuid

      public static String uuid()
    • partition

      public static <T> List<List<T>> partition(Collection<T> members, int maxSize)
    • capitalize

      public static String capitalize(String str)
      Capitalize the first character of a string.
    • atoi

      public static int atoi(String a)
      Convert a String value into a primitive integer value.
    • atoi

      public static int atoi(String a, int def)
      Convert a String value into a primitive integer value. If the string is invalid, the value of the "def" argument is returned.
    • otoi

      public static int otoi(Object o)
      Convert an object to a Integer.
    • atol

      public static long atol(String a)
      Convert a string to a long.
    • itoa

      public static String itoa(int i)
      Convert an integer to a string.
    • ltoa

      public static String ltoa(long l)
      Convert a long to a string.
    • ftoa

      public static String ftoa(float f)
      Convert a float to a string.
    • dtoa

      public static String dtoa(double d)
      Convert a double to a string.
    • otob

      public static boolean otob(Object o)
      Convert an object to a boolean.
    • otos

      public static String otos(Object o)
      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

      public static List<String> otol(Object o)
      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 List or 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

      public static Map<String,Object> otom(Object o)
      Convert an object to a Map.
    • otolForNonCSVList

      public static List<String> otolForNonCSVList(Object o)
    • getValueFromMap

      public static Object getValueFromMap(Map map, String name)
    • csvToList

      public static List<String> csvToList(String src)
    • csvToList

      public static List<String> csvToList(String src, String delimiter)
    • escapeMetaCharacters

      public static String escapeMetaCharacters(String inputString)
      Escapes the following metaCharacters String[] metaCharacters = new String[]{"\\", "^", "$", "{", "}", "[", "]", "(", ")", ".", "*", "+", "?", "|", "<", ">", "-", "&", "%"};
    • listToCsv

      public static String listToCsv(List list)
    • listToCsv

      public static String listToCsv(List list, boolean filterEmpty)
    • setToCsv

      public static String setToCsv(Set<?> set)
    • listToQuotedCsv

      public static String listToQuotedCsv(List list, Character quoteChar, boolean filterEmpty)
    • listToQuotedCsv

      public static String listToQuotedCsv(List list, Character quoteChar, boolean filterEmpty, boolean conditionallyQuote)
    • listToQuotedCsv

      public static String listToQuotedCsv(List list, Character quoteChar, boolean filterEmpty, boolean conditionallyQuote, boolean conditionallyAddSpace)
    • size

      public static int size(Collection c)
      Return the size of the given collection.
      Parameters:
      c - The possibly-null collection to get the size of.
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String str)
    • isNotNullOrEmpty

      public static boolean isNotNullOrEmpty(String str)
    • isEmpty

      public static boolean isEmpty(Collection collection)
    • isEmpty

      public static boolean isEmpty(Iterator i)
      Return true if the specified Iterator is empty.
      Parameters:
      i - Iterator being checked
      Returns:
      true of the given Iterator is empty
    • isEmpty

      public static boolean isEmpty(Object[] args)
    • isEmpty

      public static boolean isEmpty(Map map)
    • isEmpty

      public static boolean isEmpty(String src)
    • isNothing

      public static boolean isNothing(String str)
    • isInt

      public static boolean isInt(String str)
    • asList

      public static List asList(Object o)
      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

      public static String getString(String s)
    • getString

      public static String getString(Map map, String name)
    • convertStringToList

      public static List<String> convertStringToList(String value, String delimiter)
    • stringToList

      public static List stringToList(String value)
    • convertStringToSet

      public static Set<String> convertStringToSet(String value, String delimiter)
    • replaceCharacter

      public static String replaceCharacter(String toReplace, String replaceWith, String str)
    • readFile

      public static List<String[]> readFile(String fileNameWithPath, String delimiter, boolean skipHeaderOnFirstLine) throws Exception
      Throws:
      Exception
    • isBooleanOrNumberOrList

      public static boolean isBooleanOrNumberOrList(Object attributeValue)
    • quoteSQLPassword

      public static String quoteSQLPassword(String passwordToQuote)
    • quoteNameSQLObject

      public static String quoteNameSQLObject(String sqlParam)
    • iterate

      public static <T> Iterable<T> iterate(Iterable<T> iterable)
    • safeIterable

      public static <T> Iterable<T> safeIterable(Iterable<T> iterable)
    • stackToString

      public static String stackToString(Throwable th)
    • atob

      public static boolean atob(String a)
      Convert a string to a boolean.
    • listToMap

      public static Map listToMap(List<String> listOfValues)
    • isAnyNullOrEmpty

      public static boolean isAnyNullOrEmpty(String... vals)
    • get

      public static Object get(Map map, String name)
    • getInt

      public static int getInt(Map map, String name)
    • getBoolean

      public static boolean getBoolean(Map map, String name)
    • trimWhitespace

      public static String trimWhitespace(String src)
    • nullSafeCaseInsensitiveEq

      public static boolean nullSafeCaseInsensitiveEq(String o1, String o2)
      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

      public static <T extends Comparable> int nullSafeCompareTo(T o1, T o2)
      Return the compareTo() value for two objects that may be null. Nulls are considered equal, and null is greater than non-null.
    • getHostName

      public static String getHostName()
    • nullSafeEq

      public static boolean nullSafeEq(String s1, String s2, boolean nullsEq)
    • nullSafeEq

      public static boolean nullSafeEq(String s1, String s2)
    • nullSafeContains

      public static boolean nullSafeContains(List list, Object o)
      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

      public static boolean nullSafeEq(Object o1, Object o2)
      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

      public static boolean nullSafeEq(Object o1, Object o2, boolean nullsEq)
      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

      public static boolean nullSafeEq(Object o1, Object o2, boolean nullsEq, boolean emptyStringToNull)
      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

      public static Date getDate(Object o)
    • dateToString

      public static String dateToString(Date src)
    • dateToString

      public static String dateToString(Date src, String format)
    • dateToString

      public static String dateToString(Date src, String format, TimeZone tz)
    • stringToDate

      public static Date stringToDate(String src) throws ParseException
      Throws:
      ParseException
    • computeDifferenceMilli

      public static long computeDifferenceMilli(Date start, Date end) throws Exception
      Throws:
      Exception
    • computeDifference

      public static String computeDifference(Date start, Date end) throws Exception
      Throws:
      Exception
    • isIdentityNow

      public static boolean isIdentityNow()
    • expandVariables

      public static String expandVariables(String src, Map<String,Object> variables)
    • removeDuplicates

      public static <T> void removeDuplicates(List<T> list)
    • filterNulls

      public static <T> List<T> filterNulls(List<T> src)
      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

      public static <T> List<T> arrayToList(T[] array)
      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

      public static String escapeXmlSpecialChar(String inputString)
    • getTimeDiff

      public static long getTimeDiff(Instant start)