Class GeneralUtilities
- java.lang.Object
-
- org.glassfish.hk2.utilities.general.GeneralUtilities
-
public class GeneralUtilities extends Object
This class contains utilities useful for any code- Author:
- jwells
-
-
Constructor Summary
Constructors Constructor Description GeneralUtilities()
-
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 clockstatic <K> WeakHashLRU<K>
getWeakHashLRU(boolean isWeak)
Creates a weak hash clockstatic Class<?>
loadClass(ClassLoader cl, String cName)
Loads the class from the given classloader or returns null (does not throw).static String
prettyPrintBytes(byte[] bytes)
Pretty prints a string of bytes in a hexadecimal format with byte number at the start of the linestatic boolean
safeEquals(Object a, Object b)
Returns true if a is equals to b, or both and and b are null.
-
-
-
Method Detail
-
safeEquals
public static boolean safeEquals(Object a, 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 compareb
- A possibly null object to compare- Returns:
- true if equal, false if not
-
loadClass
public static Class<?> loadClass(ClassLoader cl, 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 fromcName
- 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 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
-
-