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