Merge branch 'master' into TmfTraceModel-new
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / trace / TmfCheckpoint.java
CommitLineData
8c8bf09f 1/*******************************************************************************
5d837f9b 2 * Copyright (c) 2009, 2012 Ericsson
8c8bf09f
ASL
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
5d837f9b
FC
11 * Francois Chouinard - Updated as per TMF Trace Model 1.0
12 ******************************************************************************/
8c8bf09f 13
6c13869b 14package org.eclipse.linuxtools.tmf.core.trace;
8c8bf09f 15
4df4581d 16import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
8c8bf09f
ASL
17
18/**
19 * <b><u>TmfCheckpoint</u></b>
20 * <p>
ff4ed569 21 * This class maps an event timestamp to a generic location.
8c8bf09f 22 */
5d837f9b 23public class TmfCheckpoint implements ITmfCheckpoint {
8c8bf09f
ASL
24
25 // ------------------------------------------------------------------------
26 // Attributes
27 // ------------------------------------------------------------------------
cbdacf03 28
5d837f9b
FC
29 // The checkpoint location
30 private ITmfLocation<? extends Comparable<?>> fLocation;
31
32 // The checkpoint timestamp
4df4581d 33 private ITmfTimestamp fTimestamp;
8c8bf09f
ASL
34
35 // ------------------------------------------------------------------------
36 // Constructors
37 // ------------------------------------------------------------------------
38
5d837f9b
FC
39 /**
40 * Default constructor
41 */
ff4ed569 42 @SuppressWarnings("unused")
cbdacf03 43 private TmfCheckpoint() {
ff4ed569
FC
44 }
45
8c8bf09f 46 /**
5d837f9b
FC
47 * Full constructor
48 *
49 * @param timestamp the checkpoint timestamp
ff4ed569 50 * @param location the corresponding trace location
8c8bf09f 51 */
5d837f9b
FC
52 public TmfCheckpoint(final ITmfTimestamp timestamp, final ITmfLocation<? extends Comparable<?>> location) {
53 fTimestamp = timestamp;
8c8bf09f
ASL
54 fLocation = location;
55 }
56
ff4ed569 57 /**
5d837f9b 58 * Copy constructor
cbdacf03 59 *
ff4ed569
FC
60 * @param other the other checkpoint
61 */
cbdacf03
FC
62 public TmfCheckpoint(final TmfCheckpoint other) {
63 if (other == null)
64 throw new IllegalArgumentException();
5d837f9b
FC
65 fTimestamp = other.fTimestamp;
66 fLocation = other.fLocation;
67 }
68
69 // ------------------------------------------------------------------------
70 // Cloneable
71 // ------------------------------------------------------------------------
72
73 /* (non-Javadoc)
74 * @see java.lang.Object#clone()
75 */
76 @Override
77 public TmfCheckpoint clone() {
78 TmfCheckpoint clone = null;
79 try {
80 clone = (TmfCheckpoint) super.clone();
81 clone.fLocation = (fLocation != null) ? fLocation.clone() : null;
82 clone.fTimestamp = (fTimestamp != null) ? fTimestamp.clone() : null;
83 } catch (final CloneNotSupportedException e) {
84 }
85 return clone;
ff4ed569
FC
86 }
87
8c8bf09f
ASL
88 // ------------------------------------------------------------------------
89 // Accessors
90 // ------------------------------------------------------------------------
91
92 /**
ff4ed569 93 * @return the checkpoint timestamp
8c8bf09f 94 */
5d837f9b 95 @Override
4df4581d 96 public ITmfTimestamp getTimestamp() {
8c8bf09f
ASL
97 return fTimestamp;
98 }
99
100 /**
ff4ed569 101 * @return the checkpoint stream location
8c8bf09f 102 */
5d837f9b 103 @Override
452ad365 104 public ITmfLocation<?> getLocation() {
8c8bf09f
ASL
105 return fLocation;
106 }
107
cbd4ad82 108 // ------------------------------------------------------------------------
5d837f9b 109 // Comparable
cbd4ad82
FC
110 // ------------------------------------------------------------------------
111
550d787e 112 @Override
ff1ccee6 113 @SuppressWarnings({ "unchecked", "rawtypes" })
5d837f9b
FC
114 public int compareTo(final ITmfCheckpoint other) {
115 if (fTimestamp == null || other.getTimestamp() == null) {
116 final Comparable location1 = fLocation.getLocation();
117 final Comparable location2 = other.getLocation().getLocation();
118 return location1.compareTo(location2);
cbdacf03 119 }
5d837f9b 120 return fTimestamp.compareTo(other.getTimestamp(), false);
550d787e 121 }
cbdacf03 122
5d837f9b
FC
123 // ------------------------------------------------------------------------
124 // Object
125 // ------------------------------------------------------------------------
126
cbd4ad82
FC
127 @Override
128 public int hashCode() {
5d837f9b
FC
129 final int prime = 31;
130 int result = 1;
131 result = prime * result + ((fLocation == null) ? 0 : fLocation.hashCode());
132 result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
133 return result;
cbd4ad82 134 }
cbdacf03 135
cbd4ad82 136 @Override
5d837f9b
FC
137 public boolean equals(final Object obj) {
138 if (this == obj)
139 return true;
140 if (obj == null)
141 return false;
142 if (!(obj instanceof TmfCheckpoint))
cbdacf03 143 return false;
5d837f9b
FC
144 final TmfCheckpoint other = (TmfCheckpoint) obj;
145 if (fLocation == null) {
146 if (other.fLocation != null)
147 return false;
148 } else if (!fLocation.equals(other.fLocation))
149 return false;
150 if (fTimestamp == null) {
151 if (other.fTimestamp != null)
152 return false;
153 } else if (!fTimestamp.equals(other.fTimestamp))
154 return false;
155 return true;
cbd4ad82 156 }
cbdacf03 157
ff4ed569 158 @Override
3b38ea61 159 @SuppressWarnings("nls")
ff4ed569 160 public String toString() {
5d837f9b 161 return "TmfCheckpoint [fLocation=" + fLocation + ", fTimestamp=" + fTimestamp + "]";
8c8bf09f
ASL
162 }
163
164}
This page took 0.050788 seconds and 5 git commands to generate.