1 package org.musicontroller.core;
2
3 import java.util.Date;
4 import java.util.HashSet;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 import org.musicontroller.model.Linkable;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 public class Artist implements Linkable {
24 private long id;
25 private Date changed,inserted,birth,decease;
26 private String lastname,comments,firstname;
27 private Link link;
28 private Set<Contract_BA> bands;
29
30 public Artist() {
31 id=-1L;
32 inserted=new Date();
33 lastname="";
34 firstname="";
35 comments="";
36 link=null;
37 birth=null;
38 decease=null;
39 bands=new HashSet<Contract_BA>();
40 }
41
42 public Date getBirth() {
43 return birth;
44 }
45
46 public void setBirth(Date birth) {
47 this.birth = birth;
48 }
49
50 public Date getChanged() {
51 return changed;
52 }
53
54 public void setChanged(Date changed) {
55 this.changed = changed;
56 }
57
58 public String getComments() {
59 return comments;
60 }
61
62 public void setComments(String comments) {
63 this.comments = comments;
64 }
65
66 public Date getDecease() {
67 return decease;
68 }
69
70 public void setDecease(Date decease) {
71 this.decease = decease;
72 }
73
74 public Link getLink() {
75 return link;
76 }
77
78 public void setLink(Link link) {
79 this.link = link;
80 }
81
82 public long getId() {
83 return id;
84 }
85
86 public void setId(long id) {
87 this.id = id;
88 }
89
90 public Date getInserted() {
91 return inserted;
92 }
93
94 public void setInserted(Date inserted) {
95 this.inserted = inserted;
96 }
97
98 public String getLastname() {
99 return lastname;
100 }
101
102
103
104
105
106
107 public void setLastname(String lastname) {
108 if (lastname==null) {
109 this.lastname = null;
110 } else {
111 this.lastname = lastname.trim();
112 }
113 }
114
115
116
117
118
119
120 public String getName() {
121 StringBuilder sb = new StringBuilder();
122 if(getFirstname()!=null) {
123 sb.append(getFirstname().trim());
124 sb.append(" ");
125 }
126 sb.append(getLastname().trim());
127 return sb.toString();
128 }
129
130 public Set<Contract_BA> getBands() {
131 return bands;
132 }
133
134
135 public void setBands(Set<Contract_BA> bands) {
136 if (bands!=null) this.bands = bands;
137 }
138
139 public void addBand(Band band) {
140 if(band==null) {
141 return;
142 }
143 Iterator<Contract_BA> i = bands.iterator();
144 boolean bandalreadyincontracts = false;
145 while (i.hasNext()) {
146 Contract_BA c_ba= i.next();
147 bandalreadyincontracts = c_ba.getBand().equals(band);
148 }
149 if (!bandalreadyincontracts) {
150 Contract_BA newcontract = new Contract_BA();
151 newcontract.setBand(band);
152 newcontract.setArtist(this);
153 bands.add(newcontract);
154 }
155 }
156
157
158
159
160
161 public String getFirstname() {
162 return firstname;
163 }
164
165
166
167
168
169
170
171 public void setFirstname(String firstname) {
172 if(firstname==null) {
173 this.firstname = null;
174 } else {
175 this.firstname = firstname.trim();
176 }
177 }
178
179
180
181
182
183
184
185 public String getFormattedName() {
186 String result = null;
187 if(getFirstname()==null || getFirstname().length()<1) {
188 result = getLastname();
189 } else {
190 result = getLastname()+", "+getFirstname();
191 }
192 return result;
193 }
194
195
196
197
198
199
200
201 @Override
202 public boolean equals(Object obj) {
203 boolean result = false;
204 if (this==obj) {
205 return true;
206 } else {
207 if (obj instanceof Artist) {
208 Artist other = (Artist) obj;
209 if(this.getFirstname()==null) {
210 result = other.getFirstname()==null;
211 } else {
212 result = this.getFirstname().equalsIgnoreCase(other.getFirstname());
213 }
214
215 if(result && this.getLastname()==null) {
216 result = other.getLastname()==null;
217 } else {
218 result = this.getLastname().equalsIgnoreCase(other.getLastname());
219 }
220
221 }
222 }
223 return result;
224 }
225
226 @Override
227 public int hashCode() {
228 int result = 0;
229 if(getFirstname()!=null) {
230 result += getFirstname().toLowerCase().hashCode();
231 }
232 if(getLastname()!=null) {
233 result += (17 * result) + getLastname().toLowerCase().hashCode();
234 }
235 return result;
236 }
237
238
239
240
241
242 public String toString() {
243 return getName();
244 }
245
246 public String getType() {
247 return "A";
248 }
249 }