01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.sample.petclinic;
18:
19: import java.util.ArrayList;
20: import java.util.Collections;
21: import java.util.Date;
22: import java.util.HashSet;
23: import java.util.List;
24: import java.util.Set;
25:
26: import org.springframework.beans.support.MutableSortDefinition;
27: import org.springframework.beans.support.PropertyComparator;
28:
29: /**
30: * Simple JavaBean business object representing a pet.
31: *
32: * @author Ken Krebs
33: * @author Juergen Hoeller
34: */
35:
36: public class Pet extends NamedEntity {
37:
38: private Date birthDate;
39:
40: private PetType type;
41:
42: private Owner owner;
43:
44: private Set visits;
45:
46: public void setBirthDate(Date birthDate) {
47: this .birthDate = birthDate;
48: }
49:
50: public Date getBirthDate() {
51: return this .birthDate;
52: }
53:
54: public void setType(PetType type) {
55: this .type = type;
56: }
57:
58: public PetType getType() {
59: return type;
60: }
61:
62: protected void setOwner(Owner owner) {
63: this .owner = owner;
64: }
65:
66: public Owner getOwner() {
67: return owner;
68: }
69:
70: protected void setVisitsInternal(Set visits) {
71: this .visits = visits;
72: }
73:
74: protected Set getVisitsInternal() {
75: if (this .visits == null) {
76: this .visits = new HashSet();
77: }
78: return this .visits;
79: }
80:
81: public List getVisits() {
82: List sortedVisits = new ArrayList(getVisitsInternal());
83: PropertyComparator.sort(sortedVisits,
84: new MutableSortDefinition("date", false, false));
85: return Collections.unmodifiableList(sortedVisits);
86: }
87:
88: public void addVisit(Visit visit) {
89: getVisitsInternal().add(visit);
90: visit.setPet(this);
91: }
92: }
|