← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5401: Fixed equals/hashcode on ProgramInstance

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 5401 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-12-14 11:06:24 +0100
message:
  Fixed equals/hashcode on ProgramInstance
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramAttribute.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.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-api/src/main/java/org/hisp/dhis/message/Message.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java	2011-12-14 09:17:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/message/Message.java	2011-12-14 09:51:02 +0000
@@ -69,6 +69,12 @@
         this.sender = sender;
     }
     
+    @Override
+    public String getName()
+    {
+        return text;
+    }
+    
     public String getText()
     {
         return text;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2011-08-02 09:12:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/patient/Patient.java	2011-12-14 09:51:02 +0000
@@ -129,12 +129,14 @@
     {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((id == null) ? 0 : id.hashCode());
-        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());
+        
+        result = prime * result + ( ( id == null) ? 0 : id.hashCode() );
+        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;
     }
 
@@ -142,47 +144,80 @@
     public boolean equals( Object obj )
     {
         if ( this == obj )
+        {
             return true;
+        }
+        
         if ( obj == null )
+        {
             return false;
+        }
+        
         if ( getClass() != obj.getClass() )
+        {
             return false;
-        Patient other = (Patient) obj;
+        }
+        
+        final Patient other = (Patient) obj;
+        
         if ( birthDate == null )
         {
             if ( other.birthDate != null )
+            {
                 return false;
+            }
         }
         else if ( !birthDate.equals( other.birthDate ) )
+        {
             return false;
+        }
+        
         if ( firstName == null )
         {
             if ( other.firstName != null )
+            {
                 return false;
+            }
         }
         else if ( !firstName.equals( other.firstName ) )
+        {
             return false;
+        }
+        
         if ( gender == null )
         {
             if ( other.gender != null )
                 return false;
         }
         else if ( !gender.equals( other.gender ) )
+        {
             return false;
+        }
+        
         if ( lastName == null )
         {
             if ( other.lastName != null )
+            {
                 return false;
+            }
         }
         else if ( !lastName.equals( other.lastName ) )
+        {
             return false;
+        }
+        
         if ( middleName == null )
         {
             if ( other.middleName != null )
+            {
                 return false;
+            }
         }
         else if ( !middleName.equals( other.middleName ) )
+        {
             return false;
+        }
+        
         return true;
     }
 
@@ -393,7 +428,6 @@
         }
 
         return age;
-
     }
 
     public void setBirthDateFromAge( int age, char ageType )
@@ -407,6 +441,7 @@
         // Assumed relative to the 1st of January
         // todayCalendar.set( Calendar.DATE, 1 );
         // todayCalendar.set( Calendar.MONTH, Calendar.JANUARY );
+        
         if ( ageType == AGE_TYPE_YEAR )
         {
             todayCalendar.add( Calendar.YEAR, -1 * age );
@@ -464,19 +499,28 @@
             name = firstName;
             space = true;
         }
+        
         if ( middleName != null && middleName.length() != 0 )
         {
             if ( space )
+            {
                 name += " ";
+            }
+            
             name += middleName;
             space = true;
         }
+        
         if ( lastName != null && lastName.length() != 0 )
         {
             if ( space )
+            {
                 name += " ";
+            }
+            
             name += lastName;
         }
+        
         return name;
     }
 
@@ -519,12 +563,12 @@
     {
         switch ( dobType )
         {
-        case DOB_TYPE_VERIFIED:
-            return "Verified";
-        case DOB_TYPE_DECLARED:
-            return "Declared";
-        default:
-            return "Approxiated";
+            case DOB_TYPE_VERIFIED:
+                return "Verified";
+            case DOB_TYPE_DECLARED:
+                return "Declared";
+            default:
+                return "Approxiated";
         }
     }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramAttribute.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramAttribute.java	2011-07-21 08:26:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramAttribute.java	2011-12-14 10:06:24 +0000
@@ -80,17 +80,23 @@
     private Set<ProgramAttributeOption> attributeOptions;
 
     // -------------------------------------------------------------------------
-    // Constructors
-    // -------------------------------------------------------------------------
-
-    public ProgramAttribute()
-    {
-    }
-
-    // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
 
