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