Java Reference
In-Depth Information
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 A.12 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; }
16. public Location getLocation(){ return location; }
17.
18. public void setDescription(String newDescription){ description = newDescription; }
19. public void setLocation(Location newLocation){ location = newLocation; }
20. public void setStartDate(Date newStartDate){ startDate = newStartDate; }
21. public void setEndDate(Date newEndDate){ endDate = newEndDate; }
22. public void setAttendees(ArrayList newAttendees){
23. if (newAttendees != null){
24. attendees = newAttendees;
25. }
26. }
27.
28. public void addAttendee(Contact attendee){
29. if (!attendees.contains(attendee)){
30. attendees.add(attendee);
31. }
32. }
33.
34. public void removeAttendee(Contact attendee){
35. attendees.remove(attendee);
36. }
37.
38. public String toString(){
39. return " Description: " + description + EOL_STRING +
40. " Start Date: " + startDate + EOL_STRING +
41. " End Date: " + endDate + EOL_STRING +
42. " Location: " + location + EOL_STRING +
43. " Attendees: " + attendees;
44. }
45. }
The Scheduler class makes calls to the AppointmentBuilder , managing the creation process through the
method createAppointment .
Example A.13 Scheduler.java
1. import java.util.Date;
2. import java.util.ArrayList;
3. public class Scheduler{
4. public Appointment createAppointment(AppointmentBuilder builder,
5. Date startDate, Date endDate, String description,
6. Location location, ArrayList attendees) throws InformationRequiredException {
7. if (builder == null){
8. builder = new AppointmentBuilder();
Search WWH ::




Custom Search