← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10576: [mobile] rewrite equal() method and implement hasCode() method for mobile objects

 

------------------------------------------------------------
revno: 10576
committer: Long <Long@Long-Laptop>
branch nick: dhis2
timestamp: Tue 2013-04-16 14:52:25 +0700
message:
  [mobile] rewrite equal() method and implement hasCode() method for mobile objects
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Beneficiary.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Beneficiary.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Beneficiary.java	2013-02-25 06:32:56 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Beneficiary.java	2013-04-16 07:52:25 +0000
@@ -279,9 +279,9 @@
         {
             dout.writeBoolean( false );
         }
-        //doesn't transfer blood group to client
-            dout.writeBoolean( false );
-        
+        // doesn't transfer blood group to client
+        dout.writeBoolean( false );
+
         if ( registrationDate != null )
         {
             dout.writeBoolean( true );
@@ -334,8 +334,97 @@
     @Override
     public boolean equals( Object otherObject )
     {
-        Beneficiary otherBeneficiary = (Beneficiary) otherObject;
-        return this.getId() == otherBeneficiary.getId();
+        if ( this == otherObject )
+        {
+            return true;
+        }
+
+        if ( otherObject == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != otherObject.getClass() )
+        {
+            return false;
+        }
+        
+        final Beneficiary otherBeneficiary = (Beneficiary) otherObject;
+        
+        if ( birthDate == null )
+        {
+            if ( otherBeneficiary.birthDate != null )
+            {
+                return false;
+            }
+        }
+        else if ( !birthDate.equals( otherBeneficiary.birthDate ) )
+        {
+            return false;
+        }
+        
+        if ( firstName == null )
+        {
+            if ( otherBeneficiary.firstName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !firstName.equals( otherBeneficiary.firstName ) )
+        {
+            return false;
+        }
+
+        if ( gender == null )
+        {
+            if ( otherBeneficiary.gender != null )
+                return false;
+        }
+        else if ( !gender.equals( otherBeneficiary.gender ) )
+        {
+            return false;
+        }
+
+        if ( lastName == null )
+        {
+            if ( otherBeneficiary.lastName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !lastName.equals( otherBeneficiary.lastName ) )
+        {
+            return false;
+        }
+
+        if ( middleName == null )
+        {
+            if ( otherBeneficiary.middleName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !middleName.equals( otherBeneficiary.middleName ) )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        
+        result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
+        result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
+        result = prime * result + ((gender == null) ? 0 : gender.hashCode());
+        result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
+        result = prime * result + ((middleName == null) ? 0 : middleName.hashCode());
+
+        return result;
     }
 
     @Override
@@ -380,8 +469,8 @@
         {
             dout.writeBoolean( false );
         }
-        //doesn't transfer blood group to client
-            dout.writeBoolean( false );
+        // doesn't transfer blood group to client
+        dout.writeBoolean( false );
 
         if ( registrationDate != null )
         {
@@ -464,8 +553,8 @@
         {
             dout.writeBoolean( false );
         }
-        //doesn't transfer blood group to client
-            dout.writeBoolean( false );
+        // doesn't transfer blood group to client
+        dout.writeBoolean( false );
 
         if ( registrationDate != null )
         {
@@ -511,6 +600,6 @@
         throws IOException
     {
         // TODO Auto-generated method stub
-        
+
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java	2013-04-15 15:12:27 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataSet.java	2013-04-16 07:52:25 +0000
@@ -212,9 +212,26 @@
     }
 
     @Override
-    public boolean equals( Object obj )
-    {
-        if ( ((DataSet) obj).getId() == this.getId() )
+    public int hashCode()
+    {
+        return this.getId();
+    }
+
+    @Override
+    public boolean equals( Object otherObject )
+    {
+
+        if ( this == otherObject )
+        {
+            return true;
+        }
+
+        if ( otherObject == null )
+        {
+            return false;
+        }
+
+        if ( ((DataSet) otherObject).getId() == this.getId() )
             return true;
         return false;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java	2013-04-15 15:12:27 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/LWUITmodel/Patient.java	2013-04-16 07:52:25 +0000
@@ -34,8 +34,6 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-
-import org.hisp.dhis.api.mobile.model.Beneficiary;
 import org.hisp.dhis.api.mobile.model.DataStreamSerializable;
 import org.hisp.dhis.api.mobile.model.PatientAttribute;
 import org.hisp.dhis.api.mobile.model.PatientIdentifier;
@@ -484,8 +482,97 @@
     @Override
     public boolean equals( Object otherObject )
     {
-        Beneficiary otherBeneficiary = (Beneficiary) otherObject;
-        return this.getId() == otherBeneficiary.getId();
+        if ( this == otherObject )
+        {
+            return true;
+        }
+
+        if ( otherObject == null )
+        {
+            return false;
+        }
+
+        if ( getClass() != otherObject.getClass() )
+        {
+            return false;
+        }
+
+        final Patient otherPatient = (Patient) otherObject;
+
+        if ( birthDate == null )
+        {
+            if ( otherPatient.birthDate != null )
+            {
+                return false;
+            }
+        }
+        else if ( !birthDate.equals( otherPatient.birthDate ) )
+        {
+            return false;
+        }
+
+        if ( firstName == null )
+        {
+            if ( otherPatient.firstName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !firstName.equals( otherPatient.firstName ) )
+        {
+            return false;
+        }
+
+        if ( gender == null )
+        {
+            if ( otherPatient.gender != null )
+                return false;
+        }
+        else if ( !gender.equals( otherPatient.gender ) )
+        {
+            return false;
+        }
+
+        if ( lastName == null )
+        {
+            if ( otherPatient.lastName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !lastName.equals( otherPatient.lastName ) )
+        {
+            return false;
+        }
+
+        if ( middleName == null )
+        {
+            if ( otherPatient.middleName != null )
+            {
+                return false;
+            }
+        }
+        else if ( !middleName.equals( otherPatient.middleName ) )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+
+        result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
+        result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
+        result = prime * result + ((gender == null) ? 0 : gender.hashCode());
+        result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
+        result = prime * result + ((middleName == null) ? 0 : middleName.hashCode());
+
+        return result;
     }
 
     @Override