Java Reference
In-Depth Information
9. public static final int ATTENDEE_REQUIRED = 8;
10. public static final int LOCATION_REQUIRED = 16;
11.
12. protected Appointment appointment;
13.
14. protected int requiredElements;
15.
16. public void buildAppointment(){
17. appointment = new Appointment();
18. }
19.
20. public void buildDates(Date startDate, Date endDate){
21. Date currentDate = new Date();
22. if ((startDate != null) && (startDate.after(currentDate))){
23. appointment.setStartDate(startDate);
24. }
25. if ((endDate != null) && (endDate.after(startDate))){
26. appointment.setEndDate(endDate);
27. }
28. }
29.
30. public void buildDescription(String newDescription){
31. appointment.setDescription(newDescription);
32. }
33.
34. public void buildAttendees(ArrayList attendees){
35. if ((attendees != null) && (!attendees.isEmpty())){
36. appointment.setAttendees(attendees);
37. }
38. }
39.
40. public void buildLocation(Location newLocation){
41. if (newLocation != null){
42. appointment.setLocation(newLocation);
43. }
44. }
45.
46. public Appointment getAppointment() throws InformationRequiredException{
47. requiredElements = 0;
48.
49. if (appointment.getStartDate() == null){
50. requiredElements += START_DATE_REQUIRED;
51. }
52.
53. if (appointment.getLocation() == null){
54. requiredElements += LOCATION_REQUIRED;
55. }
56.
57. if (appointment.getAttendees().isEmpty()){
58. requiredElements += ATTENDEE_REQUIRED;
59. }
60.
61. if (requiredElements > 0){
62. throw new InformationRequiredException(requiredElements);
63. }
64. return appointment;
65. }
66.
67. public int getRequiredElements(){ return requiredElements; }
68. }
Example 1.11 Appointment.java
1. import java.util.ArrayList;
2. import java.util.Date;
3. public class Appointment{
4. private Date startDate;
5. private Date endDate;
6. private String description;
7. private ArrayList attendees = new ArrayList();
8. private Location location;
9. public static final String EOL_STRING =
10. System.getProperty("line.separator");
11.
12. public Date getStartDate(){ return startDate; }
13. public Date getEndDate(){ return endDate; }
14. public String getDescription(){ return description; }
15. public ArrayList getAttendees(){ return attendees; }
Search WWH ::




Custom Search