I have my own class of which is an object with a set of other objects inside of it. i.e.
public class Curve{
@Override
public Collection<CurvePoint> getCurvePoints() {
return curvePoints;
}
@Override
public boolean equals(Object other) {
if (other instanceof Curve) {
Curve otherCurve = (Curve) other;
return getCurvePoints().equals(otherCurve.getCurvePoints());
}
return false;
}
}
where the CurvePoint class implments Comparable and also overrides the equals method like so:
public class CurvePoint implements ICurvePoint, Comparable<CurvePoint> {
@Override
public int compareTo(CurvePointother) {
return getSnapDate().compareTo(other.getSnapDate());
}
@Override
public boolean equals(Object other) {
if (other instanceof CurvePoint) {
CurvePointotherPoint = (CurvePoint) other;
return (getId().equals(otherPoint.getId())
&& getBid().getRate() == otherPoint.getBid().getRate()
&& getOffer().getRate() == otherPoint.getOffer().getRate() && getMid()
.getRate() == otherPoint.getMid().getRate());
}
return false;
}
}
My question is when I have a 2 collections of Curve, how do I compare these to check if they equal? When I use the .equals it always just returns false, is there a way to do it without looping through both collections?