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