Author: oheger
Date: Fri Jul 11 20:25:36 2014
New Revision: 1609806
URL: http://svn.apache.org/r1609806
Log:
Added an addAll() method to EventListenerList.
This method copies the content of one list with event listeners to another
list.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java?rev=1609806&r1=1609805&r2=1609806&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/event/EventListenerList.java
Fri Jul 11 20:25:36 2014
@@ -214,6 +214,27 @@ public class EventListenerList
}
/**
+ * Adds all event listener registrations stored in the specified
+ * {@code EventListenerList} to this list.
+ *
+ * @param c the list to be copied (must not be <b>null</b>)
+ * @throws IllegalArgumentException if the list to be copied is <b>null</b>
+ */
+ public void addAll(EventListenerList c)
+ {
+ if (c == null)
+ {
+ throw new IllegalArgumentException(
+ "List to be copied must not be null!");
+ }
+
+ for (EventListenerRegistrationData<?> regData : c.getRegistrations())
+ {
+ addEventListener(regData);
+ }
+ }
+
+ /**
* Helper method for calling an event listener with an event. We have to
* operate on raw types to make this code compile. However, this is safe
* because of the way the listeners have been registered and associated
with
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java?rev=1609806&r1=1609805&r2=1609806&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/event/TestEventListenerList.java
Fri Jul 11 20:25:36 2014
@@ -474,6 +474,43 @@ public class TestEventListenerList
}
/**
+ * Tests whether the content of another list can be added.
+ */
+ @Test
+ public void testAddAll()
+ {
+ EventListener<EventBase> l1 = new ListenerTestImpl();
+ EventListener<EventBase> l2 = new ListenerTestImpl();
+ EventListener<EventBase> l3 = new ListenerTestImpl();
+ list.addEventListener(typeBase, l1);
+ EventListenerList list2 = new EventListenerList();
+ list2.addEventListener(typeSub1, l2);
+ list2.addEventListener(typeBase, l3);
+
+ list.addAll(list2);
+ Iterator<EventListenerRegistrationData<?>> it =
+ list.getRegistrations().iterator();
+ EventListenerRegistrationData<?> reg = it.next();
+ assertEquals("Wrong type (1)", typeBase, reg.getEventType());
+ assertEquals("Wrong listener (1)", l1, reg.getListener());
+ reg = it.next();
+ assertEquals("Wrong type (2)", typeSub1, reg.getEventType());
+ assertEquals("Wrong listener (2)", l2, reg.getListener());
+ reg = it.next();
+ assertEquals("Wrong type (3)", typeBase, reg.getEventType());
+ assertEquals("Wrong listener (3)", l3, reg.getListener());
+ }
+
+ /**
+ * Tries to add the content of a null list.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testAddAllNull()
+ {
+ list.addAll(null);
+ }
+
+ /**
* Test event class. For testing purposes, a small hierarchy of test event
* class is created. This way it can be checked whether event types are
* correctly evaluated and take the event hierarchy into account.