View Javadoc

1   /*
2    * @(#) EventProducingMap.java Nov 19, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.event.util;
11  
12  import java.util.Collection;
13  import java.util.Map;
14  import java.util.Set;
15  
16  import nl.tudelft.simulation.event.EventProducer;
17  import nl.tudelft.simulation.event.EventType;
18  
19  /***
20   * The Event producing map provides a map to which one can subscribe interest in
21   * entry changes. This class does not keep track of changes which take place
22   * indirectly. One is for example not notified on
23   * <code>map.iterator.remove()</code>. A listener must subscribe to the
24   * iterator, key set, etc. individually.
25   * <p>
26   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
27   * University of Technology </a>, the Netherlands. <br>
28   * See for project information <a
29   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
30   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31   * License (GPL) </a>, no warranty <br>
32   * 
33   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
34   *         Jacobs </a>
35   * @version 1.3, 2004-03-18
36   * @since 1.2
37   */
38  public class EventProducingMap extends EventProducer implements Map
39  {
40  	/*** OBJECT_ADDED_EVENT is fired on new entries */
41  	public static final EventType OBJECT_ADDED_EVENT = new EventType(
42  			"OBJECT_ADDED_EVENT");
43  
44  	/*** OBJECT_REMOVED_EVENT is fired on removel of entries */
45  	public static final EventType OBJECT_REMOVED_EVENT = new EventType(
46  			"OBJECT_REMOVED_EVENT");
47  
48  	/*** the parent map */
49  	private Map parent = null;
50  
51  	/***
52  	 * constructs a new EventProducingMap.
53  	 * 
54  	 * @param parent the parent map.
55  	 */
56  	public EventProducingMap(final Map parent)
57  	{
58  		super();
59  		this.parent = parent;
60  	}
61  
62  	/***
63  	 * @see java.util.Map#size()
64  	 */
65  	public int size()
66  	{
67  		return this.parent.size();
68  	}
69  
70  	/***
71  	 * @see java.util.Map#isEmpty()
72  	 */
73  	public boolean isEmpty()
74  	{
75  		return this.parent.isEmpty();
76  	}
77  
78  	/***
79  	 * @see java.util.Map#containsKey(java.lang.Object)
80  	 */
81  	public boolean containsKey(final Object arg0)
82  	{
83  		return this.parent.containsKey(arg0);
84  	}
85  
86  	/***
87  	 * @see java.util.Map#containsValue(java.lang.Object)
88  	 */
89  	public boolean containsValue(final Object arg0)
90  	{
91  		return this.parent.containsValue(arg0);
92  	}
93  
94  	/***
95  	 * @see java.util.Map#get(java.lang.Object)
96  	 */
97  	public Object get(final Object arg0)
98  	{
99  		return this.parent.get(arg0);
100 	}
101 
102 	/***
103 	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
104 	 */
105 	public Object put(final Object arg0, final Object arg1)
106 	{
107 		Object result = this.parent.put(arg0, arg1);
108 		this.fireEvent(OBJECT_ADDED_EVENT, null);
109 		return result;
110 	}
111 
112 	/***
113 	 * @see java.util.Map#remove(java.lang.Object)
114 	 */
115 	public Object remove(final Object arg0)
116 	{
117 		Object result = this.parent.remove(arg0);
118 		this.fireEvent(OBJECT_REMOVED_EVENT, null);
119 		return result;
120 	}
121 
122 	/***
123 	 * @see java.util.Map#putAll(java.util.Map)
124 	 */
125 	public void putAll(final Map arg0)
126 	{
127 		this.parent.putAll(arg0);
128 		this.fireEvent(OBJECT_ADDED_EVENT, null);
129 	}
130 
131 	/***
132 	 * @see java.util.Map#clear()
133 	 */
134 	public void clear()
135 	{
136 		this.parent.clear();
137 		this.fireEvent(OBJECT_REMOVED_EVENT, null);
138 	}
139 
140 	/***
141 	 * @see java.util.Map#keySet()
142 	 */
143 	public Set keySet()
144 	{
145 		return this.parent.keySet();
146 	}
147 
148 	/***
149 	 * @see java.util.Map#values()
150 	 */
151 	public Collection values()
152 	{
153 		return this.parent.values();
154 	}
155 
156 	/***
157 	 * @see java.util.Map#entrySet()
158 	 */
159 	public Set entrySet()
160 	{
161 		return this.parent.entrySet();
162 	}
163 }