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 | ||
6c13869b | 13 | package org.eclipse.linuxtools.tmf.core.trace; |
8c8bf09f | 14 | |
6c13869b | 15 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
8c8bf09f ASL |
16 | |
17 | /** | |
18 | * <b><u>TmfCheckpoint</u></b> | |
19 | * <p> | |
ff4ed569 | 20 | * This class maps an event timestamp to a generic location. |
8c8bf09f | 21 | */ |
a79913eb | 22 | @SuppressWarnings("rawtypes") |
550d787e | 23 | public class TmfCheckpoint implements Comparable<TmfCheckpoint>, Cloneable { |
8c8bf09f ASL |
24 | |
25 | // ------------------------------------------------------------------------ | |
26 | // Attributes | |
27 | // ------------------------------------------------------------------------ | |
28 | ||
550d787e | 29 | private TmfTimestamp fTimestamp; |
a79913eb | 30 | private ITmfLocation<? extends Comparable> fLocation; |
8c8bf09f ASL |
31 | |
32 | // ------------------------------------------------------------------------ | |
33 | // Constructors | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
ff4ed569 FC |
36 | @SuppressWarnings("unused") |
37 | private TmfCheckpoint() { | |
38 | fTimestamp = null; | |
39 | fLocation = null; | |
40 | } | |
41 | ||
8c8bf09f | 42 | /** |
ff4ed569 FC |
43 | * @param ts the checkpoint timestamp |
44 | * @param location the corresponding trace location | |
8c8bf09f | 45 | */ |
a79913eb | 46 | public TmfCheckpoint(TmfTimestamp ts, ITmfLocation<? extends Comparable> location) { |
8c8bf09f ASL |
47 | fTimestamp = ts; |
48 | fLocation = location; | |
49 | } | |
50 | ||
ff4ed569 FC |
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 | ||
8c8bf09f ASL |
62 | // ------------------------------------------------------------------------ |
63 | // Accessors | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
66 | /** | |
ff4ed569 | 67 | * @return the checkpoint timestamp |
8c8bf09f ASL |
68 | */ |
69 | public TmfTimestamp getTimestamp() { | |
70 | return fTimestamp; | |
71 | } | |
72 | ||
73 | /** | |
ff4ed569 | 74 | * @return the checkpoint stream location |
8c8bf09f | 75 | */ |
452ad365 | 76 | public ITmfLocation<?> getLocation() { |
8c8bf09f ASL |
77 | return fLocation; |
78 | } | |
79 | ||
cbd4ad82 FC |
80 | // ------------------------------------------------------------------------ |
81 | // Object | |
82 | // ------------------------------------------------------------------------ | |
83 | ||
550d787e FC |
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 | ||
cbd4ad82 FC |
98 | @Override |
99 | public int hashCode() { | |
ff4ed569 | 100 | return fTimestamp.hashCode(); |
cbd4ad82 FC |
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 | ||
ff4ed569 | 112 | @Override |
3b38ea61 | 113 | @SuppressWarnings("nls") |
ff4ed569 FC |
114 | public String toString() { |
115 | return "[TmfCheckpoint(" + fTimestamp + "," + fLocation + ")]"; | |
116 | } | |
117 | ||
8c8bf09f ASL |
118 | // ------------------------------------------------------------------------ |
119 | // Comparable | |
120 | // ------------------------------------------------------------------------ | |
121 | ||
a79913eb FC |
122 | @SuppressWarnings("unchecked") |
123 | @Override | |
d4011df2 | 124 | public int compareTo(TmfCheckpoint other) { |
a79913eb FC |
125 | if (fTimestamp == null || other.fTimestamp == null) { |
126 | return fLocation.getLocation().compareTo(other.fLocation.getLocation()); | |
127 | } | |
8c8bf09f ASL |
128 | return fTimestamp.compareTo(other.fTimestamp, false); |
129 | } | |
130 | ||
131 | } |