Simpler way to sort members in Group.addMember
----------------------------------------------

         Key: HEDERA-26
         URL: https://forge.continuent.org/jira/browse/HEDERA-26
     Project: Hedera
        Type: Improvement
    Versions:  Hedera 1.5.4    
    Reporter: Jeff Mesnil
 Assigned to: Damian Arregui 
    Priority: Trivial


When adding a Member in Group.addMember(Member m), we need to sort the list.
The code could delegate all this sorting to Collections.sort(Collection) since 
the Member are Comparable:

Index: src/common/org/continuent/hedera/common/Group.java
===================================================================
RCS file: 
/cvsroot/hedera/hedera/src/common/org/continuent/hedera/common/Group.java,v
retrieving revision 1.3
diff -u -r1.3 Group.java
--- src/common/org/continuent/hedera/common/Group.java  7 Nov 2006 10:17:19 
-0000       1.3
+++ src/common/org/continuent/hedera/common/Group.java  23 Nov 2006 09:09:00 
-0000
@@ -22,6 +22,7 @@

 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -97,24 +98,10 @@
    *
    * @param m the new group member
    */
-  public void addMember(Member m)
+  public synchronized void addMember(Member m)
   {
-    IpAddress addr = m.getAddress();
-    synchronized (members)
-    {
-      int size = members.size();
-      for (int i = 0; i < size; i++)
-      {
-        Member member = (Member) members.get(i);
-        if (addr.compareTo(member.getAddress()) < 0)
-        {
-          members.add(i, m);
-          return;
-        }
-      }
-      // This is the last element
-      members.add(m);
-    }
+    members.add(m);
+    Collections.sort(members);
   }

   /**


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   https://forge.continuent.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


_______________________________________________
Hedera mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/hedera

Reply via email to