Class Kit


  • public class Kit
    extends Object
    Collection of utilities
    • Constructor Detail

      • Kit

        public Kit()
    • Method Detail

      • classOrNull

        public static Class<?> classOrNull​(String className)
      • classOrNull

        public static Class<?> classOrNull​(ClassLoader loader,
                                           String className)
        Attempt to load the class of the given name. Note that the type parameter isn't checked.
      • initCause

        public static RuntimeException initCause​(RuntimeException ex,
                                                 Throwable cause)
        If initCause methods exists in Throwable, call ex.initCause(cause) or otherwise do nothing.
        Returns:
        The ex argument.
      • xDigitToInt

        public static int xDigitToInt​(int c,
                                      int accumulator)
        If character c is a hexadecimal digit, return accumulator * 16 plus corresponding number. Otherise return -1.
      • addListener

        public static Object addListener​(Object bag,
                                         Object listener)
        Add listener to bag of listeners. The function does not modify bag and return a new collection containing listener and all listeners from bag. Bag without listeners always represented as the null value.

        Usage example:

             private volatile Object changeListeners;
        
             public void addMyListener(PropertyChangeListener l)
             {
                 synchronized (this) {
                     changeListeners = Kit.addListener(changeListeners, l);
                 }
             }
        
             public void removeTextListener(PropertyChangeListener l)
             {
                 synchronized (this) {
                     changeListeners = Kit.removeListener(changeListeners, l);
                 }
             }
        
             public void fireChangeEvent(Object oldValue, Object newValue)
             {
             // Get immune local copy
                 Object listeners = changeListeners;
                 if (listeners != null) {
                     PropertyChangeEvent e = new PropertyChangeEvent(
                         this, "someProperty" oldValue, newValue);
                     for (int i = 0; ; ++i) {
                         Object l = Kit.getListener(listeners, i);
                         if (l == null)
                             break;
                         ((PropertyChangeListener)l).propertyChange(e);
                     }
                 }
             }
         
        Parameters:
        listener - Listener to add to bag
        bag - Current collection of listeners.
        Returns:
        A new bag containing all listeners from bag and listener.
        See Also:
        removeListener(Object bag, Object listener), getListener(Object bag, int index)
      • makeHashKeyFromPair

        public static Object makeHashKeyFromPair​(Object key1,
                                                 Object key2)
      • codeBug

        public static RuntimeException codeBug()
                                        throws RuntimeException
        Throws RuntimeException to indicate failed assertion. The function never returns and its return type is RuntimeException only to be able to write throw Kit.codeBug() if plain Kit.codeBug() triggers unreachable code error.
        Throws:
        RuntimeException
      • codeBug

        public static RuntimeException codeBug​(String msg)
                                        throws RuntimeException
        Throws RuntimeException to indicate failed assertion. The function never returns and its return type is RuntimeException only to be able to write throw Kit.codeBug() if plain Kit.codeBug() triggers unreachable code error.
        Throws:
        RuntimeException