[Bug309042] Improved test code coverage and other mundane issues.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.event;
14
15 /**
16 * <b><u>TmfEvent</u></b>
17 * <p>
18 * The basic event structure in the TMF. In its canonical form, an event has:
19 * <ul>
20 * <li> a normalized timestamp
21 * <li> a source (reporter)
22 * <li> a type
23 * <li> a content
24 * </ul>
25 * For convenience, a free-form reference field is also provided. It could be
26 * used as e.g. a location marker in the event stream to distinguish between
27 * otherwise identical events.
28 *
29 * Notice that for performance reasons TmfEvent is NOT immutable. If a copy
30 * of the event is needed, use the copy constructor.
31 */
32 public class TmfEvent extends TmfData {
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37
38 protected TmfTimestamp fEffectiveTimestamp;
39 protected TmfTimestamp fOriginalTimestamp;
40 protected TmfEventSource fSource;
41 protected TmfEventType fType;
42 protected TmfEventReference fReference;
43
44 // Content requires a reference to the parent event so it is initialized
45 // using setContent()
46 protected TmfEventContent fContent;
47
48 // ------------------------------------------------------------------------
49 // Constructors
50 // ------------------------------------------------------------------------
51
52 /**
53 * @param originalTS the original timestamp
54 * @param effectiveTS the effective timestamp
55 * @param source the event source (generator)
56 * @param type the event type
57 * @param reference a free-form reference field
58 */
59 public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS,
60 TmfEventSource source, TmfEventType type, TmfEventReference reference)
61 {
62 if (source == null || type == null || effectiveTS == null) {
63 throw new IllegalArgumentException();
64 }
65 fOriginalTimestamp = originalTS;
66 fEffectiveTimestamp = effectiveTS;
67 fSource = source;
68 fType = type;
69 fReference = reference;
70 }
71
72 /**
73 * @param timestamp the effective timestamp
74 * @param source the event source (generator)
75 * @param type the event type
76 * @param reference a free-form reference field
77 */
78 public TmfEvent(TmfTimestamp timestamp, TmfEventSource source,
79 TmfEventType type, TmfEventReference reference)
80 {
81 this(timestamp, timestamp, source, type, reference);
82 }
83
84 /**
85 * Copy constructor
86 *
87 * @param other the original event
88 */
89 public TmfEvent(TmfEvent other) {
90 if (other == null)
91 throw new IllegalArgumentException();
92 fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp);
93 fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp);
94 fSource = new TmfEventSource(other.fSource);
95 fType = new TmfEventType(other.fType);
96 fContent = new TmfEventContent(other.fContent);
97 fReference = new TmfEventReference(other.fReference);
98 }
99
100 @SuppressWarnings("unused")
101 private TmfEvent() {
102 throw new AssertionError();
103 }
104
105 // ------------------------------------------------------------------------
106 // Accessors
107 // ------------------------------------------------------------------------
108
109 /**
110 * @return the effective event timestamp
111 */
112 public TmfTimestamp getTimestamp() {
113 return fEffectiveTimestamp;
114 }
115
116 /**
117 * @return the original event timestamp
118 */
119 public TmfTimestamp getOriginalTimestamp() {
120 return fOriginalTimestamp;
121 }
122
123 /**
124 * @return the event source
125 */
126 public TmfEventSource getSource() {
127 return fSource;
128 }
129
130 /**
131 * @return the event type
132 */
133 public TmfEventType getType() {
134 return fType;
135 }
136
137 /**
138 * @return the event content
139 */
140 public TmfEventContent getContent() {
141 return fContent;
142 }
143
144 /**
145 * @return the event reference
146 */
147 public TmfEventReference getReference() {
148 return fReference;
149 }
150
151 /**
152 * @param content the new event content
153 */
154 public void setContent(TmfEventContent content) {
155 fContent = content;
156 }
157
158 // ------------------------------------------------------------------------
159 // Object
160 // ------------------------------------------------------------------------
161
162 @Override
163 public int hashCode() {
164 int result = 17;
165 result = 37 * result + fSource.hashCode();
166 result = 37 * result + fType.hashCode();
167 result = 37 * result + fEffectiveTimestamp.hashCode();
168 return result;
169 }
170
171 @Override
172 public boolean equals(Object other) {
173 if (!(other instanceof TmfEvent))
174 return false;
175 TmfEvent o = (TmfEvent) other;
176 return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) &&
177 fSource.equals(o.fSource) &&
178 fType.equals(o.fType) &&
179 fContent.equals(o.fContent);
180 }
181
182 @Override
183 public String toString() {
184 return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]";
185 }
186
187 }
This page took 0.034294 seconds and 5 git commands to generate.