Commit | Line | Data |
---|---|---|
534c96ce | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2014 Ericsson |
534c96ce FC |
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 | * Francois Chouinard - Initial API and implementation | |
d6b40e87 | 11 | * Alexandre Montplaisir - Made immutable |
534c96ce FC |
12 | *******************************************************************************/ |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.event; |
534c96ce | 15 | |
7709e228 MK |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.equalsNullable; |
17 | ||
2bdf0193 AM |
18 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
19 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; | |
20 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
534c96ce FC |
21 | |
22 | /** | |
23 | * A basic implementation of ITmfLostEvent. | |
24 | * | |
25 | * @author Francois Chouinard | |
7709e228 | 26 | */ |
534c96ce FC |
27 | public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
d6b40e87 AM |
33 | private final TmfTimeRange fTimeRange; |
34 | private final long fNbLostEvents; | |
534c96ce FC |
35 | |
36 | // ------------------------------------------------------------------------ | |
37 | // Constructors | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
534c96ce FC |
40 | /** |
41 | * Full constructor | |
42 | * | |
d6b40e87 AM |
43 | * @param trace |
44 | * the parent trace | |
45 | * @param rank | |
46 | * the event rank (in the trace) | |
47 | * @param timestamp | |
48 | * the event timestamp | |
d6b40e87 AM |
49 | * @param type |
50 | * the event type | |
d6b40e87 AM |
51 | * @param timeRange |
52 | * the 'problematic' time range | |
53 | * @param nbLostEvents | |
54 | * the number of lost events in the time range | |
534c96ce | 55 | */ |
d6b40e87 AM |
56 | public TmfLostEvent(final ITmfTrace trace, |
57 | final long rank, | |
58 | final ITmfTimestamp timestamp, | |
d6b40e87 | 59 | final ITmfEventType type, |
d6b40e87 AM |
60 | final TmfTimeRange timeRange, |
61 | final long nbLostEvents) { | |
e1de2fd4 | 62 | super(trace, rank, timestamp, type, null); |
534c96ce FC |
63 | fTimeRange = timeRange; |
64 | fNbLostEvents = nbLostEvents; | |
65 | } | |
66 | ||
534c96ce FC |
67 | // ------------------------------------------------------------------------ |
68 | // ITmfLostEvent | |
69 | // ------------------------------------------------------------------------ | |
70 | ||
534c96ce FC |
71 | @Override |
72 | public TmfTimeRange getTimeRange() { | |
73 | return fTimeRange; | |
74 | } | |
75 | ||
534c96ce FC |
76 | @Override |
77 | public long getNbLostEvents() { | |
78 | return fNbLostEvents; | |
79 | } | |
80 | ||
534c96ce FC |
81 | // ------------------------------------------------------------------------ |
82 | // Object | |
83 | // ------------------------------------------------------------------------ | |
84 | ||
534c96ce FC |
85 | @Override |
86 | public int hashCode() { | |
87 | final int prime = 31; | |
88 | int result = super.hashCode(); | |
89 | result = prime * result + (int) (fNbLostEvents ^ (fNbLostEvents >>> 32)); | |
90 | result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode()); | |
91 | return result; | |
92 | } | |
93 | ||
534c96ce FC |
94 | @Override |
95 | public boolean equals(Object obj) { | |
96 | if (this == obj) { | |
97 | return true; | |
98 | } | |
99 | if (!super.equals(obj)) { | |
100 | return false; | |
101 | } | |
102 | if (!(obj instanceof TmfLostEvent)) { | |
103 | return false; | |
104 | } | |
105 | TmfLostEvent other = (TmfLostEvent) obj; | |
106 | if (fNbLostEvents != other.fNbLostEvents) { | |
107 | return false; | |
108 | } | |
7709e228 | 109 | if (!equalsNullable(fTimeRange, other.fTimeRange)) { |
534c96ce FC |
110 | return false; |
111 | } | |
112 | return true; | |
113 | } | |
114 | ||
534c96ce FC |
115 | @Override |
116 | @SuppressWarnings("nls") | |
117 | public String toString() { | |
d6b40e87 AM |
118 | return getClass().getSimpleName() + " [Event=" + super.toString() + |
119 | ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]"; | |
534c96ce FC |
120 | } |
121 | ||
122 | } |