KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > petclinic > Pet


1 package org.springframework.samples.petclinic;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collections JavaDoc;
5 import java.util.Date JavaDoc;
6 import java.util.HashSet JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.Set JavaDoc;
9
10 import org.springframework.beans.support.MutableSortDefinition;
11 import org.springframework.beans.support.PropertyComparator;
12
13 /**
14  * Simple JavaBean business object representing a pet.
15  *
16  * @author Ken Krebs
17  * @author Juergen Hoeller
18  */

19 public class Pet extends NamedEntity {
20
21     private Date JavaDoc birthDate;
22
23     private PetType type;
24
25     private Owner owner;
26
27     private Set JavaDoc visits;
28
29     public void setBirthDate(Date JavaDoc birthDate) {
30         this.birthDate = birthDate;
31     }
32
33     public Date JavaDoc getBirthDate() {
34         return this.birthDate;
35     }
36
37     public void setType(PetType type) {
38         this.type = type;
39     }
40
41     public PetType getType() {
42         return type;
43     }
44
45     protected void setOwner(Owner owner) {
46         this.owner = owner;
47     }
48
49     public Owner getOwner() {
50         return owner;
51     }
52
53     protected void setVisitsInternal(Set JavaDoc visits) {
54         this.visits = visits;
55     }
56
57     protected Set JavaDoc getVisitsInternal() {
58         if (this.visits == null) {
59             this.visits = new HashSet JavaDoc();
60         }
61         return this.visits;
62     }
63
64     public List JavaDoc getVisits() {
65         List JavaDoc sortedVisits = new ArrayList JavaDoc(getVisitsInternal());
66         PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
67         return Collections.unmodifiableList(sortedVisits);
68     }
69
70     public void addVisit(Visit visit) {
71         getVisitsInternal().add(visit);
72         visit.setPet(this);
73     }
74
75 }
76
Popular Tags