001 package market;
002
003 /* Generated by Together */
004 import java.util.Calendar;
005
006 import users.User;
007
008 /**
009 * A person that interacts with the market. Can be a {@link UCustomer customer} or an
010 * {@link UStaffer employee}.
011 */
012 public class UPerson extends User {
013
014 /**
015 * ID for serialization.
016 */
017 private static final long serialVersionUID = -6949039852904696724L;
018
019 public static String HERR = new String("Herr");
020 public static String FRAU = new String("Frau");
021
022 private String salutation;
023 private String name;
024 private String firstName;
025 private String street;
026 private int postcode;
027 private String city;
028 private String telephone;
029 private Calendar date;
030
031 /**
032 * Creates a new person.
033 * @param userName the person's ID.
034 */
035 public UPerson(String userName){
036 super(userName);
037 date = (Calendar)SMarket.getTime().clone();
038 }
039
040 /**
041 * Sets the person's name.
042 * @param salutation the person's salutation (Mr, Mrs)
043 * @param name the person's surname.
044 * @param firstName the person's forename.
045 */
046 public void setFullName(String salutation, String name, String firstName) {
047 this.salutation = salutation;
048 this.name = name;
049 this.firstName = firstName;
050 }
051
052 /**
053 * Sets the person's address.
054 */
055 public void setAddress(String street, int postcode, String city) {
056 this.street = street;
057 this.postcode = postcode;
058 this.city = city;
059 }
060
061 /**
062 * Sets the person's telephone number.
063 */
064 public void setTelephone(String telephone) {
065 this.telephone = telephone;
066 }
067
068 /**
069 * Gets the person's name.
070 * @return the full name, containing salutation, forename and surname.
071 */
072 public String getFullName() {
073 return (salutation + " " + firstName + " " + name);
074 }
075
076 /**
077 * Gets the person's address.
078 * @return the address, containing street, postcode and city.
079 */
080 public String getAdress() {
081 return (street + Integer.toString(postcode) + city);
082 }
083
084 /**
085 * Gets the person's telephone number.
086 * @return the telephone number.
087 */
088 public String getTelephone() {
089 return telephone;
090 }
091
092 /**
093 * Gets the person's salutation.
094 * @return the salutation.
095 */
096 public String getSalutation() {
097 return salutation;
098 }
099
100 /**
101 * Sets the person's salutation.
102 * @param salutation the salutation to be set.
103 */
104 public void setSalutation(String salutation) {
105 this.salutation = salutation;
106 }
107
108 /**
109 * Gets the person's surname.
110 * @return the surname.
111 */
112 public String getSurname() {
113 return name;
114 }
115
116 /**
117 * Sets the person's surname.
118 * @param name the surname to be set.
119 */
120 public void setSurname(String name) {
121 this.name = name;
122 }
123
124 /**
125 * Gets the person's forename.
126 * @return the forename.
127 */
128 public String getFirstName() {
129 return firstName;
130 }
131
132 /**
133 * Sets the person's forename.
134 * @param firstName the forename to be set.
135 */
136 public void setFirstName(String firstName) {
137 this.firstName = firstName;
138 }
139
140 /**
141 * Gets the street where the person lives.
142 * @return the street.
143 */
144 public String getStreet() {
145 return street;
146 }
147
148 /**
149 * Sets the street where the person lives.
150 * @param street the street to be set.
151 */
152 public void setStreet(String street) {
153 this.street = street;
154 }
155
156 /**
157 * Gets the person's postcode.
158 * @return the postcode.
159 */
160 public int getPostcode() {
161 return postcode;
162 }
163
164 /**
165 * Sets the person's postcode.
166 * @param postcode the postcode to be set.
167 */
168 public void setPostcode(int postcode) {
169 this.postcode = postcode;
170 }
171
172 /**
173 * Gets the city where the person lives.
174 * @return the city.
175 */
176 public String getCity() {
177 return city;
178 }
179
180 /**
181 * Sets the city where the person lives.
182 * @param city the city.
183 */
184 public void setCity(String city) {
185 this.city = city;
186 }
187
188 /**
189 * Gets the day the person has first had contact with the market.<br>
190 * For customer this is the registration, for workers the day of employment.
191 *
192 * @return the date registration or employment.
193 */
194 public Calendar getDayOfRegistration() {
195 return date;
196 }
197
198 /**
199 * Returns the time in months the person has been part of the market, be it as customer or worker.
200 * @return the time of membership or employment.
201 * @see #getDayOfRegistration
202 */
203 public int getMonthsOfMembership() {
204 Calendar start = (Calendar)date.clone();
205 Calendar now = SMarket.getTime();
206 int months = 12 * (now.get(Calendar.YEAR) - start.get(Calendar.YEAR));
207 months += now.get(Calendar.MONTH) - start.get(Calendar.MONTH);
208 if (start.get(Calendar.DATE) > now.get(Calendar.DATE)) months--;
209 return months;
210 }
211
212 /**
213 * Sets the default comparison order for UPersons to <surname, forename>
214 */
215 public int compareTo(Object o) {
216 if (o instanceof UPerson) {
217 UPerson u = (UPerson) o;
218 return new String(getSurname() + getFirstName()).compareTo(
219 new String(u.getSurname() + u.getFirstName()));
220 } else {
221 return 0;
222 }
223 }
224 }