Module org.glassfish.hk2.utilities
Class GeneralUtilities
java.lang.Object
org.glassfish.hk2.utilities.general.GeneralUtilities
This class contains utilities useful for any code
- Author:
- jwells
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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 StringprettyPrintBytes(byte[] bytes) Pretty prints a string of bytes in a hexadecimal format with byte number at the start of the linestatic booleansafeEquals(Object a, Object b) Returns true if a is equals to b, or both and and b are null.
-
Constructor Details
-
GeneralUtilities
public GeneralUtilities()
-
-
Method Details
-
safeEquals
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
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
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
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
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
-