| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2012, 2014 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 | * Alexandre Montplaisir - Made immutable |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.tracecompass.tmf.core.event; |
| 15 | |
| 16 | import java.util.Objects; |
| 17 | |
| 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; |
| 21 | |
| 22 | /** |
| 23 | * A basic implementation of ITmfLostEvent. |
| 24 | * |
| 25 | * @author Francois Chouinard |
| 26 | */ |
| 27 | public class TmfLostEvent extends TmfEvent implements ITmfLostEvent { |
| 28 | |
| 29 | // ------------------------------------------------------------------------ |
| 30 | // Attributes |
| 31 | // ------------------------------------------------------------------------ |
| 32 | |
| 33 | private final TmfTimeRange fTimeRange; |
| 34 | private final long fNbLostEvents; |
| 35 | |
| 36 | // ------------------------------------------------------------------------ |
| 37 | // Constructors |
| 38 | // ------------------------------------------------------------------------ |
| 39 | |
| 40 | /** |
| 41 | * Full constructor |
| 42 | * |
| 43 | * @param trace |
| 44 | * the parent trace |
| 45 | * @param rank |
| 46 | * the event rank (in the trace) |
| 47 | * @param timestamp |
| 48 | * the event timestamp |
| 49 | * @param type |
| 50 | * the event type |
| 51 | * @param timeRange |
| 52 | * the 'problematic' time range |
| 53 | * @param nbLostEvents |
| 54 | * the number of lost events in the time range |
| 55 | */ |
| 56 | public TmfLostEvent(final ITmfTrace trace, |
| 57 | final long rank, |
| 58 | final ITmfTimestamp timestamp, |
| 59 | final ITmfEventType type, |
| 60 | final TmfTimeRange timeRange, |
| 61 | final long nbLostEvents) { |
| 62 | super(trace, rank, timestamp, type, null); |
| 63 | fTimeRange = timeRange; |
| 64 | fNbLostEvents = nbLostEvents; |
| 65 | } |
| 66 | |
| 67 | // ------------------------------------------------------------------------ |
| 68 | // ITmfLostEvent |
| 69 | // ------------------------------------------------------------------------ |
| 70 | |
| 71 | @Override |
| 72 | public TmfTimeRange getTimeRange() { |
| 73 | return fTimeRange; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public long getNbLostEvents() { |
| 78 | return fNbLostEvents; |
| 79 | } |
| 80 | |
| 81 | // ------------------------------------------------------------------------ |
| 82 | // Object |
| 83 | // ------------------------------------------------------------------------ |
| 84 | |
| 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 | |
| 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 | } |
| 109 | if (!Objects.equals(fTimeRange, other.fTimeRange)) { |
| 110 | return false; |
| 111 | } |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | @SuppressWarnings("nls") |
| 117 | public String toString() { |
| 118 | return getClass().getSimpleName() + " [Event=" + super.toString() + |
| 119 | ", fTimeRange=" + fTimeRange + ", fNbLostEvents=" + fNbLostEvents + "]"; |
| 120 | } |
| 121 | |
| 122 | } |