diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java index b8fb1f8cc63..f6ee74ec6cd 100755 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/CompetitorDTOImpl.java @@ -2,6 +2,15 @@ package com.sap.sailing.domain.common.dto; import java.io.Serializable; +/** + * Equality and hash code are based on the {@link #getIdAsString() ID}, the {@link #getSailID() sail number}, the + * {@link #getBoatClass() boat class} (whose equality and hash code, in turn, depends on its name) and the + * {@link #getThreeLetterIocCountryCode() IOC country code}. Note that the three latter properties are subject + * to change for a competitor while the ID remains unchanged. + * + * @author Axel Uhl (d043530) + * + */ public class CompetitorDTOImpl extends NamedDTO implements CompetitorDTO, Serializable { private static final long serialVersionUID = -4997852354821083154L; private String twoLetterIsoCountryCode; @@ -27,8 +36,11 @@ public class CompetitorDTOImpl extends NamedDTO implements CompetitorDTO, Serial @Override public int hashCode() { final int prime = 31; - int result = 1; - result = prime * getIdAsString().hashCode(); + int result = super.hashCode(); + result = prime * result + ((boatClass == null) ? 0 : boatClass.hashCode()); + result = prime * result + ((idAsString == null) ? 0 : idAsString.hashCode()); + result = prime * result + ((sailID == null) ? 0 : sailID.hashCode()); + result = prime * result + ((threeLetterIocCountryCode == null) ? 0 : threeLetterIocCountryCode.hashCode()); return result; } @@ -36,15 +48,30 @@ public class CompetitorDTOImpl extends NamedDTO implements CompetitorDTO, Serial public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) + if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CompetitorDTOImpl other = (CompetitorDTOImpl) obj; - if (getIdAsString() == null) { - if (other.getIdAsString() != null) + if (boatClass == null) { + if (other.boatClass != null) return false; - } else if (!getIdAsString().equals(other.getIdAsString())) + } else if (!boatClass.equals(other.boatClass)) + return false; + if (idAsString == null) { + if (other.idAsString != null) + return false; + } else if (!idAsString.equals(other.idAsString)) + return false; + if (sailID == null) { + if (other.sailID != null) + return false; + } else if (!sailID.equals(other.sailID)) + return false; + if (threeLetterIocCountryCode == null) { + if (other.threeLetterIocCountryCode != null) + return false; + } else if (!threeLetterIocCountryCode.equals(other.threeLetterIocCountryCode)) return false; return true; } diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java index f91b990cd9e..3ce385a3fd7 100755 --- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java +++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/dto/PreviousCompetitorDTOImpl.java @@ -1,5 +1,11 @@ package com.sap.sailing.domain.common.dto; +/** + * Equality and hash code are based on the index pointing into a previous leaderboard's competitors list. + * + * @author Axel Uhl (d043530) + * + */ public class PreviousCompetitorDTOImpl implements CompetitorDTO { private static final long serialVersionUID = 8820028699103040805L; private int indexInPreviousCompetitorList; @@ -14,6 +20,28 @@ public class PreviousCompetitorDTOImpl implements CompetitorDTO { protected int getIndexInPreviousCompetitorList() { return indexInPreviousCompetitorList; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + indexInPreviousCompetitorList; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PreviousCompetitorDTOImpl other = (PreviousCompetitorDTOImpl) obj; + if (indexInPreviousCompetitorList != other.indexInPreviousCompetitorList) + return false; + return true; + } @Override public String getTwoLetterIsoCountryCode() {