ctf: Introduce IEventDefinition
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.core / src / org / eclipse / tracecompass / tmf / ctf / core / event / CtfTmfLostEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ctf.core.event;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
20 import org.eclipse.tracecompass.ctf.core.event.IEventDefinition;
21 import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent;
22 import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
23 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
24 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
25
26 import com.google.common.primitives.Longs;
27
28 /**
29 * An implementation of {@link ITmfLostEvent} for use in the CTF adaptor.
30 *
31 * @author Alexandre Montplaisir
32 */
33 @NonNullByDefault
34 public class CtfTmfLostEvent extends CtfTmfEvent implements ITmfLostEvent {
35
36 private final TmfTimeRange fTimeRange;
37 private final long fNbLost;
38
39 /**
40 * Constructor. Only {@link CtfTmfEventFactory} should call this.
41 *
42 * @param trace
43 * The origin trace
44 * @param rank
45 * The rank of the event in the trace
46 * @param content
47 * The event's payload (fields). In case this event has some.
48 * @param fileName
49 * The name of the trace file from which this event comes
50 * @param cpu
51 * The CPU on which this event happened
52 * @param declaration
53 * The CTF Event Declaration object that created this event
54 * @param timeRange
55 * The time range of lost events indicated by this one
56 * @param nbLost
57 * The number of lost events in the range
58 */
59 CtfTmfLostEvent(CtfTmfTrace trace,
60 long rank,
61 String fileName,
62 int cpu,
63 IEventDeclaration declaration,
64 TmfTimeRange timeRange,
65 long nbLost,
66 IEventDefinition def) {
67 /*
68 * Only the factory should call this method, the cast to
69 * (TmfNanoTimestamp) should be safe.
70 */
71 super(trace, rank, (TmfNanoTimestamp) timeRange.getStartTime(), fileName, cpu, declaration, def);
72 fTimeRange = timeRange;
73 fNbLost = nbLost;
74 }
75
76 @Override
77 public TmfTimeRange getTimeRange() {
78 return fTimeRange;
79 }
80
81 @Override
82 public long getNbLostEvents() {
83 return fNbLost;
84 }
85
86 // ------------------------------------------------------------------------
87 // Object
88 // ------------------------------------------------------------------------
89
90 @Override
91 public int hashCode() {
92 final int prime = 31;
93 int result = super.hashCode();
94 result = prime * result + getTimeRange().hashCode();
95 result = prime * result + Longs.hashCode(getNbLostEvents());
96 return result;
97 }
98
99 @Override
100 public boolean equals(@Nullable Object obj) {
101 if (!super.equals(obj)) {
102 return false;
103 }
104 /* super.equals() checks that the classes are the same */
105 CtfTmfLostEvent other = checkNotNull((CtfTmfLostEvent) obj);
106 if (!getTimeRange().equals(other.getTimeRange())) {
107 return false;
108 }
109 if (getNbLostEvents() != other.getNbLostEvents()) {
110 return false;
111 }
112 return true;
113 }
114
115 }
This page took 0.03372 seconds and 5 git commands to generate.