tmf: Make TmfEvent immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfLostEvent.java
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
15 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
16 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
17
18 /**
19 * A basic implementation of ITmfLostEvent.
20 *
21 * @author Francois Chouinard
22 * @version 1.0
23 * @since 1.2
24 */
25 public 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 */
58 public TmfLostEvent(final ITmfTrace trace, final long rank, final ITmfTimestamp timestamp,
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 super( event.getTrace(),
73 event.getRank(),
74 event.getTimestamp(),
75 event.getSource(),
76 event.getType(),
77 event.getContent(),
78 event.getReference());
79 fTimeRange = event.getTimeRange();
80 fNbLostEvents = event.getNbLostEvents();
81 }
82
83 // ------------------------------------------------------------------------
84 // ITmfLostEvent
85 // ------------------------------------------------------------------------
86
87 @Override
88 public TmfTimeRange getTimeRange() {
89 return fTimeRange;
90 }
91
92 @Override
93 public long getNbLostEvents() {
94 return fNbLostEvents;
95 }
96
97 // ------------------------------------------------------------------------
98 // Convenience setters
99 // ------------------------------------------------------------------------
100
101 /**
102 * @param timeRange the 'problematic' time range
103 */
104 protected void setTimeRange(final TmfTimeRange timeRange) {
105 fTimeRange = timeRange;
106 }
107
108 /**
109 * @param nbLostEvents the number of lost events
110 */
111 protected void setNbLostEvents(final long nbLostEvents) {
112 fNbLostEvents = nbLostEvents;
113 }
114
115 // ------------------------------------------------------------------------
116 // Object
117 // ------------------------------------------------------------------------
118
119 @Override
120 public int hashCode() {
121 final int prime = 31;
122 int result = super.hashCode();
123 result = prime * result + (int) (fNbLostEvents ^ (fNbLostEvents >>> 32));
124 result = prime * result + ((fTimeRange == null) ? 0 : fTimeRange.hashCode());
125 return result;
126 }
127
128 @Override
129 public boolean equals(Object obj) {
130 if (this == obj) {
131 return true;
132 }
133 if (!super.equals(obj)) {
134 return false;
135 }
136 if (!(obj instanceof TmfLostEvent)) {
137 return false;
138 }
139 TmfLostEvent other = (TmfLostEvent) obj;
140 if (fNbLostEvents != other.fNbLostEvents) {
141 return false;
142 }
143 if (fTimeRange == null) {
144 if (other.fTimeRange != null) {
145 return false;
146 }
147 } else if (!fTimeRange.equals(other.fTimeRange)) {
148 return false;
149 }
150 return true;
151 }
152
153 @Override
154 @SuppressWarnings("nls")
155 public String toString() {
156 return "TmfLostEvent [Event=" + super.toString() + ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]";
157 }
158
159 }
This page took 0.032863 seconds and 5 git commands to generate.