Committed by
Gerrit Code Review
Symmertry issue on overridden equals method - fix
Change-Id: If19d09a31e02b6c1957fd07e052e7f295e4f0c7b
Showing
3 changed files
with
5 additions
and
3 deletions
| ... | @@ -87,7 +87,9 @@ public class OchPort extends DefaultPort { | ... | @@ -87,7 +87,9 @@ public class OchPort extends DefaultPort { |
| 87 | if (this == obj) { | 87 | if (this == obj) { |
| 88 | return true; | 88 | return true; |
| 89 | } | 89 | } |
| 90 | - if (obj instanceof OchPort) { | 90 | + |
| 91 | + // Subclass is considered as a change of identity, hence equals() will return false if class type don't match | ||
| 92 | + if (obj != null && getClass() == obj.getClass()) { | ||
| 91 | final OchPort other = (OchPort) obj; | 93 | final OchPort other = (OchPort) obj; |
| 92 | return Objects.equals(this.element().id(), other.element().id()) && | 94 | return Objects.equals(this.element().id(), other.element().id()) && |
| 93 | Objects.equals(this.number(), other.number()) && | 95 | Objects.equals(this.number(), other.number()) && | ... | ... |
| ... | @@ -71,7 +71,7 @@ public class OduCltPort extends DefaultPort { | ... | @@ -71,7 +71,7 @@ public class OduCltPort extends DefaultPort { |
| 71 | if (this == obj) { | 71 | if (this == obj) { |
| 72 | return true; | 72 | return true; |
| 73 | } | 73 | } |
| 74 | - if (obj instanceof OduCltPort) { | 74 | + if (obj != null && getClass() == obj.getClass()) { |
| 75 | final OduCltPort other = (OduCltPort) obj; | 75 | final OduCltPort other = (OduCltPort) obj; |
| 76 | return Objects.equals(this.element().id(), other.element().id()) && | 76 | return Objects.equals(this.element().id(), other.element().id()) && |
| 77 | Objects.equals(this.number(), other.number()) && | 77 | Objects.equals(this.number(), other.number()) && | ... | ... |
| ... | @@ -102,7 +102,7 @@ public class OmsPort extends DefaultPort { | ... | @@ -102,7 +102,7 @@ public class OmsPort extends DefaultPort { |
| 102 | if (this == obj) { | 102 | if (this == obj) { |
| 103 | return true; | 103 | return true; |
| 104 | } | 104 | } |
| 105 | - if (obj instanceof OmsPort) { | 105 | + if (obj != null && getClass() == obj.getClass()) { |
| 106 | final OmsPort other = (OmsPort) obj; | 106 | final OmsPort other = (OmsPort) obj; |
| 107 | return Objects.equals(this.element().id(), other.element().id()) && | 107 | return Objects.equals(this.element().id(), other.element().id()) && |
| 108 | Objects.equals(this.number(), other.number()) && | 108 | Objects.equals(this.number(), other.number()) && | ... | ... |
-
Please register or login to post a comment