내 안에는 다른 개체가 포함 된 개체가 있습니다. CurvePoint 클래스 implments 대등는 equals 메소드과 같이 우선 즉Java 자신의 개체 및 .equals 컬렉션
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;
}
}
:
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;
}
}
나는, 곡선의 2 명 컬렉션을 때 내 질문에 내가 확인하려면 다음을 비교합니까 어떻게 그들이 동등하다면? .equals를 사용할 때 항상 false를 반환합니다. 두 컬렉션 모두를 반복하지 않고 수행하는 방법이 있습니까?
아니요. 표준 콜렉션의 equals() 구현은 항상 모든 자식을 비교합니다. 다른 모든 것은 끔찍합니다. –