db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/collections TrackingCollectionImpl.java
Date Tue, 16 Nov 2004 20:59:56 GMT
brj         2004/11/16 12:59:56

  Modified:    src/java/org/apache/ojb/broker/util/collections
                        TrackingCollectionImpl.java
  Log:
  addAll / removeAll use add / remove
  
  Revision  Changes    Path
  1.2       +53 -46    db-ojb/src/java/org/apache/ojb/broker/util/collections/TrackingCollectionImpl.java
  
  Index: TrackingCollectionImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/collections/TrackingCollectionImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TrackingCollectionImpl.java	13 Nov 2004 10:08:16 -0000	1.1
  +++ TrackingCollectionImpl.java	16 Nov 2004 20:59:55 -0000	1.2
  @@ -1,26 +1,26 @@
   package org.apache.ojb.broker.util.collections;
   
   /* Copyright 2003-2004 The Apache Software Foundation
  -*
  -* Licensed under the Apache License, Version 2.0 (the "License");
  -* you may not use this file except in compliance with the License.
  -* You may obtain a copy of the License at
  -*
  -*     http://www.apache.org/licenses/LICENSE-2.0
  -*
  -* Unless required by applicable law or agreed to in writing, software
  -* distributed under the License is distributed on an "AS IS" BASIS,
  -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  -* See the License for the specific language governing permissions and
  -* limitations under the License.
  -*/
  + *
  + * Licensed under the Apache License, Version 2.0 (the "License");
  + * you may not use this file except in compliance with the License.
  + * You may obtain a copy of the License at
  + *
  + *     http://www.apache.org/licenses/LICENSE-2.0
  + *
  + * Unless required by applicable law or agreed to in writing, software
  + * distributed under the License is distributed on an "AS IS" BASIS,
  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  + * See the License for the specific language governing permissions and
  + * limitations under the License.
  + */
   
  -import java.util.ArrayList;
   import java.util.Collection;
  +import java.util.HashSet;
   import java.util.Iterator;
   
   /**
  - * A Wrapper to track modifications on a Collection.
  + * A Wrapper to track modifications (add / remove) on a Collection.
    *
    * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    * @version $Id$
  @@ -29,10 +29,9 @@
   {
       private static final long serialVersionUID = 3256726190730392115L;
   
  -   
  -    private Collection m_newObjects = new ArrayList();
  -    private Collection m_deletedObjects = new ArrayList();
  -    
  +    private Collection m_newObjects = new HashSet();
  +    private Collection m_deletedObjects = new HashSet();
  +
       /**
        * @param collection
        */
  @@ -40,7 +39,7 @@
       {
           super(collection);
       }
  -    
  +
       /**
        * @see java.util.Collection#add(java.lang.Object)
        */
  @@ -53,59 +52,69 @@
           }
           return result;
       }
  -    
  +
       /**
        * @see java.util.Collection#addAll(java.util.Collection)
        */
       public boolean addAll(Collection c)
       {
  -        boolean result = super.addAll(c);
  -        if (result)
  +        boolean modified = false;
  +        Iterator iter = c.iterator();
  +        while (iter.hasNext())
           {
  -            registerNew(c);
  +            if (add(iter.next()))
  +            {
  +                modified = true;
  +            }
           }
  -        return result;
  +        return modified;
       }
  -    
  +
       /**
        * @see java.util.Collection#clear()
        */
       public void clear()
       {
           registerDelete(getCollection());
  -        
  +
           super.clear();
       }
  -    
  -    
  +
       /**
        * @see java.util.Collection#remove(java.lang.Object)
        */
       public boolean remove(Object o)
       {
           boolean result = super.remove(o);
  -        
  +
           if (result)
           {
               registerDelete(o);
           }
           return result;
       }
  -    
  +
       /**
        * @see java.util.Collection#removeAll(java.util.Collection)
        */
       public boolean removeAll(Collection c)
       {
  -        boolean result = super.removeAll(c);
  -        
  -        if (result)
  +        boolean modified = false;
  +        Iterator iter = iterator();
  +        while (iter.hasNext())
           {
  -            registerDelete(c);
  +            Object obj = iter.next();
  +            if (c.contains(obj))
  +            {
  +                iter.remove();
  +                registerDelete(obj);
  +                modified = true;
  +            }
           }
  -        return result;
  +
  +        return modified;
       }
  -    
  +
       /**
        * @see java.util.Collection#retainAll(java.util.Collection)
        */
  @@ -123,11 +132,10 @@
                   modified = true;
               }
           }
  -        
  +
           return modified;
       }
  -       
  -     
  +
       /**
        * @return Returns the deletedObjects.
        */
  @@ -135,12 +143,12 @@
       {
           return m_deletedObjects;
       }
  -    
  +
       public void clearDeletedObjects()
       {
           m_deletedObjects.clear();
       }
  -    
  +
       /**
        * @return Returns the newObjects.
        */
  @@ -151,9 +159,9 @@
   
       public void clearNewObjects()
       {
  -        m_newObjects.clear();        
  +        m_newObjects.clear();
       }
  -    
  +
       /**
        * Register a deleted Object. 
        * @param obj
  @@ -194,7 +202,6 @@
           m_newObjects.addAll(coll);
       }
   
  -    
       private void removeFromDeletion(Object toBeReadded)
       {
           m_deletedObjects.remove(toBeReadded);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message