Package org.mozilla.javascript
Class Kit
java.lang.Object
org.mozilla.javascript.Kit
Collection of utilities
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
addListener
(Object bag, Object listener) Add listener to bag of listeners.static Class
<?> classOrNull
(ClassLoader loader, String className) Attempt to load the class of the given name.static Class
<?> classOrNull
(String className) static RuntimeException
codeBug()
Throws RuntimeException to indicate failed assertion.static RuntimeException
Throws RuntimeException to indicate failed assertion.static Object
getListener
(Object bag, int index) Get listener at index position in bag or null if index equals to number of listeners in bag.static Object
makeHashKeyFromPair
(Object key1, Object key2) static String
readReader
(Reader reader) static byte[]
readStream
(InputStream is, int initialBufferCapacity) static Object
removeListener
(Object bag, Object listener) Remove listener from bag of listeners.static int
xDigitToInt
(int c, int accumulator) If characterc
is a hexadecimal digit, returnaccumulator
* 16 plus corresponding number.
-
Constructor Details
-
Kit
public Kit()
-
-
Method Details
-
classOrNull
-
classOrNull
Attempt to load the class of the given name. Note that the type parameter isn't checked. -
xDigitToInt
public static int xDigitToInt(int c, int accumulator) If characterc
is a hexadecimal digit, returnaccumulator
* 16 plus corresponding number. Otherwise return -1. -
addListener
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:
bag
- Current collection of listeners.listener
- Listener to add to bag- Returns:
- A new bag containing all listeners from bag and listener.
- See Also:
-
removeListener
Remove listener from bag of listeners. The function does not modify bag and return a new collection containing all listeners from bag except listener. If bag does not contain listener, the function returns bag.For usage example, see
addListener(Object bag, Object listener)
.- Parameters:
bag
- Current collection of listeners.listener
- Listener to remove from bag- Returns:
- A new bag containing all listeners from bag except listener.
- See Also:
-
getListener
Get listener at index position in bag or null if index equals to number of listeners in bag.For usage example, see
addListener(Object bag, Object listener)
.- Parameters:
bag
- Current collection of listeners.index
- Index of the listener to access.- Returns:
- Listener at the given index or null.
- See Also:
-
makeHashKeyFromPair
-
readReader
- Throws:
IOException
-
readStream
- Throws:
IOException
-
codeBug
Throws RuntimeException to indicate failed assertion. The function never returns and its return type is RuntimeException only to be able to writethrow Kit.codeBug()
if plainKit.codeBug()
triggers unreachable code error.- Throws:
RuntimeException
-
codeBug
Throws RuntimeException to indicate failed assertion. The function never returns and its return type is RuntimeException only to be able to writethrow Kit.codeBug()
if plainKit.codeBug()
triggers unreachable code error.- Throws:
RuntimeException
-