commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections/decorators ObservedTestHelper.java
Date Sun, 31 Aug 2003 21:09:49 GMT
scolebourne    2003/08/31 14:09:49

  Modified:    collections/src/java/org/apache/commons/collections/event
                        StandardModificationListener.java
                        ModificationHandler.java
                        StandardModificationHandler.java
               collections/src/java/org/apache/commons/collections/decorators
                        ObservedCollection.java
               collections/src/test/org/apache/commons/collections/decorators
                        ObservedTestHelper.java
  Removed:     collections/src/java/org/apache/commons/collections/event
                        ModificationListener.java
  Log:
  Refactor events so listener is defined as an Object for flexibility
  
  Revision  Changes    Path
  1.3       +5 -3      jakarta-commons/collections/src/java/org/apache/commons/collections/event/StandardModificationListener.java
  
  Index: StandardModificationListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/event/StandardModificationListener.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StandardModificationListener.java	31 Aug 2003 17:25:49 -0000	1.2
  +++ StandardModificationListener.java	31 Aug 2003 21:09:49 -0000	1.3
  @@ -57,6 +57,8 @@
    */
   package org.apache.commons.collections.event;
   
  +import java.util.EventListener;
  +
   /**
    * A listener that receives events from the <code>StandardModificationHandler</code>.
    * <p>
  @@ -73,7 +75,7 @@
    * 
    * @author Stephen Colebourne
    */
  -public interface StandardModificationListener extends ModificationListener {
  +public interface StandardModificationListener extends EventListener {
   
       /**
        * A collection modification is occurring.
  
  
  
  1.3       +10 -5     jakarta-commons/collections/src/java/org/apache/commons/collections/event/ModificationHandler.java
  
  Index: ModificationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/event/ModificationHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModificationHandler.java	31 Aug 2003 17:25:49 -0000	1.2
  +++ ModificationHandler.java	31 Aug 2003 21:09:49 -0000	1.3
  @@ -129,7 +129,7 @@
        * @return the listeners
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public ModificationListener[] getModificationListeners() {
  +    public Object[] getModificationListeners() {
           throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
       }
       
  @@ -138,13 +138,18 @@
        * <p>
        * No error occurs if the listener is <code>null</code>.
        * <p>
  +     * The listener does not necessarily have to be a listener in the classic
  +     * JavaBean sense. It is entirely up to the handler as to how it interprets
  +     * the listener parameter. A ClassCastException is thrown if the handler
  +     * cannot interpret the parameter.
  +     * <p>
        * This implementation throws UnsupportedOperationException.
        * 
        * @param listener  the listener to add, may be null (ignored)
        * @throws ClassCastException if the listener is not of the correct type
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public void addModificationListener(ModificationListener listener) {
  +    public void addModificationListener(Object listener) {
           throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
       }
       
  @@ -159,7 +164,7 @@
        * @param listener  the listener to remove, may be null (ignored)
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public void removeModificationListener(ModificationListener listener) {
  +    public void removeModificationListener(Object listener) {
           throw new UnsupportedOperationException("Listeners not supported by " + getClass().getName());
       }
       
  
  
  
  1.3       +9 -10     jakarta-commons/collections/src/java/org/apache/commons/collections/event/StandardModificationHandler.java
  
  Index: StandardModificationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/event/StandardModificationHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StandardModificationHandler.java	31 Aug 2003 17:25:49 -0000	1.2
  +++ StandardModificationHandler.java	31 Aug 2003 21:09:49 -0000	1.3
  @@ -123,8 +123,8 @@
        * 
        * @return the listeners
        */
  -    public synchronized ModificationListener[] getModificationListeners() {
  -        ModificationListener[] lnrs = new ModificationListener[holders.length];
  +    public synchronized Object[] getModificationListeners() {
  +        Object[] lnrs = new Object[holders.length];
           for (int i = 0; i < holders.length; i++) {
               lnrs[i] = holders[i].listener;
           }
  @@ -139,8 +139,8 @@
        * @param listener  the listener to add, may be null (ignored)
        * @throws ClassCastException if the listener is not a StandardModificationListener
        */
  -    public void addModificationListener(ModificationListener listener) {
  -        addModificationListener(listener, -1, -1);
  +    public void addModificationListener(Object listener) {
  +        addModificationListener((StandardModificationListener) listener, -1, -1);
       }
       
       /**
  @@ -151,14 +151,13 @@
        * @param listener  the listener to add, may be null (ignored)
        * @param preMask  the mask for pre events (0 for none, -1 for all)
        * @param postMask  the mask for post events (0 for none, -1 for all)
  -     * @throws ClassCastException if the listener is not a StandardModificationListener
        */
  -    public synchronized void addModificationListener(ModificationListener listener, int
preMask, int postMask) {
  +    public synchronized void addModificationListener(StandardModificationListener listener,
int preMask, int postMask) {
           if (listener != null) {
               int oldSize = holders.length;
               Holder[] array = new Holder[oldSize + 1];
               System.arraycopy(holders, 0, array, 0, oldSize);
  -            array[oldSize] = new Holder((StandardModificationListener) listener, preMask,
postMask);
  +            array[oldSize] = new Holder(listener, preMask, postMask);
               holders = array;
               calculateMasks();
           }
  @@ -173,7 +172,7 @@
        * 
        * @param listener  the listener to remove, may be null (ignored)
        */
  -    public synchronized void removeModificationListener(ModificationListener listener)
{
  +    public synchronized void removeModificationListener(Object listener) {
           if (listener != null) {
               switch (holders.length) {
                   case 0:
  
  
  
  1.3       +10 -6     jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/ObservedCollection.java
  
  Index: ObservedCollection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/decorators/ObservedCollection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObservedCollection.java	31 Aug 2003 17:24:46 -0000	1.2
  +++ ObservedCollection.java	31 Aug 2003 21:09:49 -0000	1.3
  @@ -61,7 +61,6 @@
   import java.util.Iterator;
   
   import org.apache.commons.collections.event.ModificationHandler;
  -import org.apache.commons.collections.event.ModificationListener;
   import org.apache.commons.collections.event.StandardModificationHandler;
   import org.apache.commons.collections.event.StandardModificationListener;
   
  @@ -244,7 +243,7 @@
        * @return the listeners
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public ModificationListener[] getModificationListeners() {
  +    public Object[] getModificationListeners() {
           return getHandler().getModificationListeners();
       }
       
  @@ -253,12 +252,17 @@
        * This method simply delegates to the handler.
        * <p>
        * No error occurs if the listener is <code>null</code>.
  +     * <p>
  +     * The listener does not necessarily have to be a listener in the classic
  +     * JavaBean sense. It is entirely up to the handler as to how it interprets
  +     * the listener parameter. A ClassCastException is thrown if the handler
  +     * cannot interpret the parameter.
        * 
        * @param listener  the listener to add, may be null (ignored)
        * @throws ClassCastException if the listener is not of the correct type
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public void addModificationListener(ModificationListener listener) {
  +    public void addModificationListener(Object listener) {
           getHandler().addModificationListener(listener);
       }
       
  @@ -274,7 +278,7 @@
        * @param listener  the listener to remove, may be null (ignored)
        * @throws UnsupportedOperationException if the handler does not support listeners
        */
  -    public void removeModificationListener(ModificationListener listener) {
  +    public void removeModificationListener(Object listener) {
           getHandler().removeModificationListener(listener);
       }
       
  
  
  
  1.3       +3 -4      jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/ObservedTestHelper.java
  
  Index: ObservedTestHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/decorators/ObservedTestHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ObservedTestHelper.java	31 Aug 2003 17:28:42 -0000	1.2
  +++ ObservedTestHelper.java	31 Aug 2003 21:09:49 -0000	1.3
  @@ -64,7 +64,6 @@
   import junit.framework.Assert;
   
   import org.apache.commons.collections.event.ModificationEventType;
  -import org.apache.commons.collections.event.ModificationListener;
   import org.apache.commons.collections.event.StandardModificationEvent;
   import org.apache.commons.collections.event.StandardModificationHandler;
   import org.apache.commons.collections.event.StandardModificationListener;
  @@ -157,7 +156,7 @@
           Assert.assertEquals(0, coll.getModificationListeners().length);
           
           try {
  -            coll.addModificationListener(new ModificationListener() {});
  +            coll.addModificationListener(new Object());
               Assert.fail();
           } catch (ClassCastException ex) {
           }
  
  
  

Mime
View raw message