Source code: datas/Borrower.java
1 package datas;
2
3 import java.util.NoSuchElementException;
4 import java.util.StringTokenizer;
5
6 /**
7 * Class Borrower
8 * @invariant ((lastname != null) && (lastname.getLenght() != 0)) // lastname must be valid
9 */
10
11 public class Borrower {
12
13 // Attributs
14 private final String SEPARATEUR = "/";
15
16 private String lastname;
17 private String firstname;
18 private String address;
19 private String city;
20 private String zipCode;
21 private String state;
22
23 // Constructeurs
24 /**
25 * Constructror create a borrower with a String containing the data.
26 * @param data String describing a borrower
27 * @throws NoSuchElementException If the data is not correct
28 *
29 * @pre ((data != null) && (data.length() != 0)) // data must be set
30 */
31 public Borrower(String data) throws NoSuchElementException {
32 this.parseData(data);
33 }
34
35 /**
36 * Constructror create a borrower with all his information.
37 * @param lastname Lastname of the borrower
38 * @param firstname Firstname of the borrower
39 * @param address Adress of the boorower
40 * @param city City of the borrower
41 * @param zipCode zipCode of the borrower
42 * @param state state of the borrower
43 *
44 * @pre ((lasname != null) && (lasname.length() != 0)) // lasname must be set
45 * @pre ((firstname != null) && (firstname.length() != 0)) // firstname must be set
46 * @pre ((address != null) && (address.length() != 0)) // address must be set
47 * @pre ((city != null) && (city.length() != 0)) // city must be set
48 * @pre ((zipcode != null) && (zipcode.length() != 0)) // zipcode must be set
49 * @pre ((state != null) && (state.length() != 0)) // state must be set
50 *
51 */
52 public Borrower(
53 String lastname,
54 String firstname,
55 String address,
56 String city,
57 String zipCode,
58 String state) {
59
60 this.lastname = lastname;
61 this.firstname = firstname;
62 this.address = address;
63 this.city = city;
64 this.zipCode = zipCode;
65 this.state = state;
66 }
67
68 /**
69 * Method getLastname get the lastname.
70 * @return String lastname
71 */
72 public String getLastname() {
73 return lastname;
74 }
75
76 /**
77 * Method getFirstname get the firstname.
78 * @return String firstname
79 */
80 public String getFirstname() {
81 return firstname;
82 }
83
84 /**
85 * Method getAddress get the address.
86 * @return String adress
87 */
88 public String getAddress() {
89 return address;
90 }
91
92 /**
93 * Method getCity get the city.
94 * @return String city
95 */
96 public String getCity() {
97 return city;
98 }
99
100 /**
101 * Method getZipCode get the zip code.
102 * @return String zipcode
103 */
104 public String getZipCode() {
105 return zipCode;
106 }
107
108 /**
109 * Method getState get the state.
110 * @return String state
111 */
112 public String getState() {
113 return state;
114 }
115
116 //Modificateur
117 /**
118 * Method setBorrower update the borrower whith all his information.
119 * @param lastname Lastname
120 * @param firstname Firstname
121 * @param address Address
122 * @param city City
123 * @param zipCode ZipCode
124 * @param state State
125 *
126 * @pre ((lastname != null) && (lastname.length() != 0)) // lastname must be set
127 * @pre ((firstname != null) && (firstname.length() != 0)) // firstname must be set
128 * @pre ((address != null) && (address.length() != 0)) // address must be set
129 * @pre ((city != null) && (city.length() != 0)) // city must be set
130 * @pre ((zipcode != null) && (zipcode.length() != 0)) // zipcode must be set
131 * @pre ((state != null) && (state.length() != 0)) // state must be set
132 */
133 public void setBorrower(
134 String lastname,
135 String firstname,
136 String address,
137 String city,
138 String zipCode,
139 String state) {
140
141 this.lastname = lastname;
142 this.firstname = firstname;
143 this.address = address;
144 this.city = city;
145 this.zipCode = zipCode;
146 this.state = state;
147 }
148
149 /**
150 * Compares this Borrower to the specified object. The result is true if and only if the argument is not null
151 * and is a Item object that represents the same Borrower as this object.
152 * @param o the object to compare this Borrower against.
153 * @return boolean true if the Borrower are equal; false otherwise.
154 * @see Object#equals(Object)
155 */
156 public boolean equals(Object o) {
157 boolean ret = false;
158 if (o != null) {
159 if (o.getClass().getName().equals(this.getClass().getName())) {
160 if (lastname.equalsIgnoreCase(((Borrower) o).getLastname())) {
161 ret = true;
162 }
163 }
164 }
165 return ret;
166 }
167
168 /**
169 * Method toString give a String whith all the borrower information.
170 * @return String
171 * @see Object#toString()
172 */
173 public String toString() {
174 StringBuffer sb = new StringBuffer();
175 sb.append(lastname);
176 sb.append(SEPARATEUR);
177 sb.append(firstname);
178 sb.append(SEPARATEUR);
179 sb.append(address);
180 sb.append(SEPARATEUR);
181 sb.append(city);
182 sb.append(SEPARATEUR);
183 sb.append(zipCode);
184 sb.append(SEPARATEUR);
185 sb.append(state);
186 return sb.toString();
187 }
188
189 /**
190 * Method parseData parse a String describing a borrower.
191 * @param data The boorower
192 * @throws NoSuchElementException Data is not a borrower's data
193 */
194 private void parseData(String data) throws NoSuchElementException {
195 StringTokenizer st = new StringTokenizer(data, SEPARATEUR);
196 lastname = st.nextToken();
197 firstname = st.nextToken();
198 address = st.nextToken();
199 city = st.nextToken();
200 zipCode = st.nextToken();
201 state = st.nextToken();
202 }
203 }