commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1612658 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/ main/java/org/apache/commons/configuration/builder/combined/ test/java/org/apache/commons/configuration/builder/ test/java/org/apache...
Date Tue, 22 Jul 2014 19:55:02 GMT
Author: oheger
Date: Tue Jul 22 19:55:02 2014
New Revision: 1612658

URL: http://svn.apache.org/r1612658
Log:
Changed return type of add/removeConfigurationListener().

The methods no longer support method chaining (this is difficult to implement
over the hierarchy of builders anyway). Instead, they use the same return
values as the methods from EventSource.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1612658&r1=1612657&r2=1612658&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
Tue Jul 22 19:55:02 2014
@@ -274,14 +274,12 @@ public class BasicConfigurationBuilder<T
      * @param eventType the event type object
      * @param listener the listener to be registered
      * @param <E> the event type
-     * @return a reference to this builder for method chaining
      */
-    public synchronized <E extends Event> BasicConfigurationBuilder<T> addConfigurationListener(
+    public synchronized <E extends Event> void addConfigurationListener(
             EventType<E> eventType, EventListener<? super E> listener)
     {
         configListeners.addEventListener(eventType, listener);
         fetchEventSource().addEventListener(eventType, listener);
-        return this;
     }
 
     /**
@@ -291,14 +289,13 @@ public class BasicConfigurationBuilder<T
      * @param eventType the event type object
      * @param listener the listener to be removed
      * @param <E> the event type
-     * @return a reference to this builder for method chaining
+     * @return a flag whether the listener could be removed
      */
-    public synchronized <E extends Event> BasicConfigurationBuilder<T> removeConfigurationListener(
+    public synchronized <E extends Event> boolean removeConfigurationListener(
             EventType<E> eventType, EventListener<? super E> listener)
     {
-        configListeners.removeEventListener(eventType, listener);
         fetchEventSource().removeEventListener(eventType, listener);
-        return this;
+        return configListeners.removeEventListener(eventType, listener);
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java?rev=1612658&r1=1612657&r2=1612658&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
Tue Jul 22 19:55:02 2014
@@ -230,7 +230,7 @@ public class MultiFileConfigurationBuild
      * at managed configuration builders.
      */
     @Override
-    public synchronized <E extends Event> BasicConfigurationBuilder<T> addConfigurationListener(
+    public synchronized <E extends Event> void addConfigurationListener(
             EventType<E> eventType, EventListener<? super E> l)
     {
         super.addConfigurationListener(eventType, l);
@@ -238,7 +238,6 @@ public class MultiFileConfigurationBuild
         {
             b.addConfigurationListener(eventType, l);
         }
-        return this;
     }
 
     /**
@@ -246,15 +245,15 @@ public class MultiFileConfigurationBuild
      * removed from managed configuration builders.
      */
     @Override
-    public synchronized <E extends Event> BasicConfigurationBuilder<T> removeConfigurationListener(
+    public synchronized <E extends Event> boolean removeConfigurationListener(
             EventType<E> eventType, EventListener<? super E> l)
     {
-        super.removeConfigurationListener(eventType, l);
+        boolean result = super.removeConfigurationListener(eventType, l);
         for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
         {
             b.removeConfigurationListener(eventType, l);
         }
-        return this;
+        return result;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java?rev=1612658&r1=1612657&r2=1612658&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestBasicConfigurationBuilder.java
Tue Jul 22 19:55:02 2014
@@ -356,8 +356,8 @@ public class TestBasicConfigurationBuild
         EasyMock.replay(l1, l2);
         BasicConfigurationBuilder<PropertiesConfiguration> builder =
                 new BasicConfigurationBuilder<PropertiesConfiguration>(
-                        PropertiesConfiguration.class)
-                        .addConfigurationListener(ConfigurationEvent.ANY, l1);
+                        PropertiesConfiguration.class);
+        builder.addConfigurationListener(ConfigurationEvent.ANY, l1);
         PropertiesConfiguration config = builder.getConfiguration();
         builder.addConfigurationListener(ConfigurationEvent.ANY, l2);
         Collection<EventListener<? super ConfigurationEvent>> listeners =
@@ -377,11 +377,12 @@ public class TestBasicConfigurationBuild
         EasyMock.replay(l1, l2);
         BasicConfigurationBuilder<PropertiesConfiguration> builder =
                 new BasicConfigurationBuilder<PropertiesConfiguration>(
-                        PropertiesConfiguration.class)
-                        .addConfigurationListener(
-                                ConfigurationEvent.ANY_HIERARCHICAL, l1)
-                        .addConfigurationListener(ConfigurationEvent.ANY, l2);
-        builder.removeConfigurationListener(ConfigurationEvent.ANY, l2);
+                        PropertiesConfiguration.class);
+        builder.addConfigurationListener(ConfigurationEvent.ANY_HIERARCHICAL,
+                l1);
+        builder.addConfigurationListener(ConfigurationEvent.ANY, l2);
+        assertTrue("Wrong result",
+                builder.removeConfigurationListener(ConfigurationEvent.ANY, l2));
         PropertiesConfiguration config = builder.getConfiguration();
         assertFalse("Removed listener was registered", config
                 .getEventListeners(ConfigurationEvent.ANY).contains(l2));

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java?rev=1612658&r1=1612657&r2=1612658&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
Tue Jul 22 19:55:02 2014
@@ -975,9 +975,9 @@ public class TestCombinedConfigurationBu
         File testFile =
                 ConfigurationAssert
                         .getTestFile("testCCCombinedChildBuilder.xml");
-        builder.configure(new XMLBuilderParametersImpl().setFile(testFile))
-                .addConfigurationListener(Event.ANY, l1)
-                .addConfigurationListener(ConfigurationEvent.ANY, l2);
+        builder.configure(new XMLBuilderParametersImpl().setFile(testFile));
+        builder.addConfigurationListener(Event.ANY, l1);
+        builder.addConfigurationListener(ConfigurationEvent.ANY, l2);
         CombinedConfiguration cc = builder.getConfiguration();
         CombinedConfiguration cc2 =
                 (CombinedConfiguration) cc.getConfiguration("subcc");

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java?rev=1612658&r1=1612657&r2=1612658&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
Tue Jul 22 19:55:02 2014
@@ -265,8 +265,7 @@ public class TestMultiFileConfigurationB
         EasyMock.replay(l1, l2);
         MultiFileConfigurationBuilder<XMLConfiguration> builder =
                 createTestBuilder(null);
-        assertSame("Wrong result", builder,
-                builder.addConfigurationListener(ConfigurationEvent.ANY, l1));
+        builder.addConfigurationListener(ConfigurationEvent.ANY, l1);
         switchToConfig(1);
         XMLConfiguration config = builder.getConfiguration();
         assertTrue("Listener not added", config.getEventListeners(ConfigurationEvent.ANY)
@@ -274,7 +273,9 @@ public class TestMultiFileConfigurationB
         builder.addConfigurationListener(Event.ANY, l2);
         assertTrue("Listener 2 not added", config.getEventListeners(Event.ANY)
                 .contains(l2));
-        builder.removeConfigurationListener(Event.ANY, l2);
+        assertTrue("Wrong result", builder.removeConfigurationListener(Event.ANY, l2));
+        assertFalse("Wrong result after removal",
+                builder.removeConfigurationListener(Event.ANY, l2));
         assertFalse("Listener not removed", config.getEventListeners(Event.ANY)
                 .contains(l2));
         switchToConfig(2);



Mime
View raw message