View Javadoc

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    * The history event is a structural copy of the corresponding database table, that is attributes of this class
10   * correspond to the table's columns.
11   * <p/>
12   * History events can be deletions, transfers, etc. of enzymes.
13   *
14   * @author Michael Darsow
15   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:04 $
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     * Nothing special.
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     * Makes instances of this class comparable.
48     *
49     * @param historyEvent The object to be compared to this instance.
50     * @return a pos. integer if this instance is greater than, a neg. integer if it is less than or 0 if it equals o.
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     * Checks if two <code>HistoryEvent</code> objects are equal.
61     *
62     * @param o The other <code>HistoryEvent</code> to compare with this one.
63     * @return <code>true</code>, if the two objects are equal.
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     * Calculates a unique hash code.
85     *
86     * @return the hash code.
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    * Returns <code>true</code> if the given node is the successor of this node.
102    *
103    * @param node The node to be compared to this node's relatives.
104    * @return <code>true</code> if the given node is the successor of this node.
105    */
106   public boolean isSuccessor(HistoryNode node) {
107     if (node == null) return afterNode == null;
108     return afterNode.equals(node);
109   }
110 
111 
112   // ------------------- GETTER & SETTER ------------------------
113 
114   /**
115    * Returns the relative node of the given node.
116    *
117    * @param node The node of which the relative is demanded.
118    * @return The relative node or <code>null</code> if no relative exists.
119    * @throws NullPointerException if the given node is <code>null</code>.
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 }