1 package uk.ac.ebi.intenz.domain.history;
2
3 import uk.ac.ebi.intenz.domain.DomainObject;
4 import uk.ac.ebi.intenz.domain.constants.EventConstant;
5
6 import java.util.Date;
7
8
9
10
11
12
13
14
15
16
17 public class HistoryEvent extends DomainObject implements Comparable<HistoryEvent> {
18 protected Long groupId;
19
20 protected Long eventId;
21
22 protected HistoryNode beforeNode;
23
24 protected HistoryNode afterNode;
25
26 protected EventConstant eventClass;
27
28 protected Date date;
29
30 protected String note;
31
32
33
34
35 public HistoryEvent() {
36 super();
37 this.groupId = new Long(0);
38 this.eventId = new Long(0);
39 this.beforeNode = null;
40 this.afterNode = null;
41 this.eventClass = EventConstant.CREATION;
42 this.date = null;
43 this.note = "";
44 }
45
46
47
48
49
50
51
52 public int compareTo(HistoryEvent historyEvent) {
53 if (this.getDate().before(historyEvent.getDate())) return -1;
54 if (this.getDate().after(historyEvent.getDate())) return 1;
55
56 return 0;
57 }
58
59
60
61
62
63
64
65 public boolean equals(Object o) {
66 if (this == o) return true;
67 if (!(o instanceof HistoryEvent)) return false;
68 if (!super.equals(o)) return false;
69
70 final HistoryEvent event = (HistoryEvent) o;
71
72 if (afterNode != null ? !afterNode.equals(event.afterNode) : event.afterNode != null) return false;
73 if (beforeNode != null ? !beforeNode.equals(event.beforeNode) : event.beforeNode != null) return false;
74 if (date != null ? !date.equals(event.date) : event.date != null) return false;
75 if (eventClass != null ? !eventClass.equals(event.eventClass) : event.eventClass != null) return false;
76 if (eventId != null ? !eventId.equals(event.eventId) : event.eventId != null) return false;
77 if (groupId != null ? !groupId.equals(event.groupId) : event.groupId != null) return false;
78 if (note != null ? !note.equals(event.note) : event.note != null) return false;
79
80 return true;
81 }
82
83
84
85
86
87
88 public int hashCode() {
89 int result = super.hashCode();
90 result = 29 * result + (groupId != null ? groupId.hashCode() : 0);
91 result = 29 * result + (eventId != null ? eventId.hashCode() : 0);
92 result = 29 * result + (beforeNode != null ? beforeNode.hashCode() : 0);
93 result = 29 * result + (afterNode != null ? afterNode.hashCode() : 0);
94 result = 29 * result + (eventClass != null ? eventClass.hashCode() : 0);
95 result = 29 * result + (date != null ? date.hashCode() : 0);
96 result = 29 * result + (note != null ? note.hashCode() : 0);
97 return result;
98 }
99
100
101
102
103
104
105
106 public boolean isSuccessor(HistoryNode node) {
107 if (node == null) return afterNode == null;
108 return afterNode.equals(node);
109 }
110
111
112
113
114
115
116
117
118
119
120
121 public HistoryNode getRelative(HistoryNode node) {
122 if (node == null) throw new NullPointerException();
123
124 if (beforeNode == null || afterNode == null) return null;
125
126 if (beforeNode.getEnzymeEntry().getId().equals(node.getEnzymeEntry().getId()) ) return afterNode;
127 return beforeNode;
128 }
129
130 public Long getGroupId() {
131 return groupId;
132 }
133
134 public void setGroupId(Long groupId) {
135 if (groupId == null) throw new NullPointerException("Parameter 'groupId' must not be null.");
136 this.groupId = groupId;
137 }
138
139 public Long getEventId() {
140 return eventId;
141 }
142
143 public void setEventId(Long eventId) {
144 if (eventId == null) throw new NullPointerException("Parameter 'eventId' must not be null.");
145 this.eventId = eventId;
146 }
147
148 public HistoryNode getBeforeNode() {
149 return beforeNode;
150 }
151
152 public void setBeforeNode(HistoryNode beforeNode) {
153 this.beforeNode = beforeNode;
154 }
155
156 public HistoryNode getAfterNode() {
157 return afterNode;
158 }
159
160 public void setAfterNode(HistoryNode afterNode) {
161 this.afterNode = afterNode;
162 }
163
164 public EventConstant getEventClass() {
165 return eventClass;
166 }
167
168 public void setEventClass(EventConstant eventClass) {
169 if (eventClass == null) throw new NullPointerException("Parameter 'eventClass' must not be null.");
170 this.eventClass = eventClass;
171 }
172
173 public Date getDate() {
174 return date;
175 }
176
177 public void setDate(Date date) {
178 if (date == null) throw new NullPointerException("Parameter 'date' must not be null.");
179 this.date = date;
180 }
181
182 public String getNote() {
183 return note;
184 }
185
186 public void setNote(String note) {
187 if (note == null) throw new NullPointerException("Parameter 'note' must not be null.");
188 this.note = note;
189 }
190 }