| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2013, 2015 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 | * Alexandre Montplaisir - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.tracecompass.tmf.ctf.core.event; |
| 14 | |
| 15 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
| 16 | |
| 17 | import org.eclipse.jdt.annotation.NonNullByDefault; |
| 18 | import org.eclipse.jdt.annotation.Nullable; |
| 19 | import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration; |
| 20 | import org.eclipse.tracecompass.ctf.core.event.IEventDefinition; |
| 21 | import org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent; |
| 22 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; |
| 23 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
| 24 | |
| 25 | import com.google.common.primitives.Longs; |
| 26 | |
| 27 | /** |
| 28 | * An implementation of {@link ITmfLostEvent} for use in the CTF adaptor. |
| 29 | * |
| 30 | * @author Alexandre Montplaisir |
| 31 | */ |
| 32 | @NonNullByDefault |
| 33 | public class CtfTmfLostEvent extends CtfTmfEvent implements ITmfLostEvent { |
| 34 | |
| 35 | private final TmfTimeRange fTimeRange; |
| 36 | private final long fNbLost; |
| 37 | |
| 38 | /** |
| 39 | * Constructor. Only {@link CtfTmfEventFactory} should call this. |
| 40 | * |
| 41 | * @param trace |
| 42 | * The origin trace |
| 43 | * @param rank |
| 44 | * The rank of the event in the trace |
| 45 | * @param content |
| 46 | * The event's payload (fields). In case this event has some. |
| 47 | * @param fileName |
| 48 | * The name of the trace file from which this event comes |
| 49 | * @param cpu |
| 50 | * The CPU on which this event happened |
| 51 | * @param declaration |
| 52 | * The CTF Event Declaration object that created this event |
| 53 | * @param timeRange |
| 54 | * The time range of lost events indicated by this one |
| 55 | * @param nbLost |
| 56 | * The number of lost events in the range |
| 57 | */ |
| 58 | CtfTmfLostEvent(CtfTmfTrace trace, |
| 59 | long rank, |
| 60 | String fileName, |
| 61 | int cpu, |
| 62 | IEventDeclaration declaration, |
| 63 | TmfTimeRange timeRange, |
| 64 | long nbLost, |
| 65 | IEventDefinition def) { |
| 66 | /* |
| 67 | * Only the factory should call this method, the cast to |
| 68 | * (TmfNanoTimestamp) should be safe. |
| 69 | */ |
| 70 | super(trace, rank, timeRange.getStartTime(), fileName, cpu, declaration, def); |
| 71 | fTimeRange = timeRange; |
| 72 | fNbLost = nbLost; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public TmfTimeRange getTimeRange() { |
| 77 | return fTimeRange; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public long getNbLostEvents() { |
| 82 | return fNbLost; |
| 83 | } |
| 84 | |
| 85 | // ------------------------------------------------------------------------ |
| 86 | // Object |
| 87 | // ------------------------------------------------------------------------ |
| 88 | |
| 89 | @Override |
| 90 | public int hashCode() { |
| 91 | final int prime = 31; |
| 92 | int result = super.hashCode(); |
| 93 | result = prime * result + getTimeRange().hashCode(); |
| 94 | result = prime * result + Longs.hashCode(getNbLostEvents()); |
| 95 | return result; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean equals(@Nullable Object obj) { |
| 100 | if (!super.equals(obj)) { |
| 101 | return false; |
| 102 | } |
| 103 | /* super.equals() checks that the classes are the same */ |
| 104 | CtfTmfLostEvent other = checkNotNull((CtfTmfLostEvent) obj); |
| 105 | if (!getTimeRange().equals(other.getTimeRange())) { |
| 106 | return false; |
| 107 | } |
| 108 | if (getNbLostEvents() != other.getNbLostEvents()) { |
| 109 | return false; |
| 110 | } |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | } |