1 /*******************************************************************************
2 * Copyright (c) 2011, 2015 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.ctf
.core
.trace
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
17 import java
.io
.Serializable
;
18 import java
.util
.Comparator
;
20 import org
.eclipse
.tracecompass
.ctf
.core
.event
.EventDefinition
;
21 import org
.eclipse
.tracecompass
.ctf
.core
.trace
.CTFStreamInputReader
;
24 * <b><u>StreamInputReaderTimestampComparator</u></b>
26 * Compares two StreamInputReader by their timestamp (smaller comes before).
28 public class StreamInputReaderTimestampComparator
implements
29 Comparator
<CTFStreamInputReader
>, Serializable
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 private static final long serialVersionUID
= 1066434959451875045L;
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * @throws NullPointerException
43 * If any {@link CTFStreamInputReader} parameter is null, of if
44 * any of them does not contain a current event.
47 public int compare(CTFStreamInputReader a
, CTFStreamInputReader b
) {
48 EventDefinition eventA
= checkNotNull(a
.getCurrentEvent());
49 EventDefinition eventB
= checkNotNull(b
.getCurrentEvent());
51 long ta
= eventA
.getTimestamp();
52 long tb
= eventB
.getTimestamp();
53 return Utils
.unsignedCompare(ta
, tb
);