Contribute native CTF Parser (bug370499)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / StreamInputReaderTimestampComparator.java
CommitLineData
866e5b51
FC
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
13package org.eclipse.linuxtools.ctf.core.trace;
14
15import java.io.Serializable;
16import java.util.Comparator;
17
18/**
19 * <b><u>StreamInputReaderTimestampComparator</u></b>
20 * <p>
21 * Compares two StreamInputReader by their timestamp (smaller comes before).
22 */
23public class StreamInputReaderTimestampComparator implements
24 Comparator<StreamInputReader>, Serializable {
25
26 // ------------------------------------------------------------------------
27 // Constants
28 // ------------------------------------------------------------------------
29
30 private static final long serialVersionUID = 1066434959451875045L;
31
32 // ------------------------------------------------------------------------
33 // Operations
34 // ------------------------------------------------------------------------
35
36 @Override
37 public int compare(StreamInputReader a, StreamInputReader b) {
38 // TODO: use unsigned comparison to avoid sign errors if needed
39 if (a.getCurrentEvent() == null) {
40 return 0;
41 }
42 if (b.getCurrentEvent() == null) {
43 return 0;
44 }
45 long ta = a.getCurrentEvent().timestamp;
46 long tb = b.getCurrentEvent().timestamp;
47
48 if (ta < tb) {
49 return -1;
50 } else if (ta > tb) {
51 return 1;
52 } else {
53 return 0;
54 }
55 }
56
57}
This page took 0.030996 seconds and 5 git commands to generate.