Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfLostEvent.java
CommitLineData
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
13package org.eclipse.linuxtools.tmf.core.event;
14
15import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
16import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
17
18/**
19 * A basic implementation of ITmfLostEvent.
20 *
21 * @author Francois Chouinard
22 * @version 1.0
a13e7612 23 * @since 2.0
534c96ce
FC
24*/
25public class TmfLostEvent extends TmfEvent implements ITmfLostEvent {
26
27 // ------------------------------------------------------------------------
28 // Attributes
29 // ------------------------------------------------------------------------
30
31 private TmfTimeRange fTimeRange;
32 private long fNbLostEvents;
33
34 // ------------------------------------------------------------------------
35 // Constructors
36 // ------------------------------------------------------------------------
37
38 /**
39 * Default constructor which boils down to the default TmfEvent with no
40 * lost event over the empty time range.
41 */
42 public TmfLostEvent() {
43 this(null, ITmfContext.UNKNOWN_RANK, null, null, null, null, TmfTimeRange.NULL_RANGE, 0);
44 }
45
46 /**
47 * Full constructor
48 *
49 * @param trace the parent trace
50 * @param rank the event rank (in the trace)
51 * @param timestamp the event timestamp
52 * @param source the event source
53 * @param type the event type
54 * @param reference the event reference
55 * @param timeRange the 'problematic' time range
56 * @param nbLostEvents the number of lost events in the time range
57 */
a13e7612 58 public TmfLostEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp,
534c96ce
FC
59 final String source, final ITmfEventType type, final String reference, final TmfTimeRange timeRange, final long nbLostEvents)
60 {
61 super(trace, rank, timestamp, source, type, null, reference);
62 fTimeRange = timeRange;
63 fNbLostEvents = nbLostEvents;
64 }
65
66 /**
67 * Copy constructor
68 *
69 * @param event the original event
70 */
71 public TmfLostEvent(final ITmfLostEvent event) {
72 if (event == null) {
73 throw new IllegalArgumentException();
74 }
75 setTrace(event.getTrace());
76 setRank(event.getRank());
77 setTimestamp(event.getTimestamp());
78 setSource(event.getSource());
79 setType(event.getType());
80 setContent(event.getContent());
81 setReference(event.getReference());
82
83 fTimeRange = event.getTimeRange();
84 fNbLostEvents = event.getNbLostEvents();
85 }
86
87 // ------------------------------------------------------------------------
88 // ITmfLostEvent
89 // ------------------------------------------------------------------------
90
91 /* (non-Javadoc)
92 * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getTimeRange()
93 */
94 @Override
95 public TmfTimeRange getTimeRange() {
96 return fTimeRange;
97 }
98
99 /* (non-Javadoc)
100 * @see org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent#getNbLostEvents()
101 */
102 @Override
103 public long getNbLostEvents() {
104 return fNbLostEvents;
105 }
106
107 // ------------------------------------------------------------------------
108 // Convenience setters
109 // ------------------------------------------------------------------------
110
111 /**
112 * @param timeRange the 'problematic' time range
113 */
114 protected void setTimeRange(final TmfTimeRange timeRange) {
115 fTimeRange = timeRange;
116 }
117
118 /**
119 * @param nbLostEvents the number of lost events
120 */
121 protected void setNbLostEvents(final long nbLostEvents) {
122 fNbLostEvents = nbLostEvents;
123 }
124
125 // ------------------------------------------------------------------------
126 // Cloneable
127 // ------------------------------------------------------------------------
128
129 /* (non-Javadoc)
130 * @see java.lang.Object#clone()
131 */
132 @Override
133 public TmfLostEvent clone() {
134 TmfLostEvent clone = null;
135 try {
136 clone = (TmfLostEvent) super.clone();
137 clone.fTimeRange = fTimeRange.clone();
138 clone.fNbLostEvents = fNbLostEvents;
139 } catch (CloneNotSupportedException e) {
140 }
141 return clone;
142 }
143
144 // ------------------------------------------------------------------------
145 // Object
146 // ------------------------------------------------------------------------
147
148 /* (non-Javadoc)
149 * @see java.lang.Object#hashCode()
150 */
151 @Override
152 public int hashCode() {
153 final int prime = 31;
154 int result = super.hashCode();
155 result = prime * result + (int) (fNbLostEvents ^ (fNbLostEvents >>> 32));
156 result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode());
157 return result;
158 }
159
160 /* (non-Javadoc)
161 * @see java.lang.Object#equals(java.lang.Object)
162 */
163 @Override
164 public boolean equals(Object obj) {
165 if (this == obj) {
166 return true;
167 }
168 if (!super.equals(obj)) {
169 return false;
170 }
171 if (!(obj instanceof TmfLostEvent)) {
172 return false;
173 }
174 TmfLostEvent other = (TmfLostEvent) obj;
175 if (fNbLostEvents != other.fNbLostEvents) {
176 return false;
177 }
178 if (fTimeRange == null) {
179 if (other.fTimeRange != null) {
180 return false;
181 }
182 } else if (!fTimeRange.equals(other.fTimeRange)) {
183 return false;
184 }
185 return true;
186 }
187
188 /* (non-Javadoc)
189 * @see java.lang.Object#toString()
190 */
191 @Override
192 @SuppressWarnings("nls")
193 public String toString() {
194 return "TmfLostEvent [Event=" + super.toString() + ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]";
195 }
196
197}
This page took 0.030554 seconds and 5 git commands to generate.