- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
/**
* Returns an array of all the objects currently registered
* as <code><em>Foo</em>Listener</code>s
* upon this <code>Component</code>.
* <code><em>Foo</em>Listener</code>s are registered using the
* <code>add<em>Foo</em>Listener</code> method.
*
* <p>
* You can specify the <code>listenerType</code> argument
* with a class literal, such as
* <code><em>Foo</em>Listener.class</code>.
* For example, you can query a
* <code>Component</code> <code>c</code>
* for its mouse listeners with the following code:
*
* <pre>MouseListener[] mls = (MouseListener[])(c.getListeners(MouseListener.class));</pre>
*
* If no such listeners exist, this method returns an empty array.
*
* @param listenerType the type of listeners requested; this parameter
* should specify an interface that descends from
* <code>java.util.EventListener</code>
* @return an array of all objects registered as
* <code><em>Foo</em>Listener</code>s on this component,
* or an empty array if no such listeners have been added
* @exception ClassCastException if <code>listenerType</code>
* doesn't specify a class or interface that implements
* <code>java.util.EventListener</code>
*
* @see #getComponentListeners
* @see #getFocusListeners
* @see #getHierarchyListeners
* @see #getHierarchyBoundsListeners
* @see #getKeyListeners
* @see #getMouseListeners
* @see #getMouseMotionListeners
* @see #getMouseWheelListeners
* @see #getInputMethodListeners
* @see #getPropertyChangeListeners
*
* @since 1.3
*/
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
EventListener l = null;
if (listenerType == ComponentListener.class) {
l = componentListener;
} else if (listenerType == FocusListener.class) {
l = focusListener;
} else if (listenerType == HierarchyListener.class) {
l = hierarchyListener;
} else if (listenerType == HierarchyBoundsListener.class) {
l = hierarchyBoundsListener;
} else if (listenerType == KeyListener.class) {
l = keyListener;
} else if (listenerType == MouseListener.class) {
l = mouseListener;
} else if (listenerType == MouseMotionListener.class) {
l = mouseMotionListener;
} else if (listenerType == MouseWheelListener.class) {
l = mouseWheelListener;
} else if (listenerType == InputMethodListener.class) {
l = inputMethodListener;
} else if (listenerType == PropertyChangeListener.class) {
return (T[])getPropertyChangeListeners();
}
return AWTEventMulticaster.getListeners(l, listenerType);
}
Ну - минусуйте меня теперь за то что я сказал ))))
Можно же было использовать хотя бы switch на худой конец, а еще лучше собрать все значения в массив и по нему ходить!
массив был бы лучше, но может это такая говнооптимизация
Я тоже сначала подумал про оптимизацию
скорее, он обрел новое дыхание, став синхронизированным, и при этом реализуя упомянутый интерфейс. Совместно с ArrayList, который не синхронизирован и, будучи при этом non thread-safe, дает выигрыш в скорости.
То есть, не всегда нужно в срочном порядке выкидывать его из кода, как тот же Hashtable
з.ы. он все еще жив и вполне используется,например, в качестве модели для JList, JComboBox
синхронизировать лучше через спец утилиты Collections.
или вообще конкаррент коллекшинс юзать
да и писать case и break достаёт, к тому же в if-elsif ты не ограничен "=="
А массив — да, хорошее решение.
Недаром там по умолчанию идёт сквозной проход по всем условиям. (это когда без брэйков).
http://bit.ly/d9em9Y
http://bit.ly/byYFvh
Я с тем же успехом могу заявить, что функции были придуманы исключительно для организации рекурсивных вычислений, как будто у них нет других применений.
Соглашусь, что читабельность лучше в свитче.
знаете какой?
сквозной проход там делается с помощью continue.
А сквозной проход, как я сказал выше, делается с помощью continue.
ой мамочки!
Совсем забыл, что FF и подобные игрушки представляют кириллические УРЛ в виде %D0%A5... Опера кириллицу отображает кириллицей.
Жду очередной Священной войны.
не дождёшься, я против холиваров
но оно унылое по большей части.
Написал под старым постом, что бы моего коммента никто не увидел=)
Хех, наивный :)))