Iteración 3(Versión sin idiomas)
[ISBets21MAUBRY] / eclipse-workspace / ISBets21MAUBRY / src / main / java / domain / Question.java
1 package domain;
2
3 import java.io.Serializable;
4 import java.util.Vector;
5
6 import javax.persistence.CascadeType;
7 import javax.persistence.Entity;
8 import javax.persistence.FetchType;
9 import javax.persistence.GeneratedValue;
10 import javax.persistence.Id;
11 import javax.persistence.OneToMany;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
15
16 @SuppressWarnings("serial")
17 @XmlAccessorType(XmlAccessType.FIELD)
18 @Entity
19 public class Question implements Serializable {
20
21         @Id
22         @XmlJavaTypeAdapter(IntegerAdapter.class)
23         @GeneratedValue
24         private Integer questionNumber;
25         private String question;
26         private float betMinimum;
27         private String result;
28         @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
29         private Vector<Forecast> forecasts = new Vector<Forecast>();
30         private Event event;
31         private boolean hasResult;
32
33         public boolean hasResult() {
34                 return hasResult;
35         }
36
37         public void hasResult(boolean hasResult) {
38                 this.hasResult = hasResult;
39         }
40
41         public Question() {
42                 super();
43         }
44
45         public Question(Integer queryNumber, String query, float betMinimum, Event event) {
46                 super();
47                 this.questionNumber = queryNumber;
48                 this.question = query;
49                 this.betMinimum = betMinimum;
50                 this.event = event;
51                 this.hasResult=false;
52         }
53
54         public Question(String query, float betMinimum, Event event) {
55                 super();
56                 this.question = query;
57                 this.betMinimum = betMinimum;
58                 this.hasResult=false;
59
60                 this.event = event;
61         }
62
63         /**
64          * Get the number of the question
65          * 
66          * @return the question number
67          */
68         public Integer getQuestionNumber() {
69                 return questionNumber;
70         }
71
72         /**
73          * Set the bet number to a question
74          * 
75          * @param questionNumber to be setted
76          */
77         public void setQuestionNumber(Integer questionNumber) {
78                 this.questionNumber = questionNumber;
79         }
80
81         /**
82          * Get the question description of the bet
83          * 
84          * @return the bet question
85          */
86
87         public String getQuestion() {
88                 return question;
89         }
90
91         /**
92          * Set the question description of the bet
93          * 
94          * @param question to be setted
95          */
96         public void setQuestion(String question) {
97                 this.question = question;
98         }
99
100         /**
101          * Get the minimun ammount of the bet
102          * 
103          * @return the minimum bet ammount
104          */
105
106         public float getBetMinimum() {
107                 return betMinimum;
108         }
109
110         /**
111          * Get the minimun ammount of the bet
112          * 
113          * @param betMinimum minimum bet ammount to be setted
114          */
115
116         public void setBetMinimum(float betMinimum) {
117                 this.betMinimum = betMinimum;
118         }
119
120         /**
121          * Get the result of the query
122          * 
123          * @return the the query result
124          */
125         public String getResult() {
126                 return result;
127         }
128
129         /**
130          * Get the result of the query
131          * 
132          * @param result of the query to be setted
133          */
134
135         public void setResult(String result) {
136                 this.result = result;
137         }
138
139         /**
140          * Get the event associated to the bet
141          * 
142          * @return the associated event
143          */
144         public Event getEvent() {
145                 return event;
146         }
147
148         /**
149          * Set the event associated to the bet
150          * 
151          * @param event to associate to the bet
152          */
153         public void setEvent(Event event) {
154                 this.event = event;
155         }
156
157         public Vector<Forecast> getForecasts() {
158                 return forecasts;
159         }
160
161         public void setForecasts(Vector<Forecast> forecasts) {
162                 this.forecasts = forecasts;
163         }
164
165         public Forecast addForecast(String forecast, float fee) {
166                 Forecast f = new Forecast(forecast, fee, this);
167                 forecasts.add(f);
168                 return f;
169         }
170
171         public Forecast addForecast(Forecast forecast) {
172                 forecasts.add(forecast);
173                 return forecast;
174         }
175
176         public boolean DoesForecastExists(String forecast) {
177                 for (Forecast f : this.getForecasts()) {
178                         if (f.getForecast().compareTo(forecast) == 0)
179                                 return true;
180                 }
181                 return false;
182         }
183
184         @Override
185         public String toString() {
186                 return questionNumber + "; " + question + "; " + Float.toString(betMinimum) + " ➪ " + event.getDescription();
187         }
188
189 }