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