[519] | 1 | package geniusweb.profile;
|
---|
| 2 |
|
---|
| 3 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 4 |
|
---|
| 5 | import geniusweb.issuevalue.Bid;
|
---|
| 6 | import geniusweb.issuevalue.Domain;
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * Set up such that jackson can look at the getters.
|
---|
| 10 | *
|
---|
| 11 | */
|
---|
| 12 | public abstract class DefaultProfile implements Profile {
|
---|
| 13 | private final String name;
|
---|
| 14 | private final Domain domain;
|
---|
| 15 | private final Bid reservationbid;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | *
|
---|
| 19 | * @param name the name for the profile
|
---|
| 20 | * @param domain the {@link Domain} description
|
---|
| 21 | * @param reservationbid the reservation {@link Bid}
|
---|
| 22 | */
|
---|
| 23 | @JsonCreator
|
---|
| 24 | public DefaultProfile(String name, Domain domain, Bid reservationbid) {
|
---|
| 25 | this.name = name;
|
---|
| 26 | this.domain = domain;
|
---|
| 27 | this.reservationbid = reservationbid;
|
---|
| 28 | if (reservationbid != null) {
|
---|
| 29 | String message = domain.isFitting(reservationbid);
|
---|
| 30 | if (message != null)
|
---|
| 31 | throw new IllegalArgumentException(
|
---|
| 32 | "reservationbid is not fitting domain: " + message);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | @Override
|
---|
| 38 | public String getName() {
|
---|
| 39 | return name;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @Override
|
---|
| 43 | public Domain getDomain() {
|
---|
| 44 | return domain;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | @Override
|
---|
| 48 | public Bid getReservationBid() {
|
---|
| 49 | return reservationbid;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | *
|
---|
| 54 | * @return string of values contained in here. Useful to make derived
|
---|
| 55 | * toString functions
|
---|
| 56 | */
|
---|
| 57 | public String getValuesString() {
|
---|
| 58 | return name + "," + domain + "," + reservationbid;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | @Override
|
---|
| 62 | public int hashCode() {
|
---|
| 63 | final int prime = 31;
|
---|
| 64 | int result = 1;
|
---|
| 65 | result = prime * result + ((domain == null) ? 0 : domain.hashCode());
|
---|
| 66 | result = prime * result + ((name == null) ? 0 : name.hashCode());
|
---|
| 67 | result = prime * result
|
---|
| 68 | + ((reservationbid == null) ? 0 : reservationbid.hashCode());
|
---|
| 69 | return result;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public boolean equals(Object obj) {
|
---|
| 74 | if (this == obj)
|
---|
| 75 | return true;
|
---|
| 76 | if (obj == null)
|
---|
| 77 | return false;
|
---|
| 78 | if (getClass() != obj.getClass())
|
---|
| 79 | return false;
|
---|
| 80 | DefaultProfile other = (DefaultProfile) obj;
|
---|
| 81 | if (domain == null) {
|
---|
| 82 | if (other.domain != null)
|
---|
| 83 | return false;
|
---|
| 84 | } else if (!domain.equals(other.domain))
|
---|
| 85 | return false;
|
---|
| 86 | if (name == null) {
|
---|
| 87 | if (other.name != null)
|
---|
| 88 | return false;
|
---|
| 89 | } else if (!name.equals(other.name))
|
---|
| 90 | return false;
|
---|
| 91 | if (reservationbid == null) {
|
---|
| 92 | if (other.reservationbid != null)
|
---|
| 93 | return false;
|
---|
| 94 | } else if (!reservationbid.equals(other.reservationbid))
|
---|
| 95 | return false;
|
---|
| 96 | return true;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | }
|
---|