I am using hibernate and id... is used for persistence (which is why it is omitted in comparison). (Also, using google guava helper equals)
HolidayPackageVariant:
<
Following the Secret of Equals:
HolidayPackageVariant:
public abstract class HolidayPackageVariant {
private Integer idHolidayPackageVariant;
private HolidayPackage holidayPackage;
private String typeHolidayPackage;
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if(obj == null) return false;
if (getClass().equals(obj.getClass())) {
final HolidayPackageVariant otherPackageVariant = (HolidayPackageVariant) obj;
return Objects.equal(getTypeHolidayPackage(),otherPackageVariant.getTypeHolidayPackage())
&& Objects.equal(getHolidayPackage(),
otherPackageVariant.getHolidayPackage());
}
return false;
}
}
FlightHolidayPackageVariant:
public final class FlightHolidayPackageVariant extends HolidayPackageVariant{
private Destination originCity;
@Override
public boolean equals(Object obj) {
if(super.equals(obj)){
return Objects.equal(getOriginCity(),
((FlightHolidayPackageVariant)(obj)).getOriginCity());
}
return false;
}
}
This will ensure that only the same Type of variants are equal to each other.