IteraciĆ³n 3(VersiĆ³n sin idiomas)
[ISBets21MAUBRY] / eclipse-workspace / ISBets21MAUBRY / src / main / java / domain / Event.java
diff --git a/eclipse-workspace/ISBets21MAUBRY/src/main/java/domain/Event.java b/eclipse-workspace/ISBets21MAUBRY/src/main/java/domain/Event.java
new file mode 100644 (file)
index 0000000..0a43386
--- /dev/null
@@ -0,0 +1,146 @@
+package domain;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.Vector;
+
+import javax.persistence.*;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlID;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@Entity
+public class Event implements Serializable {
+       
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       @XmlID @Id
+       @XmlJavaTypeAdapter(IntegerAdapter.class)
+       private Integer eventNumber;
+       private String description; 
+       private Date eventDate;
+       @OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.PERSIST)
+       private Vector<Question> questions=new Vector<Question>();
+
+       private boolean closed;
+       
+       public Vector<Question> getQuestions() {
+               return questions;
+       }
+
+       public void setQuestions(Vector<Question> questions) {
+               this.questions = questions;
+       }
+
+
+       public Event(Integer eventNumber, String description,Date eventDate) {
+               this.eventNumber = eventNumber;
+               this.description = description;
+               this.eventDate=eventDate;
+               this.closed=false;
+       }
+       
+       public Event(String description,Date eventDate) {
+               this.description = description;
+               this.eventDate=eventDate;
+               this.closed=false;
+       }
+
+       public Integer getEventNumber() {
+               return eventNumber;
+       }
+
+       public void setEventNumber(Integer eventNumber) {
+               this.eventNumber = eventNumber;
+       }
+
+       public String getDescription() {
+               return description;
+       }
+       
+       public void setDescription(String description) {
+               this.description=description;
+       }
+
+       public Date getEventDate() {
+               return eventDate;
+       }
+
+       public void setEventDate(Date eventDate) {
+               this.eventDate = eventDate;
+       }
+       
+       
+       public String toString(){
+               return eventNumber+"; "+description;
+       }
+       
+       /**
+        * This method creates a bet with a question, minimum bet ammount and percentual profit
+        * 
+        * @param question to be added to the event
+        * @param betMinimum of that question
+        * @return Bet
+        */
+       public Question addQuestion(String question, float betMinimum)  {
+        Question q=new Question(question,betMinimum, this);
+        questions.add(q);
+        return q;
+       }
+
+       
+       /**
+        * This method checks if the question already exists for that event
+        * 
+        * @param question that needs to be checked if there exists
+        * @return true if the question exists and false in other case
+        */
+       public boolean DoesQuestionExists(String question)  {   
+               for (Question q:this.getQuestions()){
+                       if (q.getQuestion().compareTo(question)==0)
+                               return true;
+               }
+               return false;
+       }
+               
+
+       
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + eventNumber;
+               return result;
+       }
+       
+       public void setClosed(boolean b) {
+               this.closed=b;
+       }
+       
+       public boolean getClosed() {
+               return closed;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               Event other = (Event) obj;
+               if (eventNumber != other.eventNumber)
+                       return false;
+               return true;
+       }
+       
+       
+       
+       
+
+}