View Javadoc

1   /*
2    * @(#) EventIterator.java Nov 19, 2003 Copyright (c) 2002-2005 Delft University
3    * of Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights
4    * reserved. This software is proprietary information of Delft University of
5    * Technology The code is published under the Lesser General Public License
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  }