source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/jfc/data/JFCEvent.java @ 318

Last change on this file since 318 was 318, checked in by sherbold, 13 years ago
  • Property svn:mime-type set to text/plain
File size: 3.6 KB
Line 
1package de.ugoe.cs.eventbench.jfc.data;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import de.ugoe.cs.eventbench.data.IReplayable;
7import de.ugoe.cs.eventbench.data.ReplayableEvent;
8
9/**
10 * <p>
11 * This class defines JFC events.
12 * </p>
13 *
14 * @author Steffen Herbold
15 * @version 1.0
16 */
17public class JFCEvent extends ReplayableEvent<IReplayable> {
18
19        /**
20         * <p>
21         * Id for object serialization.
22         * </p>
23         */
24        private static final long serialVersionUID = 1L;
25
26        /**
27         * <p>
28         * Internal map of parameters associated with the event.
29         * </p>
30         */
31        private Map<String, String> parameters;
32
33        /**
34         * <p>
35         * Information about the event source.
36         * </p>
37         */
38        private Map<String, String> sourceParameters;
39
40        /**
41         * <p>
42         * Information about the parent of the event source.
43         * </p>
44         */
45        private Map<String, String> parentParameters;
46
47        /**
48         * <p>
49         * Constructor. Creates a new JFCEvent.
50         * </p>
51         *
52         * @param type
53         *            type of the event
54         */
55        public JFCEvent(String type) {
56                super(type);
57                parameters = new HashMap<String, String>();
58                sourceParameters = new HashMap<String, String>();
59                parentParameters = new HashMap<String, String>();
60        }
61
62        /**
63         * <p>
64         * Adds a new parameter to the event.
65         * </p>
66         *
67         * @param name
68         *            name of the parameter
69         * @param value
70         *            value of the parameter
71         */
72        public void addParameter(String name, String value) {
73                parameters.put(name, value);
74        }
75
76        /**
77         * <p>
78         * Retrieves the value of a parameter.
79         * </p>
80         *
81         * @param name
82         *            name of the parameter
83         * @return value of the parameter
84         */
85        public String getParameter(String name) {
86                return parameters.get(name);
87        }
88
89        /**
90         * <p>
91         * Adds new information about the source of the event.
92         * </p>
93         *
94         * @param name
95         *            name of the information
96         * @param value
97         *            value of the information
98         */
99        public void addSourceInformation(String name, String value) {
100                if( "toString".equals(name) ) {
101                        setTarget(value);
102                }
103                sourceParameters.put(name, value);
104        }
105
106        /**
107         * <p>
108         * Retrieves information about the source of the event.
109         * </p>
110         *
111         * @param name
112         *            name of the information
113         * @return value of the information
114         */
115        public String getSourceInformation(String name) {
116                return sourceParameters.get(name);
117        }
118
119        /**
120         * <p>
121         * Adds new information about the parent of the source of the event.
122         * </p>
123         *
124         * @param name
125         *            name of the information
126         * @param value
127         *            value of the information
128         */
129        public void addParentInformation(String name, String value) {
130                parentParameters.put(name, value);
131        }
132
133        /**
134         * <p>
135         * Retrieves information about the parent of the source of the event.
136         * </p>
137         *
138         * @param name
139         *            name of the information
140         * @return value of the information
141         */
142        public String getParentInformation(String name) {
143                return parentParameters.get(name);
144        }
145
146        /*
147         * (non-Javadoc)
148         *
149         * @see de.ugoe.cs.eventbench.data.ReplayableEvent#equals(java.lang.Object)
150         */
151        @Override
152        public boolean equals(Object other) {
153                if (other == this) {
154                        return true;
155                }
156                if (other instanceof JFCEvent) {
157                        return super.equals(other)
158                                        && parameters.equals(((JFCEvent) other).parameters);
159                }
160                return false;
161        }
162
163        /*
164         * (non-Javadoc)
165         *
166         * @see de.ugoe.cs.eventbench.data.ReplayableEvent#hashCode()
167         */
168        @Override
169        public int hashCode() {
170                int hashCode = super.hashCode();
171                hashCode *= parameters.hashCode();
172                return hashCode;
173        }
174
175}
Note: See TracBrowser for help on using the repository browser.