VersiĆ³n del proyecto de Apuestas tras la iteraciĆ³n 1
[ISBets21MAUBRY] / eclipse-workspace / ISBets21BRYMAUJONUNA / src / main / java / domain / Event.java
1 package domain;
2
3 import java.io.Serializable;
4 import java.util.Date;
5 import java.util.Vector;
6
7 import javax.persistence.*;
8 import javax.xml.bind.annotation.XmlAccessType;
9 import javax.xml.bind.annotation.XmlAccessorType;
10 import javax.xml.bind.annotation.XmlID;
11 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
12
13 @XmlAccessorType(XmlAccessType.FIELD)
14 @Entity
15 public class Event implements Serializable {
16         
17         /**
18          * 
19          */
20         private static final long serialVersionUID = 1L;
21         @XmlID
22         @XmlJavaTypeAdapter(IntegerAdapter.class)
23         @Id @GeneratedValue
24         private Integer eventNumber;
25         private String description; 
26         private Date eventDate;
27         @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.PERSIST)
28         private Vector<Question> questions=new Vector<Question>();
29
30         public Vector<Question> getQuestions() {
31                 return questions;
32         }
33
34         public void setQuestions(Vector<Question> questions) {
35                 this.questions = questions;
36         }
37
38
39         public Event(Integer eventNumber, String description,Date eventDate) {
40                 this.eventNumber = eventNumber;
41                 this.description = description;
42                 this.eventDate=eventDate;
43         }
44         
45         public Event( String description,Date eventDate) {
46                 this.description = description;
47                 this.eventDate=eventDate;
48         }
49
50         public Integer getEventNumber() {
51                 return eventNumber;
52         }
53
54         public void setEventNumber(Integer eventNumber) {
55                 this.eventNumber = eventNumber;
56         }
57
58         public String getDescription() {
59                 return description;
60         }
61         
62         public void setDescription(String description) {
63                 this.description=description;
64         }
65
66         public Date getEventDate() {
67                 return eventDate;
68         }
69
70         public void setEventDate(Date eventDate) {
71                 this.eventDate = eventDate;
72         }
73         
74         
75         public String toString(){
76                 return eventNumber+";"+description;
77         }
78         
79         /**
80          * This method creates a bet with a question, minimum bet ammount and percentual profit
81          * 
82          * @param question to be added to the event
83          * @param betMinimum of that question
84          * @return Bet
85          */
86         public Question addQuestion(String question, float betMinimum)  {
87         Question q=new Question(question,betMinimum, this);
88         questions.add(q);
89         return q;
90         }
91
92         
93         /**
94          * This method checks if the question already exists for that event
95          * 
96          * @param question that needs to be checked if there exists
97          * @return true if the question exists and false in other case
98          */
99         public boolean DoesQuestionExists(String question)  {   
100                 for (Question q:this.getQuestions()){
101                         if (q.getQuestion().compareTo(question)==0)
102                                 return true;
103                 }
104                 return false;
105         }
106                 
107
108         
109         @Override
110         public int hashCode() {
111                 final int prime = 31;
112                 int result = 1;
113                 result = prime * result + eventNumber;
114                 return result;
115         }
116
117         @Override
118         public boolean equals(Object obj) {
119                 if (this == obj)
120                         return true;
121                 if (obj == null)
122                         return false;
123                 if (getClass() != obj.getClass())
124                         return false;
125                 Event other = (Event) obj;
126                 if (eventNumber != other.eventNumber)
127                         return false;
128                 return true;
129         }
130         
131         
132         
133         
134
135 }