Commit | Line | Data |
---|---|---|
866e5b51 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others |
866e5b51 FC |
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 | ||
ce2388e0 | 13 | package org.eclipse.linuxtools.internal.ctf.core.trace; |
866e5b51 FC |
14 | |
15 | import java.io.Serializable; | |
16 | import java.util.Comparator; | |
17 | ||
b64f60be | 18 | import org.eclipse.linuxtools.ctf.core.event.EventDefinition; |
d84419e1 | 19 | import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader; |
b64f60be | 20 | import org.eclipse.linuxtools.ctf.core.trace.Utils; |
ce2388e0 | 21 | |
866e5b51 FC |
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 | |
d84419e1 | 28 | Comparator<CTFStreamInputReader>, Serializable { |
866e5b51 FC |
29 | |
30 | // ------------------------------------------------------------------------ | |
31 | // Constants | |
32 | // ------------------------------------------------------------------------ | |
33 | ||
34 | private static final long serialVersionUID = 1066434959451875045L; | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Operations | |
38 | // ------------------------------------------------------------------------ | |
39 | ||
b64f60be EB |
40 | /** |
41 | * @throws NullPointerException | |
d84419e1 | 42 | * If any {@link CTFStreamInputReader} parameter is null, of if any |
b64f60be EB |
43 | * of them does not contain a current event. |
44 | */ | |
866e5b51 | 45 | @Override |
d84419e1 | 46 | public int compare(CTFStreamInputReader a, CTFStreamInputReader b) { |
b64f60be EB |
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); | |
866e5b51 FC |
53 | } |
54 | ||
55 | } |