01: /* ListenerIterator.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Mon Jun 4 16:12:35 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zk.ui.impl;
20:
21: import java.util.List;
22: import java.util.Iterator;
23:
24: /**
25: * Used to iterate the event listener.
26: *
27: * <p>It resolves a bug of LinkedList:
28: * LinkedList's hasNext() and hasPrevious() doesn't check
29: * concurrent-modification.
30: * Thus, if the 2nd last listener is removed, hasNext() simply return
31: * false (and the last listener is ignored) rather than throwing
32: * ConcurrentModificationException. Refer to Bug 1730532.
33: *
34: * @author tomyeh
35: */
36: public class ListenerIterator implements Iterator {
37: private final List _org;
38: private final int _orgsz;
39: private final Iterator _it;
40:
41: public ListenerIterator(List list) {
42: _org = list;
43: _orgsz = list.size();
44: _it = list.iterator();
45: }
46:
47: public boolean hasNext() {
48: if (_orgsz != _org.size())
49: throw new java.util.ConcurrentModificationException();
50: return _it.hasNext();
51: }
52:
53: public Object next() {
54: return _it.next();
55: }
56:
57: public void remove() {
58: throw new UnsupportedOperationException();
59: }
60: }
|