← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8518: Removed poor hashcode/equals method impl from User class, will fallback to impl in BaseIdentifiab...

 

------------------------------------------------------------
revno: 8518
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-10-14 19:22:01 +0200
message:
  Removed poor hashcode/equals method impl from User class, will fallback to impl in BaseIdentifiableObject. Should propably do this for all identifiable objects.
removed:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupServiceTest.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/common/BaseIdentifiableObject.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java	2012-10-09 10:30:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/BaseIdentifiableObject.java	2012-10-14 17:22:01 +0000
@@ -194,20 +194,9 @@
         this.displayName = displayName;
     }
 
-    @Override
-    public boolean equals( Object o )
-    {
-        if ( this == o ) return true;
-        if ( o == null || getClass() != o.getClass() ) return false;
-
-        BaseIdentifiableObject that = (BaseIdentifiableObject) o;
-
-        if ( code != null ? !code.equals( that.code ) : that.code != null ) return false;
-        if ( name != null ? !name.equals( that.name ) : that.name != null ) return false;
-        if ( uid != null ? !uid.equals( that.uid ) : that.uid != null ) return false;
-
-        return true;
-    }
+    // -------------------------------------------------------------------------
+    // hashCode and equals
+    // -------------------------------------------------------------------------
 
     @Override
     public int hashCode()
@@ -220,6 +209,36 @@
         return result;
     }
 
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        
+        if ( o == null || getClass() != o.getClass() ) return false;
+
+        BaseIdentifiableObject that = (BaseIdentifiableObject) o;
+
+        if ( uid != null ? !uid.equals( that.uid ) : that.uid != null )
+        {
+            return false;
+        }
+
+        if ( code != null ? !code.equals( that.code ) : that.code != null )
+        {
+            return false;
+        }
+        
+        if ( name != null ? !name.equals( that.name ) : that.name != null )
+        {
+            return false;
+        }
+        
+        return true;
+    }
+
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
@@ -299,8 +318,8 @@
     @Override
     public String toString()
     {
-        return "{" + "id=" + id + ", uid='" + uid + '\'' + ", code='" +
-            code + '\'' + ", name='" + name + '\'' + ", lastUpdated=" + lastUpdated + "}";
+        return "{" + "id=" + getId() + ", uid='" + getUid() + '\'' + ", code='" +
+            getCode() + '\'' + ", name='" + getName() + '\'' + ", lastUpdated=" + getLastUpdated() + "}";
     }
 
     @Override

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2012-10-06 08:45:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java	2012-10-14 17:22:01 +0000
@@ -112,101 +112,9 @@
     private Set<AttributeValue> attributeValues = new HashSet<AttributeValue>();
 
     // -------------------------------------------------------------------------
-    // hashCode and equals
-    // -------------------------------------------------------------------------
-
-    @Override
-    public int hashCode()
-    {
-        final int prime = 31;
-
-        int result = 1;
-
-        result = prime * result + ((email == null) ? 0 : email.hashCode());
-        result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
-        result = prime * result + ((phoneNumber == null) ? 0 : phoneNumber.hashCode());
-        result = prime * result + ((surname == null) ? 0 : surname.hashCode());
-
-        return result;
-    }
-
-    // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
 
-    // TODO fix, users might very well have the same name, should use
-    // credentials
-
-    @Override
-    public boolean equals( Object object )
-    {
-        if ( this == object )
-        {
-            return true;
-        }
-        if ( object == null )
-        {
-            return false;
-        }
-
-        if ( getClass() != object.getClass() )
-        {
-            return false;
-        }
-
-        User other = (User) object;
-
-        if ( firstName == null )
-        {
-            if ( other.firstName != null )
-            {
-                return false;
-            }
-        }
-        else if ( !firstName.equals( other.firstName ) )
-        {
-            return false;
-        }
-
-        if ( surname == null )
-        {
-            if ( other.surname != null )
-            {
-                return false;
-            }
-        }
-        else if ( !surname.equals( other.surname ) )
-        {
-            return false;
-        }
-
-        if ( email == null )
-        {
-            if ( other.email != null )
-            {
-                return false;
-            }
-        }
-        else if ( !email.equals( other.email ) )
-        {
-            return false;
-        }
-
-        if ( phoneNumber == null )
-        {
-            if ( other.phoneNumber != null )
-            {
-                return false;
-            }
-        }
-        else if ( !phoneNumber.equals( other.phoneNumber ) )
-        {
-            return false;
-        }
-
-        return true;
-    }
-
     public void addOrganisationUnit( OrganisationUnit unit )
     {
         organisationUnits.add( unit );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupServiceTest.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupServiceTest.java	2012-10-14 17:22:01 +0000
@@ -37,6 +37,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.hisp.dhis.DhisSpringTest;
 import org.junit.Test;
 
 /**
@@ -44,13 +45,28 @@
  * @version $Id$
  */
 public class UserGroupServiceTest
-    extends UserGroupTest
+    extends DhisSpringTest
 {
+    private UserGroupService userGroupService;
+    
+    private User user1;
+    private User user2;    
+    private User user3;
+    
     @Override
     public void setUpTest()
         throws Exception
     {
-        setUpUserGroupTest();
+        userService = (UserService) getBean( UserService.ID );
+        userGroupService = (UserGroupService) getBean( UserGroupService.ID );
+
+        user1 = createUser( 'A' );
+        user2 = createUser( 'B' );
+        user3 = createUser( 'C' );
+        
+        userService.addUser( user1 );
+        userService.addUser( user2 );
+        userService.addUser( user3 );
     }
 
     // -------------------------------------------------------------------------

=== removed file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupTest.java	2011-01-04 04:11:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserGroupTest.java	1970-01-01 00:00:00 +0000
@@ -1,64 +0,0 @@
-package org.hisp.dhis.user;
-
-/*
- * Copyright (c) 2004-2008, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.DhisSpringTest;
-
-/**
- * @author Dang Duy Hieu
- * @version $Id$
- */
-public abstract class UserGroupTest
-    extends DhisSpringTest
-{
-    protected UserGroupService userGroupService;
-    
-    protected User user1;
-    
-    protected User user2;
-    
-    protected User user3;
-
-    public void setUpUserGroupTest()
-        throws Exception
-    {
-        userGroupService = (UserGroupService) getBean( UserGroupService.ID );
-
-        // ---------------------------------------------------------------------
-        // Setup User
-        // ---------------------------------------------------------------------
-
-        user1 = createUser( 'A' );
-        user2 = createUser( 'B' );
-        user3 = createUser( 'C' );
-        
-        user1.setId( 1 );
-        user2.setId( 2 );
-        user3.setId( 3 );
-    }
-}