1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
14 import java
.text
.DateFormat
;
15 import java
.text
.SimpleDateFormat
;
16 import java
.util
.Date
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
22 * The CTF adapter for the TMF timestamp
25 * @author Matthew khouzam
27 public class CtfTmfTimestamp
extends TmfTimestamp
{
31 public enum TimestampType
{
33 * yyyy/mm/dd hh:mm:ss.nnnnnnnnnn
41 * nnnnnnnnnnnnnnnnnnnnn ns
45 * ssssssssss.nnnnnnnnnn s
50 private TimestampType type
;
53 * Constructor for CtfTmfTimestamp.
54 * @param timestamp long
56 public CtfTmfTimestamp(long timestamp
) {
57 setValue(timestamp
, -9, 0);
58 type
= TimestampType
.DAY
;
63 * @param value TimestampType
65 public void setType(TimestampType value
) {
71 * @return TimestampType
73 public TimestampType
getType() {
81 * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse
82 * .linuxtools.tmf.core.event.ITmfTimestamp)
86 * @param ts ITmfTimestamp
87 * @return ITmfTimestamp
88 * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#getDelta(ITmfTimestamp)
91 public ITmfTimestamp
getDelta(ITmfTimestamp ts
) {
92 TmfTimestamp parent
= (TmfTimestamp
) super.getDelta(ts
);
93 long value
= parent
.getValue();
94 long exp
= parent
.getScale();
96 for (int i
= 0; i
< diff
; i
++) {
99 CtfTmfTimestamp retVal
= new CtfTmfTimestamp(value
);
100 if (value
> 100000000) {
101 retVal
.type
= TimestampType
.SECONDS
;
103 retVal
.type
= TimestampType
.NANOS
;
111 * @see java.lang.Object#toString()
114 public String
toString() {
117 return dateToString();
120 return toFullDateString();
123 return nanoToString();
126 return secondsToString();
131 return super.toString();
135 * Method secondsToString.
138 private String
secondsToString() {
139 double timestamp
= getValue();
140 timestamp
/= 1000000000;
141 StringBuilder retVal
= new StringBuilder();
142 retVal
.append(timestamp
);
143 retVal
.append(" s"); //$NON-NLS-1$
144 return retVal
.toString();
148 * Method nanoToString.
151 private String
nanoToString() {
152 final long timestamp
= getValue();
153 StringBuilder retVal
= new StringBuilder();
154 retVal
.append(timestamp
);
155 retVal
.append(" ns"); //$NON-NLS-1$
156 return retVal
.toString();
160 * Method dateToString.
163 private String
dateToString() {
164 final long timestamp
= getValue();
165 final Date d
= new Date(timestamp
/ 1000000);
166 final DateFormat df
= new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$
167 final long nanos
= (timestamp
% 1000000000);
168 StringBuilder output
= new StringBuilder();
169 output
.append(df
.format(d
));
170 output
.append(String
.format("%09d", nanos
)); //$NON-NLS-1$
171 return output
.toString();
175 * Method toFullDateString.
178 private String
toFullDateString() {
179 final long timestamp
= getValue();
180 final Date d
= new Date(timestamp
/ 1000000);
181 final DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
182 final long nanos
= (timestamp
% 1000000000);
183 StringBuilder output
= new StringBuilder();
184 output
.append(df
.format(d
));
185 output
.append(String
.format("%09d", nanos
)); //$NON-NLS-1$
186 return output
.toString();
190 * @see java.lang.Object#hashCode()
193 public int hashCode() {
194 final int prime
= 31;
195 int result
= super.hashCode() * prime
;
196 result
+= ((type
== null) ?
0 : type
.toString().hashCode());
201 * @see java.lang.Object#equals(java.lang.Object)
204 public boolean equals(Object obj
) {
208 if (!super.equals(obj
)) {
211 if (!(obj
instanceof CtfTmfTimestamp
)) {
214 CtfTmfTimestamp other
= (CtfTmfTimestamp
) obj
;
215 if (type
!= other
.type
) {
This page took 0.035094 seconds and 5 git commands to generate.