Improve API.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / trace / StreamInputReaderTimestampComparator.java
1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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.trace.StreamInputReader;
19
20
21 /**
22 * <b><u>StreamInputReaderTimestampComparator</u></b>
23 * <p>
24 * Compares two StreamInputReader by their timestamp (smaller comes before).
25 */
26 public class StreamInputReaderTimestampComparator implements
27 Comparator<StreamInputReader>, Serializable {
28
29 // ------------------------------------------------------------------------
30 // Constants
31 // ------------------------------------------------------------------------
32
33 private static final long serialVersionUID = 1066434959451875045L;
34
35 // ------------------------------------------------------------------------
36 // Operations
37 // ------------------------------------------------------------------------
38
39 @Override
40 public int compare(StreamInputReader a, StreamInputReader b) {
41 // TODO: use unsigned comparison to avoid sign errors if needed
42 if (a.getCurrentEvent() == null) {
43 return 0;
44 }
45 if (b.getCurrentEvent() == null) {
46 return 0;
47 }
48 long ta = a.getCurrentEvent().getTimestamp();
49 long tb = b.getCurrentEvent().getTimestamp();
50
51 if (ta < tb) {
52 return -1;
53 } else if (ta > tb) {
54 return 1;
55 } else {
56 return 0;
57 }
58 }
59
60 }
This page took 0.031201 seconds and 5 git commands to generate.