Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. package br.com.clinimuni.vaccinaeweb.domain;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Objects;
  5. import java.util.Set;
  6.  
  7. import javax.persistence.ElementCollection;
  8. import javax.persistence.EmbeddedId;
  9. import javax.persistence.Entity;
  10. import javax.persistence.FetchType;
  11. import javax.persistence.ManyToOne;
  12. import javax.persistence.MapsId;
  13. import javax.persistence.Table;
  14.  
  15. /**
  16.  * @author ivocalado
  17.  *
  18.  *         Esta classe tem por objetivo representar o relacionamento
  19.  *         Many-To-Many entre uma vacina e o calendario vacinal incluindo a
  20.  *         lista de doses a serem tomadas para a vacina
  21.  */
  22. @Entity(name = "VacinaCalendarioVacinal")
  23. @Table(name = "vacina_calendario_vacinal")
  24. public class VacinaCalendarioVacinal {
  25.     @EmbeddedId
  26.     private VacinaCalendarioVacinalId id;
  27.  
  28.     @ManyToOne(fetch = FetchType.LAZY)
  29.     @MapsId("vacinaId")
  30.     private Vacina vacina;
  31.  
  32.     @ManyToOne(fetch = FetchType.LAZY)
  33.     @MapsId("vacinaCalendarioId")
  34.     private CalendarioVacinal calendario;
  35.  
  36.     @ElementCollection
  37.     private Set<Integer> dosesAplicacao = new HashSet<>(); // doses a serem aplicadas em meses
  38.  
  39.     private VacinaCalendarioVacinal() {
  40.     }
  41.  
  42.     /**
  43.      * @param vacina
  44.      * @param calendario
  45.      */
  46.     public VacinaCalendarioVacinal(Vacina vacina, CalendarioVacinal calendario) {
  47.         this();
  48.         this.vacina = vacina;
  49.         this.calendario = calendario;
  50.         this.id = new VacinaCalendarioVacinalId(vacina.getId(), calendario.getId());
  51.     }
  52.  
  53.     public void addDose(Integer dose) {
  54.         dosesAplicacao.add(dose);
  55.     }
  56.  
  57.     public boolean removeDose(Integer dose) {
  58.         return dosesAplicacao.remove(dose);
  59.     }
  60.  
  61.     /**
  62.      * @return the id
  63.      */
  64.     public VacinaCalendarioVacinalId getId() {
  65.         return id;
  66.     }
  67.  
  68.     /**
  69.      * @param id the id to set
  70.      */
  71.     public void setId(VacinaCalendarioVacinalId id) {
  72.         this.id = id;
  73.     }
  74.  
  75.     /**
  76.      * @return the vacina
  77.      */
  78.     public Vacina getVacina() {
  79.         return vacina;
  80.     }
  81.  
  82.     /**
  83.      * @param vacina the vacina to set
  84.      */
  85.     public void setVacina(Vacina vacina) {
  86.         this.vacina = vacina;
  87.     }
  88.  
  89.     /**
  90.      * @return the calendario
  91.      */
  92.     public CalendarioVacinal getCalendario() {
  93.         return calendario;
  94.     }
  95.  
  96.     /**
  97.      * @param calendario the calendario to set
  98.      */
  99.     public void setCalendario(CalendarioVacinal calendario) {
  100.         this.calendario = calendario;
  101.     }
  102.  
  103.     /**
  104.      * @return the dosesAplicacao
  105.      */
  106.     public Set<Integer> getDosesAplicacao() {
  107.         return dosesAplicacao;
  108.     }
  109.  
  110.     /**
  111.      * @param dosesAplicacao the dosesAplicacao to set
  112.      */
  113.     public void setDosesAplicacao(Set<Integer> dosesAplicacao) {
  114.         this.dosesAplicacao = dosesAplicacao;
  115.     }
  116.  
  117.     /*
  118.      * (non-Javadoc)
  119.      *
  120.      * @see java.lang.Object#hashCode()
  121.      */
  122.     @Override
  123.     public int hashCode() {
  124.         return Objects.hash(calendario, vacina);
  125.     }
  126.  
  127.     /*
  128.      * (non-Javadoc)
  129.      *
  130.      * @see java.lang.Object#equals(java.lang.Object)
  131.      */
  132.     @Override
  133.     public boolean equals(Object obj) {
  134.         if (this == obj) {
  135.             return true;
  136.         }
  137.         if (obj == null) {
  138.             return false;
  139.         }
  140.         if (!(obj instanceof VacinaCalendarioVacinal)) {
  141.             return false;
  142.         }
  143.         VacinaCalendarioVacinal other = (VacinaCalendarioVacinal) obj;
  144.         return Objects.equals(calendario, other.calendario) && Objects.equals(vacina, other.vacina);
  145.     }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement