1 package org.musicontroller.core;
2
3 import java.util.Date;
4
5 import org.musicontroller.security.IUser;
6
7 public class Event implements Comparable<Event> {
8 private long id;
9 private Song song;
10 private int eventkind;
11 private IUser user;
12 private Date moment;
13 private char submitted;
14
15 public static final int unknown=-1;
16 public static final int requested=1;
17 public static final int played=2;
18 public static final int skipped=3;
19 public static final int downloaded=4;
20
21 public Event() {
22 id=-1L;
23 song=null;
24 eventkind=unknown;
25 user=null;
26 moment=new Date();
27 submitted='N';
28 }
29
30 public int getEventkind() {
31 return eventkind;
32 }
33
34 public void setEventkind(int eventkind) {
35 this.eventkind = eventkind;
36 }
37
38
39
40
41
42 public static String getDescription(int kind) {
43 switch (kind) {
44 case requested : return "Requested";
45 case played : return "Played";
46 case skipped : return "Skipped";
47 case downloaded : return "Downloaded";
48 default : return "Unknown";
49 }
50 }
51
52
53
54
55 public String getDescription() {
56 return getDescription(eventkind);
57 }
58
59 public long getId() {
60 return id;
61 }
62
63 public void setId(long id) {
64 this.id = id;
65 }
66
67 public Date getMoment() {
68 return moment;
69 }
70
71 public void setMoment(Date moment) {
72 this.moment = moment;
73 }
74
75 public Song getSong() {
76 return song;
77 }
78
79 public void setSong(Song song) {
80 this.song = song;
81 }
82
83 public IUser getUser() {
84 return user;
85 }
86
87 public void setUser(IUser user) {
88 this.user = user;
89 }
90
91 public char getSubmitted() {
92 return submitted;
93 }
94
95 public void setSubmitted(char submitted) {
96 this.submitted = submitted;
97 }
98
99 public int compareTo(Event ev) {
100 if(this.getMoment()==null) {
101 if(ev.getMoment()==null) {
102 return 0;
103 } else {
104 return -1;
105 }
106 }
107 if(ev.getMoment()==null) {
108 if(getMoment()==null) {
109 return 0;
110 } else {
111 return 1;
112 }
113 }
114 if (this.getMoment().before(ev.getMoment())) {
115 return -1;
116 } else {
117 if (this.getMoment().after(ev.getMoment())) {
118 return 1;
119 } else {
120 return 0;
121 }
122 }
123 }
124
125
126
127
128
129 @Override
130 public boolean equals(Object o) {
131 if (o==null) return false;
132 if (o instanceof Event) {
133 Event other = (Event) o;
134 if ((moment==null && other.moment==null) || (moment!=null && moment.equals(other.moment))) {
135 if ((song==null && other.song==null) || (song!=null && song.equals(other.song))) {
136 return id==other.id;
137 }
138 }
139 }
140 return false;
141 }
142
143
144
145
146
147 @Override
148 public int hashCode() {
149 return Long.valueOf(id).hashCode();
150 }
151 }