source: geniuswebcore/geniusweb/profile/DefaultProfile.py@ 73

Last change on this file since 73 was 73, checked in by Bart Vastenhouw, 3 years ago

Fix for IssueValue hashcode.

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