IteraciĆ³n 3(VersiĆ³n sin idiomas)
[ISBets21MAUBRY] / eclipse-workspace / ISBets21MAUBRY / 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 @Id
22         @XmlJavaTypeAdapter(IntegerAdapter.class)
23         private Integer eventNumber;
24         private String description; 
25         private Date eventDate;
26         @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.PERSIST)
27         private Vector<Question> questions=new Vector<Question>();
28
29         private boolean closed;
30         
31         public Vector<Question> getQuestions() {
32                 return questions;
33         }
34
35         public void setQuestions(Vector<Question> questions) {
36                 this.questions = questions;
37         }
38
39
40         public Event(Integer eventNumber, String description,Date eventDate) {
41                 this.eventNumber = eventNumber;
42                 this.description = description;
43                 this.eventDate=eventDate;
44                 this.closed=false;
45         }
46         
47         public Event(String description,Date eventDate) {
48                 this.description = description;
49                 this.eventDate=eventDate;
50                 this.closed=false;
51         }
52
53         public Integer getEventNumber() {
54                 return eventNumber;
55         }
56
57         public void setEventNumber(Integer eventNumber) {
58                 this.eventNumber = eventNumber;
59         }
60
61         public String getDescription() {
62                 return description;
63         }
64         
65         public void setDescription(String description) {
66                 this.description=description;
67         }
68
69         public Date getEventDate() {
70                 return eventDate;
71         }
72
73         public void setEventDate(Date eventDate) {
74                 this.eventDate = eventDate;
75         }
76         
77         
78         public String toString(){
79                 return eventNumber+"; "+description;
80         }
81         
82         /**
83          * This method creates a bet with a question, minimum bet ammount and percentual profit
84          * 
85          * @param question to be added to the event
86          * @param betMinimum of that question
87          * @return Bet
88          */
89         public Question addQuestion(String question, float betMinimum)  {
90         Question q=new Question(question,betMinimum, this);
91         questions.add(q);
92         return q;
93         }
94
95         
96         /**
97          * This method checks if the question already exists for that event
98          * 
99          * @param question that needs to be checked if there exists
100          * @return true if the question exists and false in other case
101          */
102         public boolean DoesQuestionExists(String question)  {   
103                 for (Question q:this.getQuestions()){
104                         if (q.getQuestion().compareTo(question)==0)
105                                 return true;
106                 }
107                 return false;
108         }
109                 
110
111         
112         @Override
113         public int hashCode() {
114                 final int prime = 31;
115                 int result = 1;
116                 result = prime * result + eventNumber;
117                 return result;
118         }
119         
120         public void setClosed(boolean b) {
121                 this.closed=b;
122         }
123         
124         public boolean getClosed() {
125                 return closed;
126         }
127
128         @Override
129         public boolean equals(Object obj) {
130                 if (this == obj)
131                         return true;
132                 if (obj == null)
133                         return false;
134                 if (getClass() != obj.getClass())
135                         return false;
136                 Event other = (Event) obj;
137                 if (eventNumber != other.eventNumber)
138                         return false;
139                 return true;
140         }
141         
142         
143         
144         
145
146 }