+    public void addAttributeOptions( ProgramAttributeOption option )
+    {
+        if ( attributeOptions == null )
+        {
+            attributeOptions = new HashSet<ProgramAttributeOption>();
+        }
+        
+        attributeOptions.add( option );
+    }
+
+    // -------------------------------------------------------------------------
+    // hashCode and equals
+    // -------------------------------------------------------------------------
+
     @Override
     public int hashCode()
     {
@@ -104,19 +110,34 @@
     public boolean equals( Object obj )
     {
         if ( this == obj )
+        {
             return true;
+        }
+        
         if ( obj == null )
+        {
             return false;
+        }
+        
         if ( getClass() != obj.getClass() )
+        {
             return false;
+        }
+            
         ProgramAttribute other = (ProgramAttribute) obj;
+        
         if ( name == null )
         {
             if ( other.name != null )
+            {
                 return false;
+            }
         }
         else if ( !name.equals( other.name ) )
+        {
             return false;
+        }
+        
         return true;
     }
 
@@ -173,12 +194,4 @@
     {
         this.attributeOptions = attributeOptions;
     }
-
-    public void addAttributeOptions( ProgramAttributeOption option )
-    {
-        if ( attributeOptions == null )
-            attributeOptions = new HashSet<ProgramAttributeOption>();
-        attributeOptions.add( option );
-    }
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2011-12-14 07:33:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramInstance.java	2011-12-14 10:00:44 +0000
@@ -83,29 +83,17 @@
     // hashCode and equals
     // -------------------------------------------------------------------------
 
-    @Override
-    public boolean equals( Object o )
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    /**
+     * @return the id
+     */
+    public int getId()
     {
-        if ( this == o )
-        {
-            return true;
-        }
-
-        if ( o == null )
-        {
-            return false;
-        }
-
-        if ( !(o instanceof ProgramInstance) )
-        {
-            return false;
-        }
-
-        final ProgramInstance other = (ProgramInstance) o;
-
-        return enrollmentDate.equals( other.getEnrollmentDate() ) && patient.equals( other.getPatient() )
-            && program.equals( other.getProgram() );
-
+        return id;
     }
 
     @Override
@@ -113,31 +101,84 @@
     {
         final int prime = 31;
         int result = 1;
-
-        result = result * prime + enrollmentDate.hashCode();
-        if ( patient != null )
-        {
-            result = result * prime + patient.hashCode();
-        }
-        else
-        {
-            result = result * prime + id;
-        }
-        result = result * prime + program.hashCode();
-
+        
+        result = prime * result + ( ( dateOfIncident == null) ? 0 : dateOfIncident.hashCode() );
+        result = prime * result + ( ( enrollmentDate == null) ? 0 : enrollmentDate.hashCode() );
+        result = prime * result + ( ( patient == null) ? 0 : patient.hashCode() );
+        result = prime * result + ( ( program == null) ? 0 : program.hashCode() );
+        
         return result;
     }
 
-    // -------------------------------------------------------------------------
-    // Getters and setters
-    // -------------------------------------------------------------------------
-
-    /**
-     * @return the id
-     */
-    public int getId()
+    @Override
+    public boolean equals( Object obj )
     {
-        return id;
+        if ( this == obj )
+        {
+            return true;
+        }
+        
+        if ( obj == null )
+        {
+            return false;
+        }
+        
+        if ( getClass() != obj.getClass() )
+        {
+            return false;
+        }
+        
+        final ProgramInstance other = (ProgramInstance) obj;
+        
+        if ( dateOfIncident == null )
+        {
+            if ( other.dateOfIncident != null )
+            {
+                return false;
+            }
+        }
+        else if ( !dateOfIncident.equals( other.dateOfIncident ) )
+        {
+            return false;
+        }
+        
+        if ( enrollmentDate == null )
+        {
+            if ( other.enrollmentDate != null )
+            {
+                return false;
+            }
+        }
+        else if ( !enrollmentDate.equals( other.enrollmentDate ) )
+        {
+            return false;
+        }
+        
+        if ( patient == null )
+        {
+            if ( other.patient != null )
+            {
+                return false;
+            }
+        }
+        else if ( !patient.equals( other.patient ) )
+        {
+            return false;
+        }
+        
+        if ( program == null )
+        {
+            if ( other.program != null )
+            {
+                return false;
+            }
+        }
+        else if ( !program.equals( other.program ) )
+        {
+            return false;
+        }
+        
+        return true;
     }
 
     /**
@@ -276,7 +317,6 @@
 
     public ProgramStageInstance getProgramStageInstanceByStage( int stage )
     {
-
         int count = 1;
 
         for ( ProgramStageInstance programInstanceStage : programStageInstances )
@@ -292,7 +332,5 @@
         }
 
         return null;
-
     }
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramValidation.java	2011-12-14 10:06:24 +0000
@@ -93,9 +93,9 @@
     {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((leftSide == null) ? 0 : leftSide.hashCode());
-        result = prime * result + ((program == null) ? 0 : program.hashCode());
-        result = prime * result + ((rightSide == null) ? 0 : rightSide.hashCode());
+        result = prime * result + ( ( leftSide == null ) ? 0 : leftSide.hashCode() );
+        result = prime * result + ( ( program == null ) ? 0 : program.hashCode() );
+        result = prime * result + ( ( rightSide == null)  ? 0 : rightSide.hashCode() );
         return result;
     }
 
@@ -103,33 +103,58 @@
     public boolean equals( Object obj )
     {
         if ( this == obj )
+        {
             return true;
+        }
+        
         if ( obj == null )
+        {
             return false;
+        }
+        
         if ( getClass() != obj.getClass() )
+        {
             return false;
+        }
+        
         ProgramValidation other = (ProgramValidation) obj;
+        
         if ( leftSide == null )
         {
             if ( other.leftSide != null )
+            {
                 return false;
+            }
         }
         else if ( !leftSide.equals( other.leftSide ) )
+        {
             return false;
+        }
+        
         if ( program == null )
         {
             if ( other.program != null )
+            {
                 return false;
+            }
         }
         else if ( !program.equals( other.program ) )
+        {
             return false;
+        }
+        
         if ( rightSide == null )
         {
             if ( other.rightSide != null )
+            {
                 return false;
+            }
         }
         else if ( !rightSide.equals( other.rightSide ) )
+        {
             return false;
+        }
+        
         return true;
     }