From 2b2647abb3ffe8274557c302b4de420f8c2f88d6 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 7 Mar 2016 11:44:10 +0100 Subject: [PATCH] Reduce cyclomatic complexity Reduces number of branches in methods. Change-Id: I79e2b453dd82d0baf1ac3b8c75dea31c7fca4523 Signed-off-by: Robert Varga --- .../yang/model/util/MustDefinitionImpl.java | 20 ++++------------ .../model/util/PatternConstraintImpl.java | 24 ++++--------------- .../yang/model/util/RangeConstraintImpl.java | 20 +++------------- .../UnknownEffectiveStatementImpl.java | 21 ++++------------ 4 files changed, 15 insertions(+), 70 deletions(-) diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImpl.java index d361fa98c6..90b64767a3 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/MustDefinitionImpl.java @@ -84,7 +84,7 @@ public final class MustDefinitionImpl implements MustDefinition { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Objects.hashCode(mustStr); + result = prime * result + mustStr.hashCode(); result = prime * result + Objects.hashCode(description); result = prime * result + Objects.hashCode(reference); return result; @@ -95,28 +95,16 @@ public final class MustDefinitionImpl implements MustDefinition { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof MustDefinitionImpl)) { return false; } final MustDefinitionImpl other = (MustDefinitionImpl) obj; - if (!Objects.equals(mustStr, other.mustStr)) { - return false; - } - if (!Objects.equals(description, other.description)) { - return false; - } - if (!Objects.equals(reference, other.reference)) { - return false; - } - return true; + return mustStr.equals(other.mustStr) && Objects.equals(description, other.description) + && Objects.equals(reference, other.reference); } @Override public String toString() { return mustStr; } - } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java index eecc2a01f5..4b33f20772 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/PatternConstraintImpl.java @@ -89,29 +89,13 @@ final class PatternConstraintImpl implements PatternConstraint, Immutable { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof PatternConstraintImpl)) { return false; } final PatternConstraintImpl other = (PatternConstraintImpl) obj; - if (!Objects.equals(description, other.description)) { - return false; - } - if (!Objects.equals(errorAppTag, other.errorAppTag)) { - return false; - } - if (!Objects.equals(errorMessage, other.errorMessage)) { - return false; - } - if (!Objects.equals(reference, other.reference)) { - return false; - } - if (!Objects.equals(regex, other.regex)) { - return false; - } - return true; + return Objects.equals(description, other.description) && Objects.equals(errorAppTag, other.errorAppTag) + && Objects.equals(errorMessage, other.errorMessage) && Objects.equals(reference, other.reference) + && Objects.equals(regex, other.regex); } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java index f8db087052..2bf3b32ddb 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/RangeConstraintImpl.java @@ -96,26 +96,12 @@ final class RangeConstraintImpl implements RangeConstraint, Immutable { if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof RangeConstraintImpl)) { return false; } final RangeConstraintImpl other = (RangeConstraintImpl) obj; - if (!Objects.equals(description, other.description)) { - return false; - } - if (!Objects.equals(max, other.max)) { - return false; - } - if (!Objects.equals(min, other.min)) { - return false; - } - if (!Objects.equals(reference, other.reference)) { - return false; - } - return true; + return Objects.equals(description, other.description) && Objects.equals(max, other.max) + && Objects.equals(min, other.min) && Objects.equals(reference, other.reference); } @Override diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java index 2ee3f8283d..6e197561dc 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/UnknownEffectiveStatementImpl.java @@ -67,25 +67,12 @@ public final class UnknownEffectiveStatementImpl extends UnknownEffectiveStateme if (this == obj) { return true; } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { + if (!(obj instanceof UnknownEffectiveStatementImpl)) { return false; } UnknownEffectiveStatementImpl other = (UnknownEffectiveStatementImpl) obj; - if (!Objects.equals(maybeQNameArgument, other.maybeQNameArgument)) { - return false; - } - if (!Objects.equals(path, other.path)) { - return false; - } - if (!Objects.equals(getNodeType(), other.getNodeType())) { - return false; - } - if (!Objects.equals(getNodeParameter(), other.getNodeParameter())) { - return false; - } - return true; + return Objects.equals(maybeQNameArgument, other.maybeQNameArgument) && Objects.equals(path, other.path) + && Objects.equals(getNodeType(), other.getNodeType()) + && Objects.equals(getNodeParameter(), other.getNodeParameter()); } } -- 2.36.6