Class GeneralUtilities


  • public class GeneralUtilities
    extends java.lang.Object
    This class contains utilities useful for any code
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      WeakHashClock<K,​V>
      getWeakHashClock​(boolean isWeak)
      Creates a weak hash clock
      static <K> WeakHashLRU<K> getWeakHashLRU​(boolean isWeak)
      Creates a weak hash clock
      private static java.lang.Class<?> loadArrayClass​(java.lang.ClassLoader cl, java.lang.String aName)  
      static java.lang.Class<?> loadClass​(java.lang.ClassLoader cl, java.lang.String cName)
      Loads the class from the given classloader or returns null (does not throw).
      static java.lang.String prettyPrintBytes​(byte[] bytes)
      Pretty prints a string of bytes in a hexadecimal format with byte number at the start of the line
      static boolean safeEquals​(java.lang.Object a, java.lang.Object b)
      Returns true if a is equals to b, or both and and b are null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GeneralUtilities

        public GeneralUtilities()
    • Method Detail

      • safeEquals

        public static boolean safeEquals​(java.lang.Object a,
                                         java.lang.Object b)
        Returns true if a is equals to b, or both and and b are null. Is safe even if a or b is null. If a or b is null but the other is not null, this returns false
        Parameters:
        a - A possibly null object to compare
        b - A possibly null object to compare
        Returns:
        true if equal, false if not
      • loadArrayClass

        private static java.lang.Class<?> loadArrayClass​(java.lang.ClassLoader cl,
                                                         java.lang.String aName)
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.ClassLoader cl,
                                                   java.lang.String cName)
        Loads the class from the given classloader or returns null (does not throw). Property handles array classes as well
        Parameters:
        cl - The non-null classloader to load the class from
        cName - The fully qualified non-null name of the class to load
        Returns:
        The class if it could be loaded from the classloader, or null if it could not be found for any reason
      • getWeakHashClock

        public static <K,​V> WeakHashClock<K,​V> getWeakHashClock​(boolean isWeak)
        Creates a weak hash clock
        Parameters:
        isWeak - if true this will keep weak keyes, if false the keys will be hard and will not go away even if they do not exist anywhere else but this cache
        Returns:
        A weak hash clock implementation
      • getWeakHashLRU

        public static <K> WeakHashLRU<K> getWeakHashLRU​(boolean isWeak)
        Creates a weak hash clock
        Parameters:
        isWeak - if true this will keep weak keyes, if false the keys will be hard and will not go away even if they do not exist anywhere else but this cache
        Returns:
        A weak hash clock implementation
      • prettyPrintBytes

        public static java.lang.String prettyPrintBytes​(byte[] bytes)
        Pretty prints a string of bytes in a hexadecimal format with byte number at the start of the line
        Parameters:
        bytes - A non-null string of bytes
        Returns:
        A string that has the bytes pretty-printed