You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by br...@apache.org on 2013/07/23 13:58:29 UTC

svn commit: r1505999 - /ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java

Author: bramk
Date: Tue Jul 23 11:58:28 2013
New Revision: 1505999

URL: http://svn.apache.org/r1505999
Log:
ACE-396 Assign new endpoints to member before throwing a changed event


Modified:
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java?rev=1505999&r1=1505998&r2=1505999&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java (original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java Tue Jul 23 11:58:28 2013
@@ -168,10 +168,8 @@ public class AssociationImpl<L extends R
      */
     @SuppressWarnings("unchecked")
     private <TYPE extends RepositoryObject> List<TYPE> locateEndpoint(ObjectRepositoryImpl<?, TYPE> objectRepositoryImpl, Filter filter, List<TYPE> endpoints, int cardinality, Class<? extends RepositoryObject> clazz, boolean notify) {
-        List<TYPE> candidates = objectRepositoryImpl.get(filter);
-        List<TYPE> newEndpoints = new ArrayList<TYPE>();
-        List<TYPE> oldEndpoints = new ArrayList<TYPE>(endpoints);
 
+        List<TYPE> candidates = objectRepositoryImpl.get(filter);
         if (candidates.size() > cardinality) {
             Comparator<TYPE> comparator = candidates.get(0).getComparator();
             if (comparator != null) {
@@ -181,29 +179,19 @@ public class AssociationImpl<L extends R
                 throw new NullPointerException("Filter '" + filter.toString() + "' has resulted in multiple candidates, so the RepositoryObject descendents should have provide a comparator, which they do not.");
             }
         }
-
+        
+        List<TYPE> oldEndpoints = new ArrayList<TYPE>(endpoints);
+        List<TYPE> newEndpoints = new ArrayList<TYPE>();
         for (int i = 0; (i < cardinality) && !candidates.isEmpty(); i++) {
             TYPE current = candidates.remove(0);
             newEndpoints.add(current);
-
             if (!oldEndpoints.remove(current)) {
                 current.add(this, clazz);
             }
         }
-
         for (TYPE e : oldEndpoints) {
             e.remove(this, clazz);
         }
-
-        if (!endpoints.equals(newEndpoints)) {
-            Properties props = new Properties();
-            props.put(EVENT_OLD, new ArrayList<TYPE>(endpoints));
-            props.put(EVENT_NEW, new ArrayList<TYPE>(newEndpoints));
-            if (notify) {
-                notifyChanged(props);
-            }
-        }
-
         return newEndpoints;
     }
 
@@ -214,7 +202,19 @@ public class AssociationImpl<L extends R
      */
     private void locateLeftEndpoint(boolean notify) {
         synchronized (m_lock) {
-            m_left = locateEndpoint(m_leftRepository, m_filterLeft, m_left, (getAttribute(LEFT_CARDINALITY) == null ? 1 : Integer.parseInt(getAttribute(LEFT_CARDINALITY))), m_rightClass, notify);
+            List<L> newEndpoints = locateEndpoint(m_leftRepository, m_filterLeft, m_left, (getAttribute(LEFT_CARDINALITY) == null ? 1 : Integer.parseInt(getAttribute(LEFT_CARDINALITY))), m_rightClass, notify);
+            if (!newEndpoints.equals(m_left)) {
+                if (notify) {
+                    List<L> oldEndpoints = new ArrayList<L>(m_left);
+                    m_left = new ArrayList<L>(newEndpoints);
+                    Properties props = new Properties();
+                    props.put(EVENT_OLD, oldEndpoints);
+                    props.put(EVENT_NEW, newEndpoints);
+                    notifyChanged(props);
+                } else {
+                    m_left = newEndpoints;
+                }
+            }
         }
     }
 
@@ -225,7 +225,19 @@ public class AssociationImpl<L extends R
      */
     private void locateRightEndpoint(boolean notify) {
         synchronized (m_lock) {
-            m_right = locateEndpoint(m_rightRepository, m_filterRight, m_right, (getAttribute(RIGHT_CARDINALITY) == null ? 1 : Integer.parseInt(getAttribute(RIGHT_CARDINALITY))), m_leftClass, notify);
+            List<R> newEndpoints = locateEndpoint(m_rightRepository, m_filterRight, m_right, (getAttribute(RIGHT_CARDINALITY) == null ? 1 : Integer.parseInt(getAttribute(RIGHT_CARDINALITY))), m_leftClass, notify);
+            if (!newEndpoints.equals(m_right)) {
+                if (notify) {
+                    List<R> oldEndpoints = new ArrayList<R>(m_right);
+                    m_right = new ArrayList<R>(newEndpoints);
+                    Properties props = new Properties();
+                    props.put(EVENT_OLD, oldEndpoints);
+                    props.put(EVENT_NEW, newEndpoints);
+                    notifyChanged(props);
+                } else {
+                    m_right = newEndpoints;
+                }
+            }
         }
     }