1
2
3
4
5
6
7 package nl.tudelft.simulation.event.util;
8
9 import java.util.Iterator;
10
11 import nl.tudelft.simulation.event.EventProducer;
12 import nl.tudelft.simulation.event.EventType;
13
14 /***
15 * The Event producing iterator provides a set to which one can subscribe
16 * interest in entry changes.
17 * <p>
18 * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
19 * University of Technology </a>, the Netherlands.
20 * <p>
21 * See for project information <a
22 * href="http://www.simulation.tudelft.nl/dsol/event">www.simulation.tudelft.nl/event
23 * </a> <br>
24 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
25 * General Public License (LGPL) </a>, no warranty
26 *
27 * @author <a href="http://www.peter-jacobs.com">Peter Jacobs </a>
28 * @version $Revision: 1.5 $ $Date: 2005/07/04 12:23:01 $
29 * @since 1.5
30 * @param <T> the type of the iterator
31 */
32 public class EventIterator<T> extends EventProducer implements
33 java.util.Iterator<T>
34 {
35 /*** OBJECT_REMOVED_EVENT is fired on removel of entries */
36 public static final EventType OBJECT_REMOVED_EVENT = new EventType(
37 "OBJECT_REMOVED_EVENT");
38
39 /*** our parent iterator */
40 private Iterator<T> parent = null;
41
42 /***
43 * constructs a new Iterator.
44 *
45 * @param parent parent.
46 */
47 public EventIterator(final Iterator<T> parent)
48 {
49 super();
50 this.parent = parent;
51 }
52
53 /***
54 * @see java.util.Iterator#hasNext()
55 */
56 public boolean hasNext()
57 {
58 return this.parent.hasNext();
59 }
60
61 /***
62 * @see java.util.Iterator#next()
63 */
64 public T next()
65 {
66 return this.parent.next();
67 }
68
69 /***
70 * @see java.util.Iterator#remove()
71 */
72 public void remove()
73 {
74 this.parent.remove();
75 this.fireEvent(OBJECT_REMOVED_EVENT, null);
76 }
77 }