mirror of https://github.com/apache/cloudstack.git
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) {
|
public boolean equals(Object that) {
|
||||||
if (this == that) {
|
if (this == that) {
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
if (that instanceof String) {
|
|
||||||
if (this.toString().equalsIgnoreCase((String)that)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (that instanceof BaseType) {
|
} else if (that instanceof BaseType) {
|
||||||
BaseType th = (BaseType)that;
|
BaseType th = (BaseType)that;
|
||||||
if (this.toString().equalsIgnoreCase(th.toString())) {
|
if (this.toString().equalsIgnoreCase(th.toString())) {
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,13 @@ public class ConfigKey<T> {
|
||||||
if (obj instanceof ConfigKey) {
|
if (obj instanceof ConfigKey) {
|
||||||
ConfigKey<?> that = (ConfigKey<?>)obj;
|
ConfigKey<?> that = (ConfigKey<?>)obj;
|
||||||
return this._name.equals(that._name);
|
return this._name.equals(that._name);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSameKeyAs(Object obj) {
|
||||||
|
if(this.equals(obj)) {
|
||||||
|
return true;
|
||||||
} else if (obj instanceof String) {
|
} else if (obj instanceof String) {
|
||||||
String key = (String)obj;
|
String key = (String)obj;
|
||||||
return key.equals(_name);
|
return key.equals(_name);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,13 @@ public class Ip implements Serializable, Comparable<Ip> {
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof Ip) {
|
if (obj instanceof Ip) {
|
||||||
return ip == ((Ip)obj).ip;
|
return ip == ((Ip)obj).ip;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSameAddressAs(Object obj) {
|
||||||
|
if (this.equals(obj)) {
|
||||||
|
return true;
|
||||||
} else if (obj instanceof String) {
|
} else if (obj instanceof String) {
|
||||||
return ip == NetUtils.ip2Long((String)obj);
|
return ip == NetUtils.ip2Long((String)obj);
|
||||||
} else if (obj instanceof Long) {
|
} else if (obj instanceof Long) {
|
||||||
|
|
|
||||||
|
|
@ -55,15 +55,23 @@ public class Ip4Address {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object that) {
|
public boolean equals(Object that) {
|
||||||
if (that instanceof String) { // Assume that is an ip4 address in String form
|
|
||||||
return _addr.equals(that);
|
if (that instanceof Ip4Address) {
|
||||||
} else if (that instanceof Ip4Address) {
|
|
||||||
Ip4Address ip4 = (Ip4Address)that;
|
Ip4Address ip4 = (Ip4Address)that;
|
||||||
return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
|
return this._addr.equals(ip4._addr) && (this._mac == ip4._mac || this._mac.equals(ip4._mac));
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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
|
@Override
|
||||||
public int hashCode(){
|
public int hashCode(){
|
||||||
return (int)(_mac.hashCode()*_addr.hashCode());
|
return (int)(_mac.hashCode()*_addr.hashCode());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue