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
;
23 public class CtfTmfTimestamp
extends TmfTimestamp
{
27 public enum TimestampType
{
29 * yyyy/mm/dd hh:mm:ss.nnnnnnnnnn
37 * nnnnnnnnnnnnnnnnnnnnn ns
41 * ssssssssss.nnnnnnnnnn s
46 private TimestampType type
;
49 * Constructor for CtfTmfTimestamp.
50 * @param timestamp long
52 public CtfTmfTimestamp(long timestamp
) {
53 setValue(timestamp
, -9, 0);
54 type
= TimestampType
.DAY
;
59 * @param value TimestampType
61 public void setType(TimestampType value
) {
67 * @return TimestampType
69 public TimestampType
getType() {
77 * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse
78 * .linuxtools.tmf.core.event.ITmfTimestamp)
82 * @param ts ITmfTimestamp
83 * @return ITmfTimestamp
84 * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#getDelta(ITmfTimestamp)
87 public ITmfTimestamp
getDelta(ITmfTimestamp ts
) {
88 TmfTimestamp parent
= (TmfTimestamp
) super.getDelta(ts
);
89 long value
= parent
.getValue();
90 long exp
= parent
.getScale();
92 for (int i
= 0; i
< diff
; i
++) {
95 CtfTmfTimestamp retVal
= new CtfTmfTimestamp(value
);
96 if (value
> 100000000) {
97 retVal
.type
= TimestampType
.SECONDS
;
99 retVal
.type
= TimestampType
.NANOS
;
107 * @see java.lang.Object#toString()
110 public String
toString() {
113 return dateToString();
116 return toFullDateString();
119 return nanoToString();
122 return secondsToString();
125 return super.toString();
129 * Method secondsToString.
132 private String
secondsToString() {
133 double timestamp
= getValue();
134 timestamp
/= 1000000000;
135 StringBuilder retVal
= new StringBuilder();
136 retVal
.append(timestamp
);
137 retVal
.append(" s"); //$NON-NLS-1$
138 return retVal
.toString();
142 * Method nanoToString.
145 private String
nanoToString() {
146 final long timestamp
= getValue();
147 StringBuilder retVal
= new StringBuilder();
148 retVal
.append(timestamp
);
149 retVal
.append(" ns"); //$NON-NLS-1$
150 return retVal
.toString();
154 * Method dateToString.
157 private String
dateToString() {
158 final long timestamp
= getValue();
159 final Date d
= new Date(timestamp
/ 1000000);
160 final DateFormat df
= new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$
161 final long nanos
= (timestamp
% 1000000000);
162 StringBuilder output
= new StringBuilder();
163 output
.append(df
.format(d
));
164 output
.append(String
.format("%09d", nanos
)); //$NON-NLS-1$
165 return output
.toString();
169 * Method toFullDateString.
172 private String
toFullDateString() {
173 final long timestamp
= getValue();
174 final Date d
= new Date(timestamp
/ 1000000);
175 final DateFormat df
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
176 final long nanos
= (timestamp
% 1000000000);
177 StringBuilder output
= new StringBuilder();
178 output
.append(df
.format(d
));
179 output
.append(String
.format("%09d", nanos
)); //$NON-NLS-1$
180 return output
.toString();
184 * @see java.lang.Object#hashCode()
187 public int hashCode() {
188 final int prime
= 31;
189 int result
= super.hashCode() * prime
;
190 result
+= ((type
== null) ?
0 : type
.toString().hashCode());
195 * @see java.lang.Object#equals(java.lang.Object)
198 public boolean equals(Object obj
) {
202 if (!super.equals(obj
)) {
205 if (!(obj
instanceof CtfTmfTimestamp
)) {
208 CtfTmfTimestamp other
= (CtfTmfTimestamp
) obj
;
209 if (type
!= other
.type
) {
This page took 0.035706 seconds and 5 git commands to generate.