View Javadoc

1   package uk.ac.ebi.intenz.domain.constants;
2   
3   /**
4    * This class provides all event constants.
5    * <p/>
6    * Instances of this class are immutable.
7    *
8    * @author Michael Darsow
9    * @version $Revision: 1.3 $ $Date: 2009/04/16 15:01:04 $
10   * @deprecated use enumeration {@link Event} instead.
11   */
12  public class EventConstant {
13    private final String eventCode;
14  
15    private final String eventFullName;
16  
17    public static final EventConstant DELETION = new EventConstant("DEL", "deleted");
18    public static final EventConstant TRANSFER = new EventConstant("TRA", "transferred");
19    public static final EventConstant MODIFICATION = new EventConstant("MOD", "modified");
20    public static final EventConstant CREATION = new EventConstant("NEW", "created");
21  
22    /**
23     * Object cannot be created outside this class.
24     *
25     * @param eventCode     The event code.
26     * @param eventFullName Full name of this code.
27     */
28    private EventConstant(String eventCode, String eventFullName) {
29      this.eventCode = eventCode;
30      this.eventFullName = eventFullName;
31    }
32  
33    /**
34     * Returns the corresponding instance of the given event code.
35     * <p/>
36     * If the event code does not match any code an exception is thrown.
37     *
38     * @param eventCode The event code.
39     * @return the class constant corresponding to the given code.
40     * @throws IllegalArgumentException if the code is invalid.
41     */
42    public static EventConstant valueOf(String eventCode) {
43      if (eventCode.equals(DELETION.getCode())) return DELETION;
44      if (eventCode.equals(TRANSFER.getCode())) return TRANSFER;
45      if (eventCode.equals(MODIFICATION.getCode())) return MODIFICATION;
46      if (eventCode.equals(CREATION.getCode())) return CREATION;
47  	throw new IllegalArgumentException();
48    }
49  
50    /**
51     * Standard equals method.
52     *
53     * @param o Object to be compared to this one.
54     * @return <code>true</code> if the objects are equal.
55     */
56    public boolean equals(Object o) {
57      if (this == o) return true;
58      if (!(o instanceof EventConstant)) return false;
59  
60      final EventConstant eventConstants = (EventConstant) o;
61  
62      if (eventCode != null ? !eventCode.equals(eventConstants.eventCode) : eventConstants.eventCode != null) return false;
63      if (eventFullName != null ? !eventFullName.equals(eventConstants.eventFullName) : eventConstants.eventFullName != null) return false;
64  
65      return true;
66    }
67  
68    /**
69     * Returns the hash code of this object.
70     *
71     * @return the hash code of this object.
72     */
73    public int hashCode() {
74      int result;
75      result = (eventCode != null ? eventCode.hashCode() : 0);
76      result = 29 * result + (eventFullName != null ? eventFullName.hashCode() : 0);
77      return result;
78    }
79  
80    /**
81     * Returns the database code.
82     *
83     * @return the database code.
84     */
85    public String toString() {
86      return eventFullName;
87    }
88  
89  
90    // ------------------- GETTER ------------------
91  
92    /**
93     * Returns the code of this event.
94     *
95     * @return the event's code.
96     */
97    public String getCode() {
98      return eventCode;
99    }
100 }