Skip to content

Commit 3462944

Browse files
committed
findbugs equals(obj) implementations go against the contract these are removed from the call into separate calls
Signed-off-by: Daan Hoogland <daan@onecht.net>
1 parent 4bba499 commit 3462944

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

engine/storage/src/org/apache/cloudstack/storage/BaseType.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@ public abstract class BaseType {
2323
public boolean equals(Object that) {
2424
if (this == that) {
2525
return true;
26-
}
27-
if (that instanceof String) {
28-
if (this.toString().equalsIgnoreCase((String)that)) {
29-
return true;
30-
}
3126
} else if (that instanceof BaseType) {
3227
BaseType th = (BaseType)that;
3328
if (this.toString().equalsIgnoreCase(th.toString())) {
3429
return true;
3530
}
36-
} else {
37-
return false;
31+
}
32+
return false;
33+
}
34+
35+
public boolean isSameTypeAs(Object that) {
36+
if (this.equals(that)){
37+
return true;
38+
}
39+
if (that instanceof String) {
40+
if (this.toString().equalsIgnoreCase((String)that)) {
41+
return true;
42+
}
3843
}
3944
return false;
4045
}

framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ public boolean equals(Object obj) {
122122
if (obj instanceof ConfigKey) {
123123
ConfigKey<?> that = (ConfigKey<?>)obj;
124124
return this._name.equals(that._name);
125+
}
126+
return false;
127+
}
128+
129+
public boolean isSameKeyAs(Object obj) {
130+
if(this.equals(obj)) {
131+
return true;
125132
} else if (obj instanceof String) {
126133
String key = (String)obj;
127134
return key.equals(_name);

utils/src/com/cloud/utils/net/Ip.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public int hashCode() {
7575
public boolean equals(Object obj) {
7676
if (obj instanceof Ip) {
7777
return ip == ((Ip)obj).ip;
78+
}
79+
return false;
80+
}
81+
82+
public boolean isSameAddressAs(Object obj) {
83+
if (this.equals(obj)) {
84+
return true;
7885
} else if (obj instanceof String) {
7986
return ip == NetUtils.ip2Long((String)obj);
8087
} else if (obj instanceof Long) {

utils/src/com/cloud/utils/net/Ip4Address.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,23 @@ public long toLong() {
5555

5656
@Override
5757
public boolean equals(Object that) {
58-
if (that instanceof String) { // Assume that is an ip4 address in String form
59-
return _addr.equals(that);
60-
} else if (that instanceof Ip4Address) {
58+
59+
if (that instanceof Ip4Address) {
6160
Ip4Address ip4 = (Ip4Address)that;
6261
return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
6362
} else {
6463
return false;
6564
}
6665
}
66+
67+
public boolean isSameAddressAs(Object other) {
68+
if (other instanceof String) { // Assume that is an ip4 address in String form
69+
return _addr.equals(other);
70+
} else {
71+
return this.equals(other);
72+
}
73+
}
74+
6775
@Override
6876
public int hashCode(){
6977
return (int)(_mac.hashCode()*_addr.hashCode());

0 commit comments

Comments
 (0)