mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
4bba499412
commit
34629446b6
@ -23,18 +23,23 @@ public abstract class BaseType {
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that instanceof String) {
|
||||
if (this.toString().equalsIgnoreCase((String)that)) {
|
||||
return true;
|
||||
}
|
||||
} else if (that instanceof BaseType) {
|
||||
BaseType th = (BaseType)that;
|
||||
if (this.toString().equalsIgnoreCase(th.toString())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSameTypeAs(Object that) {
|
||||
if (this.equals(that)){
|
||||
return true;
|
||||
}
|
||||
if (that instanceof String) {
|
||||
if (this.toString().equalsIgnoreCase((String)that)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -122,6 +122,13 @@ public class ConfigKey<T> {
|
||||
if (obj instanceof ConfigKey) {
|
||||
ConfigKey<?> that = (ConfigKey<?>)obj;
|
||||
return this._name.equals(that._name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSameKeyAs(Object obj) {
|
||||
if(this.equals(obj)) {
|
||||
return true;
|
||||
} else if (obj instanceof String) {
|
||||
String key = (String)obj;
|
||||
return key.equals(_name);
|
||||
|
||||
@ -75,6 +75,13 @@ public class Ip implements Serializable, Comparable<Ip> {
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Ip) {
|
||||
return ip == ((Ip)obj).ip;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSameAddressAs(Object obj) {
|
||||
if (this.equals(obj)) {
|
||||
return true;
|
||||
} else if (obj instanceof String) {
|
||||
return ip == NetUtils.ip2Long((String)obj);
|
||||
} else if (obj instanceof Long) {
|
||||
|
||||
@ -55,15 +55,23 @@ public class Ip4Address {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that instanceof String) { // Assume that is an ip4 address in String form
|
||||
return _addr.equals(that);
|
||||
} else if (that instanceof Ip4Address) {
|
||||
|
||||
if (that instanceof Ip4Address) {
|
||||
Ip4Address ip4 = (Ip4Address)that;
|
||||
return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSameAddressAs(Object other) {
|
||||
if (other instanceof String) { // Assume that is an ip4 address in String form
|
||||
return _addr.equals(other);
|
||||
} else {
|
||||
return this.equals(other);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return (int)(_mac.hashCode()*_addr.hashCode());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user