summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/main
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2019-05-29 12:22:27 +0200
committerDominik Mizyn <d.mizyn@samsung.com>2019-05-29 16:37:08 +0200
commit788e99d836a75badf45dce96358d184aa9e549f2 (patch)
treed10fa98f8e0a162c2488f2d32bf67b280ad958d5 /ecomp-portal-BE-common/src/main
parentba546e970d779a5e87a07b3058a85e1446c39129 (diff)
Sonar: Reduce cyclomatic complexity
Reduce the number of conditional operators for equals(). Improve testEquals() to better cover this method. This patch also: * immediately returns expression instead of assigning it to the temporary variable "str", * adds the "@Override" annotation above equals() method signature. Issue-ID: PORTAL-595 Change-Id: I15f600acce873eb3f22cc405d06a50890c7e87c3 Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
index 3470a9e3..c52bc303 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserApp.java
@@ -61,13 +61,12 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
}
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() {
@@ -102,6 +101,7 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
this.priority = priority;
}
+ @Override
public boolean equals(Object other) {
if ((this == other))
return true;
@@ -111,10 +111,10 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
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() {
@@ -135,4 +135,19 @@ public class EPUserApp extends DomainVo implements java.io.Serializable, Compara
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());
+ }
}