View Javadoc

1   package org.springframework.samples.petclinic;
2   
3   import java.util.ArrayList;
4   import java.util.Collections;
5   import java.util.Date;
6   import java.util.HashSet;
7   import java.util.List;
8   import java.util.Set;
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   * @author Sam Brannen
19   */
20  public class Pet extends NamedEntity {
21  
22  	private Date birthDate;
23  
24  	private PetType type;
25  
26  	private Owner owner;
27  
28  	private Set<Visit> visits;
29  
30  
31  	public void setBirthDate(Date birthDate) {
32  		this.birthDate = birthDate;
33  	}
34  
35  	public Date getBirthDate() {
36  		return this.birthDate;
37  	}
38  
39  	public void setType(PetType type) {
40  		this.type = type;
41  	}
42  
43  	public PetType getType() {
44  		return this.type;
45  	}
46  
47  	protected void setOwner(Owner owner) {
48  		this.owner = owner;
49  	}
50  
51  	public Owner getOwner() {
52  		return this.owner;
53  	}
54  
55  	protected void setVisitsInternal(Set<Visit> visits) {
56  		this.visits = visits;
57  	}
58  
59  	protected Set<Visit> getVisitsInternal() {
60  		if (this.visits == null) {
61  			this.visits = new HashSet<Visit>();
62  		}
63  		return this.visits;
64  	}
65  
66  	public List<Visit> getVisits() {
67  		List<Visit> sortedVisits = new ArrayList<Visit>(getVisitsInternal());
68  		PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
69  		return Collections.unmodifiableList(sortedVisits);
70  	}
71  
72  	public void addVisit(Visit visit) {
73  		getVisitsInternal().add(visit);
74  		visit.setPet(this);
75  	}
76  
77  }