私は自分自身のクラスを持っています。そのクラスは、その内部に他のオブジェクトのセットを持つオブジェクトです。私は曲線の2つのコレクションを持っていたときに私の質問は、どのように私がチェックするためにこれらを比較しないさJava独自のオブジェクトと.equalsのコレクション
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;
}
}
:
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;
}
}
CurvePointクラスimplments匹敵するともそのようなequalsメソッドをオーバーライドするすなわち 彼らが等しいならば?私が.equalsを使うとき、常にfalseを返すだけです。両方のコレクションをループせずにそれを行う方法はありますか?
equals()標準コレクションの実装は、常にすべての子を比較します。他のすべてはひどいです –