Merge "Sonar: Reduce cyclomatic complexity"
authorSunder Tattavarada <statta@research.att.com>
Mon, 17 Jun 2019 15:51:58 +0000 (15:51 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 17 Jun 2019 15:51:58 +0000 (15:51 +0000)
1  2 
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java

@@@ -37,7 -37,6 +37,7 @@@
   */
  package org.onap.portalapp.portal.domain;
  
 +import javax.validation.Valid;
  import org.onap.portalsdk.core.domain.support.DomainVo;
  
  @SuppressWarnings("rawtypes")
@@@ -46,9 -45,7 +46,9 @@@ public class EPUserApp extends DomainV
        private static final long serialVersionUID = 1L;
        
        private Long userId;
 +      @Valid
        private EPApp app;
 +      @Valid
        private EPRole role;
        private Integer priority;
        
        }
        
        public Long getAppRoleId() {
-               return (role.getAppRoleId() == null) ? null : role.getAppRoleId();
+               return this.role.getAppRoleId();
        }
                
        @Override 
        public String toString() {
-               String str = "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
-               return str;
+               return "[u: "+getUserId()+"; a: "+getAppId()+", r: "+getRoleId()+"; appRoleId: "+getAppRoleId()+"]";
        }
        
        public Long getUserId() {
                this.priority = priority;
        }
  
+       @Override
        public boolean equals(Object other) {
                if ((this == other))
                        return true;
                        return false;
                EPUserApp castOther = (EPUserApp) other;
  
-               return (this.getUserId().equals(castOther.getUserId()))
-                               && (this.getApp().getId().equals(castOther.getApp().getId()))
-                               && (this.getRole().getId().equals(castOther.getRole().getId()))
-                               && ((this.priority==null && castOther.getPriority()==null) || this.getPriority().equals(castOther.getPriority()));
+               return (otherUserIdIsSameAsThisUserId(castOther))
+                               && (otherAppIdIsSameAsThis(castOther))
+                               && (otherRoleIsSameAsThis(castOther))
+                               && (otherPriorityIsSameAsThis(castOther));
        }
  
        public int hashCode() {
  
            return c1.compareTo(c2);
        }
+       private boolean otherPriorityIsSameAsThis(EPUserApp other){
+               return (this.priority==null && other.getPriority()==null) || this.getPriority().equals(other.getPriority());
+       }
+       private boolean otherRoleIsSameAsThis(EPUserApp other){
+               return this.getRole().getId().equals(other.getRole().getId());
+       }
+       private boolean otherAppIdIsSameAsThis(EPUserApp other){
+               return this.getApp().getId().equals(other.getApp().getId());
+       }
+       private boolean otherUserIdIsSameAsThisUserId(EPUserApp other){
+               return this.getUserId().equals(other.getUserId());
+       }
  }