47ce93e4741826d98cf1f700ed1d4be8930408de
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / trace / StreamInputReaderTimestampComparator.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2015 Ericsson, Ecole Polytechnique de Montreal and others
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: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.ctf.core.trace;
14
15 import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
17 import java.io.Serializable;
18 import java.util.Comparator;
19
20 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
21 import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
22
23 /**
24 * <b><u>StreamInputReaderTimestampComparator</u></b>
25 * <p>
26 * Compares two StreamInputReader by their timestamp (smaller comes before).
27 */
28 public class StreamInputReaderTimestampComparator implements
29 Comparator<CTFStreamInputReader>, Serializable {
30
31 // ------------------------------------------------------------------------
32 // Constants
33 // ------------------------------------------------------------------------
34
35 private static final long serialVersionUID = 1066434959451875045L;
36
37 // ------------------------------------------------------------------------
38 // Operations
39 // ------------------------------------------------------------------------
40
41 /**
42 * @throws NullPointerException
43 * If any {@link CTFStreamInputReader} parameter is null, of if any
44 * of them does not contain a current event.
45 */
46 @Override
47 public int compare(CTFStreamInputReader a, CTFStreamInputReader b) {
48 EventDefinition eventA = checkNotNull(a.getCurrentEvent());
49 EventDefinition eventB = checkNotNull(b.getCurrentEvent());
50
51 long ta = eventA.getTimestamp();
52 long tb = eventB.getTimestamp();
53 return Utils.unsignedCompare(ta, tb);
54 }
55
56 }
This page took 0.031245 seconds and 4 git commands to generate.