Review equality tests with classes employing pimpl idiom
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
JQuantLib |
New
|
Medium
|
Unassigned |
Bug Description
This tasks consists of finding and review classes which are exposing methods such like
* equals
* eq
* ne
It's critical we review the way equality is being implemented by certain classes, in particular those classes exposing some kind of "eq" method or overriding Object#equals method.
Observe that 'in general' Object#hashCode() must be overriden when Object#equals() is overridden.
In particular, the snippet of code below shows an example of how hashCode() and equals() must be implemented when the pimpl idiom is being employed. There's also an example of how Object#toString() must be implemented.
//
// overrides Object
//
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((impl_ == null) ? 0 : impl_.hashCode());
result = prime * result + ((impl_ == null) ? 0 : name().hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null || !(obj instanceof DayCounter)) {
return false;
}
final DayCounter other = (DayCounter) obj;
if (this.empty() && other.empty()) {
return true;
}
if (this.name(
return true;
}
return false;
}
@Override
public String toString() {
return (impl_ == null) ? "null" : impl_.name();
}
=============
Relationships
=============
related to http://
child of http://
Dropping back to the pot.
Feel free to assign to yourself :)
Cheers
Richard Gomes