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 19 public class Pet extends NamedEntity { 20 21 private Date birthDate; 22 23 private PetType type; 24 25 private Owner owner; 26 27 private Set visits; 28 29 public void setBirthDate(Date birthDate) { 30 this.birthDate = birthDate; 31 } 32 33 public Date 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 visits) { 54 this.visits = visits; 55 } 56 57 protected Set getVisitsInternal() { 58 if (this.visits == null) { 59 this.visits = new HashSet (); 60 } 61 return this.visits; 62 } 63 64 public List getVisits() { 65 List sortedVisits = new ArrayList (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 |