Commit | Line | Data |
---|---|---|
8c8bf09f ASL |
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.trace; | |
14 | ||
15 | import org.eclipse.linuxtools.tmf.event.TmfTimestamp; | |
16 | ||
17 | /** | |
18 | * <b><u>TmfCheckpoint</u></b> | |
19 | * <p> | |
ff4ed569 | 20 | * This class maps an event timestamp to a generic location. |
8c8bf09f | 21 | */ |
550d787e | 22 | public class TmfCheckpoint implements Comparable<TmfCheckpoint>, Cloneable { |
8c8bf09f ASL |
23 | |
24 | // ------------------------------------------------------------------------ | |
25 | // Attributes | |
26 | // ------------------------------------------------------------------------ | |
27 | ||
550d787e FC |
28 | private TmfTimestamp fTimestamp; |
29 | private ITmfLocation<?> fLocation; | |
8c8bf09f ASL |
30 | |
31 | // ------------------------------------------------------------------------ | |
32 | // Constructors | |
33 | // ------------------------------------------------------------------------ | |
34 | ||
ff4ed569 FC |
35 | @SuppressWarnings("unused") |
36 | private TmfCheckpoint() { | |
37 | fTimestamp = null; | |
38 | fLocation = null; | |
39 | } | |
40 | ||
8c8bf09f | 41 | /** |
ff4ed569 FC |
42 | * @param ts the checkpoint timestamp |
43 | * @param location the corresponding trace location | |
8c8bf09f | 44 | */ |
452ad365 | 45 | public TmfCheckpoint(TmfTimestamp ts, ITmfLocation<?> location) { |
8c8bf09f ASL |
46 | fTimestamp = ts; |
47 | fLocation = location; | |
48 | } | |
49 | ||
ff4ed569 FC |
50 | /** |
51 | * Deep copy constructor | |
52 | * @param other the other checkpoint | |
53 | */ | |
54 | public TmfCheckpoint(TmfCheckpoint other) { | |
55 | if (other == null) | |
56 | throw new IllegalArgumentException(); | |
57 | fTimestamp = (TmfTimestamp) other.fTimestamp.clone(); | |
58 | fLocation = other.fLocation.clone(); | |
59 | } | |
60 | ||
8c8bf09f ASL |
61 | // ------------------------------------------------------------------------ |
62 | // Accessors | |
63 | // ------------------------------------------------------------------------ | |
64 | ||
65 | /** | |
ff4ed569 | 66 | * @return the checkpoint timestamp |
8c8bf09f ASL |
67 | */ |
68 | public TmfTimestamp getTimestamp() { | |
69 | return fTimestamp; | |
70 | } | |
71 | ||
72 | /** | |
ff4ed569 | 73 | * @return the checkpoint stream location |
8c8bf09f | 74 | */ |
452ad365 | 75 | public ITmfLocation<?> getLocation() { |
8c8bf09f ASL |
76 | return fLocation; |
77 | } | |
78 | ||
cbd4ad82 FC |
79 | // ------------------------------------------------------------------------ |
80 | // Object | |
81 | // ------------------------------------------------------------------------ | |
82 | ||
550d787e FC |
83 | @Override |
84 | public TmfCheckpoint clone() { | |
85 | TmfCheckpoint result = null; | |
86 | try { | |
87 | result = (TmfCheckpoint) super.clone(); | |
88 | result.fTimestamp = new TmfTimestamp(fTimestamp); | |
89 | result.fLocation = fLocation.clone(); | |
90 | return result; | |
91 | } catch (CloneNotSupportedException e) { | |
92 | e.printStackTrace(); | |
93 | } | |
94 | return result; | |
95 | } | |
96 | ||
cbd4ad82 FC |
97 | @Override |
98 | public int hashCode() { | |
ff4ed569 | 99 | return fTimestamp.hashCode(); |
cbd4ad82 FC |
100 | } |
101 | ||
102 | @Override | |
103 | public boolean equals(Object other) { | |
104 | if (!(other instanceof TmfCheckpoint)) { | |
105 | return false; | |
106 | } | |
107 | TmfCheckpoint o = (TmfCheckpoint) other; | |
108 | return fTimestamp.equals(o.fTimestamp); | |
109 | } | |
110 | ||
ff4ed569 FC |
111 | @Override |
112 | public String toString() { | |
113 | return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]"; | |
114 | } | |
115 | ||
8c8bf09f ASL |
116 | // ------------------------------------------------------------------------ |
117 | // Comparable | |
118 | // ------------------------------------------------------------------------ | |
119 | ||
d4011df2 FC |
120 | @Override |
121 | public int compareTo(TmfCheckpoint other) { | |
8c8bf09f ASL |
122 | return fTimestamp.compareTo(other.fTimestamp, false); |
123 | } | |
124 | ||
125 | } |