package geniusweb.profile; import org.eclipse.jdt.annotation.NonNull; import com.fasterxml.jackson.annotation.JsonCreator; import geniusweb.issuevalue.Bid; import geniusweb.issuevalue.Domain; /** * Set up such that jackson can look at the getters. * */ public abstract class DefaultProfile implements Profile { private final @NonNull String name; private final @NonNull Domain domain; private final Bid reservationbid; @JsonCreator /** * * @param name the name for the profile * @param domain the {@link Domain} description * @param reservationbid the reservation {@link Bid} */ public DefaultProfile(@NonNull String name, @NonNull Domain domain, Bid reservationbid) { if (name == null) throw new NullPointerException("name must be not null"); if (domain == null) throw new NullPointerException("domain must be not null"); this.name = name; this.domain = domain; this.reservationbid = reservationbid; if (reservationbid != null) { String message = domain.isFitting(reservationbid); if (message != null) throw new IllegalArgumentException( "reservationbid is not fitting domain: " + message); } } @Override public @NonNull String getName() { return name; } @Override public @NonNull Domain getDomain() { return domain; } @Override public Bid getReservationBid() { return reservationbid; } @NonNull /** * * @return string of values contained in here. Useful to make derived * toString functions */ public String getValuesString() { return name + "," + domain + "," + reservationbid; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((domain == null) ? 0 : domain.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((reservationbid == null) ? 0 : reservationbid.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DefaultProfile other = (DefaultProfile) obj; if (domain == null) { if (other.domain != null) return false; } else if (!domain.equals(other.domain)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (reservationbid == null) { if (other.reservationbid != null) return false; } else if (!reservationbid.equals(other.reservationbid)) return false; return true; } }