Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
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: | |
1f506a43 | 10 | * Francois Chouinard - Initial API and implementation |
8c8bf09f ASL |
11 | *******************************************************************************/ |
12 | ||
13 | package org.eclipse.linuxtools.tmf.event; | |
14 | ||
15 | /** | |
16 | * <b><u>TmfEvent</u></b> | |
17 | * <p> | |
1f506a43 | 18 | * The basic event structure in the TMF. In its canonical form, an event has: |
8c8bf09f ASL |
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. | |
28b94d61 FC |
28 | * |
29 | * Notice that for performance reasons TmfEvent is NOT immutable. If a copy | |
cbd4ad82 | 30 | * of the event is needed, use the copy constructor. |
8c8bf09f | 31 | */ |
f9673903 | 32 | public class TmfEvent extends TmfData implements Cloneable { |
8c8bf09f | 33 | |
36548af3 FC |
34 | // ------------------------------------------------------------------------ |
35 | // Constants | |
36 | // ------------------------------------------------------------------------ | |
37 | ||
38 | public static final TmfEvent NullEvent = new TmfEvent(); | |
39 | ||
cbd4ad82 | 40 | // ------------------------------------------------------------------------ |
8c8bf09f | 41 | // Attributes |
cbd4ad82 | 42 | // ------------------------------------------------------------------------ |
8c8bf09f | 43 | |
28b94d61 FC |
44 | protected TmfTimestamp fEffectiveTimestamp; |
45 | protected TmfTimestamp fOriginalTimestamp; | |
46 | protected TmfEventSource fSource; | |
47 | protected TmfEventType fType; | |
48 | protected TmfEventReference fReference; | |
8c8bf09f | 49 | |
28b94d61 FC |
50 | // Content requires a reference to the parent event so it is initialized |
51 | // using setContent() | |
52 | protected TmfEventContent fContent; | |
53 | ||
cbd4ad82 | 54 | // ------------------------------------------------------------------------ |
8c8bf09f | 55 | // Constructors |
cbd4ad82 | 56 | // ------------------------------------------------------------------------ |
8c8bf09f ASL |
57 | |
58 | /** | |
cbd4ad82 FC |
59 | * @param originalTS the original timestamp |
60 | * @param effectiveTS the effective timestamp | |
61 | * @param source the event source (generator) | |
62 | * @param type the event type | |
63 | * @param reference a free-form reference field | |
8c8bf09f | 64 | */ |
28b94d61 FC |
65 | public TmfEvent(TmfTimestamp originalTS, TmfTimestamp effectiveTS, |
66 | TmfEventSource source, TmfEventType type, TmfEventReference reference) | |
8c8bf09f | 67 | { |
28b94d61 | 68 | fOriginalTimestamp = originalTS; |
1f506a43 | 69 | fEffectiveTimestamp = effectiveTS; |
28b94d61 FC |
70 | fSource = source; |
71 | fType = type; | |
72 | fReference = reference; | |
1f506a43 FC |
73 | } |
74 | ||
75 | /** | |
cbd4ad82 FC |
76 | * @param timestamp the effective timestamp |
77 | * @param source the event source (generator) | |
78 | * @param type the event type | |
79 | * @param reference a free-form reference field | |
1f506a43 FC |
80 | */ |
81 | public TmfEvent(TmfTimestamp timestamp, TmfEventSource source, | |
28b94d61 | 82 | TmfEventType type, TmfEventReference reference) |
1f506a43 | 83 | { |
28b94d61 | 84 | this(timestamp, timestamp, source, type, reference); |
4e3aa37d FC |
85 | } |
86 | ||
87 | /** | |
cbd4ad82 | 88 | * Copy constructor |
28b94d61 | 89 | * |
cbd4ad82 | 90 | * @param other the original event |
4e3aa37d | 91 | */ |
28b94d61 | 92 | public TmfEvent(TmfEvent other) { |
cbd4ad82 FC |
93 | if (other == null) |
94 | throw new IllegalArgumentException(); | |
95 | fOriginalTimestamp = new TmfTimestamp(other.fOriginalTimestamp); | |
96 | fEffectiveTimestamp = new TmfTimestamp(other.fEffectiveTimestamp); | |
97 | fSource = new TmfEventSource(other.fSource); | |
98 | fType = new TmfEventType(other.fType); | |
99 | fContent = new TmfEventContent(other.fContent); | |
100 | fReference = new TmfEventReference(other.fReference); | |
28b94d61 FC |
101 | } |
102 | ||
28b94d61 | 103 | private TmfEvent() { |
36548af3 FC |
104 | } |
105 | ||
106 | @Override | |
107 | public boolean isNullRef() { | |
108 | return this == NullEvent; | |
8c8bf09f ASL |
109 | } |
110 | ||
cbd4ad82 | 111 | // ------------------------------------------------------------------------ |
8c8bf09f | 112 | // Accessors |
cbd4ad82 | 113 | // ------------------------------------------------------------------------ |
8c8bf09f ASL |
114 | |
115 | /** | |
cbd4ad82 | 116 | * @return the effective event timestamp |
8c8bf09f ASL |
117 | */ |
118 | public TmfTimestamp getTimestamp() { | |
1f506a43 FC |
119 | return fEffectiveTimestamp; |
120 | } | |
121 | ||
122 | /** | |
cbd4ad82 | 123 | * @return the original event timestamp |
1f506a43 FC |
124 | */ |
125 | public TmfTimestamp getOriginalTimestamp() { | |
126 | return fOriginalTimestamp; | |
8c8bf09f ASL |
127 | } |
128 | ||
129 | /** | |
cbd4ad82 | 130 | * @return the event source |
8c8bf09f ASL |
131 | */ |
132 | public TmfEventSource getSource() { | |
133 | return fSource; | |
134 | } | |
135 | ||
136 | /** | |
cbd4ad82 | 137 | * @return the event type |
8c8bf09f ASL |
138 | */ |
139 | public TmfEventType getType() { | |
140 | return fType; | |
141 | } | |
142 | ||
28b94d61 | 143 | /** |
cbd4ad82 | 144 | * @return the event content |
8c8bf09f ASL |
145 | */ |
146 | public TmfEventContent getContent() { | |
147 | return fContent; | |
148 | } | |
149 | ||
150 | /** | |
cbd4ad82 | 151 | * @return the event reference |
8c8bf09f ASL |
152 | */ |
153 | public TmfEventReference getReference() { | |
154 | return fReference; | |
155 | } | |
1f506a43 | 156 | |
cbd4ad82 FC |
157 | /** |
158 | * @param content the new event content | |
159 | */ | |
160 | public void setContent(TmfEventContent content) { | |
161 | fContent = content; | |
162 | } | |
163 | ||
164 | // ------------------------------------------------------------------------ | |
165 | // Object | |
166 | // ------------------------------------------------------------------------ | |
28b94d61 FC |
167 | |
168 | @Override | |
cbd4ad82 FC |
169 | public int hashCode() { |
170 | int result = 17; | |
171 | result = 37 * result + fSource.hashCode(); | |
172 | result = 37 * result + fType.hashCode(); | |
173 | result = 37 * result + fEffectiveTimestamp.hashCode(); | |
174 | return result; | |
175 | } | |
176 | ||
177 | @Override | |
178 | public boolean equals(Object other) { | |
179 | if (!(other instanceof TmfEvent)) | |
180 | return false; | |
181 | TmfEvent o = (TmfEvent) other; | |
182 | return fEffectiveTimestamp.equals(o.fEffectiveTimestamp) && | |
183 | fSource.equals(o.fSource) && | |
184 | fType.equals(o.fType) && | |
185 | fContent.equals(o.fContent); | |
186 | } | |
28b94d61 | 187 | |
4e3aa37d | 188 | @Override |
3b38ea61 | 189 | @SuppressWarnings("nls") |
4e3aa37d | 190 | public String toString() { |
cbd4ad82 | 191 | return "[TmfEvent(" + fEffectiveTimestamp + "," + fSource + "," + fType + "," + fContent + ")]"; |
4e3aa37d | 192 | } |
cbd4ad82 | 193 | |
f9673903 FC |
194 | @Override |
195 | public TmfEvent clone() { | |
1a971e96 FC |
196 | TmfEvent clone = null; |
197 | try { | |
198 | clone = (TmfEvent) super.clone(); | |
199 | clone.fOriginalTimestamp = fOriginalTimestamp.clone(); | |
200 | clone.fEffectiveTimestamp = fEffectiveTimestamp.clone(); | |
201 | clone.fSource = fSource.clone(); | |
202 | clone.fType = fType.clone(); | |
203 | clone.fReference = fReference.clone(); | |
204 | clone.fContent = fContent.clone(); | |
205 | } | |
206 | catch (CloneNotSupportedException e) { | |
207 | e.printStackTrace(); | |
208 | } | |
209 | ||
210 | return clone; | |
f9673903 FC |
211 | } |
212 | ||
8c8bf09f | 213 | } |