1
2
3
4
5
6
7 package nl.tudelft.simulation.event;
8
9 import java.io.Serializable;
10
11 /***
12 * The EventType is a masker used for the subscription to asynchronous events.
13 * Eventtypes are used by EventProducers to show which events they potentially
14 * fire. EventTypes should be defined as static final fields.
15 * <p>
16 * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
17 * University of Technology </a>, the Netherlands.
18 * <p>
19 * See for project information <a
20 * href="http://www.simulation.tudelft.nl/dsol/event">www.simulation.tudelft.nl/event
21 * </a> <br>
22 * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
23 * General Public License (LGPL) </a>, no warranty
24 *
25 * @author <a href="http://www.peter-jacobs.com">Peter Jacobs </a>
26 * @version $Revision: 1.6 $ $Date: 2005/08/04 12:08:32 $
27 * @since 1.5
28 */
29 public final class EventType implements Serializable
30 {
31 /*** value is the flag number */
32 private int value;
33
34 /*** name refers to the name of the eventType */
35 private String name;
36
37 /***
38 * constructs a new EventType.
39 *
40 * @param name the name of this eventType. Two values are not appreciated :
41 * <code>null</code> and <code>""</code>.
42 */
43 public EventType(final String name)
44 {
45 super();
46 if (name == null || name.equals(""))
47 {
48 throw new IllegalArgumentException("name == null || name == \"\"");
49 }
50 this.value = name.hashCode();
51 this.name = name;
52 }
53
54 /***
55 * @see java.lang.Object#equals(java.lang.Object)
56 */
57 @Override
58 public boolean equals(final Object arg0)
59 {
60 if (!(arg0 instanceof EventType))
61 {
62 return false;
63 }
64 return this.value == ((EventType) arg0).value;
65 }
66
67 /***
68 * Returns a hash code for the name of the this eventType. The hash code for
69 * an <code>EventType</code> object is computed as <blockquote>
70 *
71 * <pre>
72 *
73 *
74 *
75 *
76 *
77 *
78 * s[0]*31ˆ(n-1) + s[1]*31ˆ(n-2) + ... + s[n-1]
79 *
80 *
81 *
82 *
83 *
84 *
85 * </pre>
86 *
87 * </blockquote> using <code>int</code> arithmetic, where
88 * <code>s[i]</code> is the <i>i </i>th character of the name of the
89 * eventType, <code>n</code> is the length of the name, and <code>^</code>
90 * indicates exponentiation. This algoritm assures JVM, host, time
91 * independency.
92 *
93 * @return a hash code value for this object.
94 */
95 @Override
96 public int hashCode()
97 {
98 return this.value;
99 }
100
101 /***
102 * @see java.lang.Object#toString()
103 */
104 @Override
105 public String toString()
106 {
107 return this.name;
108 }
109 }