Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpoint.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.core.trace;
14
15 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
16
17 /**
18 * <b><u>TmfCheckpoint</u></b>
19 * <p>
20 * This class maps an event timestamp to a generic location.
21 */
22 @SuppressWarnings("rawtypes")
23 public class TmfCheckpoint implements Comparable<TmfCheckpoint>, Cloneable {
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
28
29 private TmfTimestamp fTimestamp;
30 private ITmfLocation<? extends Comparable> fLocation;
31
32 // ------------------------------------------------------------------------
33 // Constructors
34 // ------------------------------------------------------------------------
35
36 @SuppressWarnings("unused")
37 private TmfCheckpoint() {
38 fTimestamp = null;
39 fLocation = null;
40 }
41
42 /**
43 * @param ts the checkpoint timestamp
44 * @param location the corresponding trace location
45 */
46 public TmfCheckpoint(TmfTimestamp ts, ITmfLocation<? extends Comparable> location) {
47 fTimestamp = ts;
48 fLocation = location;
49 }
50
51 /**
52 * Deep copy constructor
53 * @param other the other checkpoint
54 */
55 public TmfCheckpoint(TmfCheckpoint other) {
56 if (other == null)
57 throw new IllegalArgumentException();
58 fTimestamp = (TmfTimestamp) other.fTimestamp.clone();
59 fLocation = other.fLocation.clone();
60 }
61
62 // ------------------------------------------------------------------------
63 // Accessors
64 // ------------------------------------------------------------------------
65
66 /**
67 * @return the checkpoint timestamp
68 */
69 public TmfTimestamp getTimestamp() {
70 return fTimestamp;
71 }
72
73 /**
74 * @return the checkpoint stream location
75 */
76 public ITmfLocation<?> getLocation() {
77 return fLocation;
78 }
79
80 // ------------------------------------------------------------------------
81 // Object
82 // ------------------------------------------------------------------------
83
84 @Override
85 public TmfCheckpoint clone() {
86 TmfCheckpoint result = null;
87 try {
88 result = (TmfCheckpoint) super.clone();
89 result.fTimestamp = new TmfTimestamp(fTimestamp);
90 result.fLocation = fLocation.clone();
91 return result;
92 } catch (CloneNotSupportedException e) {
93 e.printStackTrace();
94 }
95 return result;
96 }
97
98 @Override
99 public int hashCode() {
100 return fTimestamp.hashCode();
101 }
102
103 @Override
104 public boolean equals(Object other) {
105 if (!(other instanceof TmfCheckpoint)) {
106 return false;
107 }
108 TmfCheckpoint o = (TmfCheckpoint) other;
109 return fTimestamp.equals(o.fTimestamp);
110 }
111
112 @Override
113 @SuppressWarnings("nls")
114 public String toString() {
115 return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]";
116 }
117
118 // ------------------------------------------------------------------------
119 // Comparable
120 // ------------------------------------------------------------------------
121
122 @SuppressWarnings("unchecked")
123 @Override
124 public int compareTo(TmfCheckpoint other) {
125 if (fTimestamp == null || other.fTimestamp == null) {
126 return fLocation.getLocation().compareTo(other.fLocation.getLocation());
127 }
128 return fTimestamp.compareTo(other.fTimestamp, false);
129 }
130
131 }
This page took 0.045859 seconds and 5 git commands to generate.