Add an equals method to Contact.
authorDa Risk <darisk972@gmail.com>
Thu, 27 May 2010 01:27:29 +0200
changeset 755 de343f195f37
parent 754 151841f2b1a1
child 756 c86eb188de1c
Add an equals method to Contact. A contact is equals to an other if they got the same bare Jid.
src/com/beem/project/beem/service/Contact.java
--- a/src/com/beem/project/beem/service/Contact.java	Mon May 24 20:45:31 2010 +0200
+++ b/src/com/beem/project/beem/service/Contact.java	Thu May 27 01:27:29 2010 +0200
@@ -79,20 +79,14 @@
 
     private int mID;
     private int mStatus;
-    private String mJID;
+    private final String mJID;
     private String mSelectedRes;
     private String mMsgState;
     private List<String> mRes;
-    private List<String> mGroups;
+    private final List<String> mGroups = new ArrayList<String>();
     private String mName;
 
     /**
-     * Constructor.
-     */
-    public Contact() {
-    }
-
-    /**
      * Construct a contact from a parcel.
      * @param in parcel to use for construction
      */
@@ -104,7 +98,6 @@
 	mName = in.readString();
 	mMsgState = in.readString();
 	mRes = new ArrayList<String>();
-	mGroups = new ArrayList<String>();
 	in.readStringList(mRes);
 	in.readStringList(mGroups);
     }
@@ -123,7 +116,6 @@
 	mSelectedRes = res;
 	if (!"".equals(res))
 	    mRes.add(res);
-	mGroups = new ArrayList<String>();
     }
 
     /**
@@ -143,7 +135,6 @@
 	String res = StringUtils.parseResource(enduri);
 	mSelectedRes = res;
 	mRes.add(res);
-	mGroups = new ArrayList<String>();
     }
 
     /**
@@ -283,7 +274,8 @@
      * @param groups the mGroups to set
      */
     public void setGroups(List<String> groups) {
-	this.mGroups = groups;
+	mGroups.clear();
+	mGroups.addAll(groups);
     }
 
     /**
@@ -295,14 +287,6 @@
     }
 
     /**
-     * Set the Jabber ID of the contact.
-     * @param jid the jabber ID to set
-     */
-    public void setJID(String jid) {
-	mJID = jid;
-    }
-
-    /**
      * Set the resource of the contact.
      * @param resource to set.
      */
@@ -365,7 +349,6 @@
     public void setStatus(PresenceAdapter presence) {
 	mStatus = presence.getStatus();
 	mMsgState = presence.getStatusText();
-
     }
 
     /**
@@ -423,4 +406,14 @@
 	    build.append('/').append(mSelectedRes);
 	return build.toString();
     }
+
+    @Override
+    public boolean equals(Object other) {
+	if (!(other instanceof Contact) )
+	    return false;
+	if (other == this)
+	    return true;
+	Contact c = (Contact) other;
+	return c.getJID().equals(getJID());
+    }
 }