Commit | Line | Data |
---|---|---|
534c96ce FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 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 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.event; | |
14 | ||
3bd46eef AM |
15 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
16 | import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; | |
534c96ce FC |
17 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
18 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
19 | ||
20 | /** | |
21 | * A basic implementation of ITmfLostEvent. | |
22 | * | |
23 | * @author Francois Chouinard | |
24 | * @version 1.0 | |
77c4a6df | 25 | * @since 1.2 |
534c96ce FC |
26 | */ |
27 | public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { | |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | private TmfTimeRange fTimeRange; | |
34 | private long fNbLostEvents; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Constructors | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
40 | /** | |
41 | * Default constructor which boils down to the default TmfEvent with no | |
42 | * lost event over the empty time range. | |
43 | */ | |
44 | public TmfLostEvent() { | |
45 | this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, TmfTimeRange.NULL_RANGE, 0); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Full constructor | |
50 | * | |
51 | * @param trace the parent trace | |
52 | * @param rank the event rank (in the trace) | |
53 | * @param timestamp the event timestamp | |
54 | * @param source the event source | |
55 | * @param type the event type | |
56 | * @param reference the event reference | |
57 | * @param timeRange the 'problematic' time range | |
58 | * @param nbLostEvents the number of lost events in the time range | |
3bd46eef | 59 | * @since 2.0 |
534c96ce | 60 | */ |
a13e7612 | 61 | public TmfLostEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp, |
534c96ce FC |
62 | final String source, final ITmfEventType type, final String reference, final TmfTimeRange timeRange, final long nbLostEvents) |
63 | { | |
64 | super(trace, rank, timestamp, source, type, null, reference); | |
65 | fTimeRange = timeRange; | |
66 | fNbLostEvents = nbLostEvents; | |
67 | } | |
68 | ||
69 | /** | |
70 | * Copy constructor | |
71 | * | |
72 | * @param event the original event | |
73 | */ | |
74 | public TmfLostEvent(final ITmfLostEvent event) { | |
bd54d363 AM |
75 | super( event.getTrace(), |
76 | event.getRank(), | |
77 | event.getTimestamp(), | |
78 | event.getSource(), | |
79 | event.getType(), | |
80 | event.getContent(), | |
81 | event.getReference()); | |
534c96ce FC |
82 | fTimeRange = event.getTimeRange(); |
83 | fNbLostEvents = event.getNbLostEvents(); | |
84 | } | |
85 | ||
86 | // ------------------------------------------------------------------------ | |
87 | // ITmfLostEvent | |
88 | // ------------------------------------------------------------------------ | |
89 | ||
3bd46eef AM |
90 | /** |
91 | * @since 2.0 | |
92 | */ | |
534c96ce FC |
93 | @Override |
94 | public TmfTimeRange getTimeRange() { | |
95 | return fTimeRange; | |
96 | } | |
97 | ||
534c96ce FC |
98 | @Override |
99 | public long getNbLostEvents() { | |
100 | return fNbLostEvents; | |
101 | } | |
102 | ||
103 | // ------------------------------------------------------------------------ | |
104 | // Convenience setters | |
105 | // ------------------------------------------------------------------------ | |
106 | ||
107 | /** | |
108 | * @param timeRange the 'problematic' time range | |
3bd46eef | 109 | * @since 2.0 |
534c96ce FC |
110 | */ |
111 | protected void setTimeRange(final TmfTimeRange timeRange) { | |
112 | fTimeRange = timeRange; | |
113 | } | |
114 | ||
115 | /** | |
116 | * @param nbLostEvents the number of lost events | |
117 | */ | |
118 | protected void setNbLostEvents(final long nbLostEvents) { | |
119 | fNbLostEvents = nbLostEvents; | |
120 | } | |
121 | ||
534c96ce FC |
122 | // ------------------------------------------------------------------------ |
123 | // Object | |
124 | // ------------------------------------------------------------------------ | |
125 | ||
534c96ce FC |
126 | @Override |
127 | public int hashCode() { | |
128 | final int prime = 31; | |
129 | int result = super.hashCode(); | |
130 | result = prime * result + (int) (fNbLostEvents ^ (fNbLostEvents >>> 32)); | |
131 | result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode()); | |
132 | return result; | |
133 | } | |
134 | ||
534c96ce FC |
135 | @Override |
136 | public boolean equals(Object obj) { | |
137 | if (this == obj) { | |
138 | return true; | |
139 | } | |
140 | if (!super.equals(obj)) { | |
141 | return false; | |
142 | } | |
143 | if (!(obj instanceof TmfLostEvent)) { | |
144 | return false; | |
145 | } | |
146 | TmfLostEvent other = (TmfLostEvent) obj; | |
147 | if (fNbLostEvents != other.fNbLostEvents) { | |
148 | return false; | |
149 | } | |
150 | if (fTimeRange == null) { | |
151 | if (other.fTimeRange != null) { | |
152 | return false; | |
153 | } | |
154 | } else if (!fTimeRange.equals(other.fTimeRange)) { | |
155 | return false; | |
156 | } | |
157 | return true; | |
158 | } | |
159 | ||
534c96ce FC |
160 | @Override |
161 | @SuppressWarnings("nls") | |
162 | public String toString() { | |
163 | return "TmfLostEvent [Event=" + super.toString() + ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]"; | |
164 | } | |
165 | ||
166 | } |