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
{
28 FULL_DATE
, DAY
, NANOS
, SECONDS
31 private TimestampType type
;
34 * Constructor for CtfTmfTimestamp.
35 * @param timestamp long
37 public CtfTmfTimestamp(long timestamp
) {
38 setValue(timestamp
, -9, 0);
39 type
= TimestampType
.DAY
;
44 * @param value TimestampType
46 public void setType(TimestampType value
) {
52 * @return TimestampType
54 public TimestampType
getType() {
62 * org.eclipse.linuxtools.tmf.core.event.TmfTimestamp#getDelta(org.eclipse
63 * .linuxtools.tmf.core.event.ITmfTimestamp)
67 * @param ts ITmfTimestamp
68 * @return ITmfTimestamp
69 * @see org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp#getDelta(ITmfTimestamp)
72 public ITmfTimestamp
getDelta(ITmfTimestamp ts
) {
73 TmfTimestamp parent
= (TmfTimestamp
) super.getDelta(ts
);
74 long value
= parent
.getValue();
75 long exp
= parent
.getScale();
77 for (int i
= 0; i
< diff
; i
++) {
80 CtfTmfTimestamp retVal
= new CtfTmfTimestamp(value
);
81 if (value
> 100000000) {
82 retVal
.type
= TimestampType
.SECONDS
;
84 retVal
.type
= TimestampType
.NANOS
;
92 * @see java.lang.Object#toString()
95 public String
toString() {
98 return dateToString();
101 return toFullDateString();
104 return nanoToString();
107 return secondsToString();
110 return super.toString();
114 * Method secondsToString.
117 private String
secondsToString() {
118 double timestamp
= getValue();
119 timestamp
/= 1000000000;
120 StringBuilder retVal
= new StringBuilder();
121 retVal
.append(timestamp
);
122 retVal
.append(" s"); //$NON-NLS-1$
123 return retVal
.toString();
127 * Method nanoToString.
130 private String
nanoToString() {
131 final long timestamp
= getValue();
132 StringBuilder retVal
= new StringBuilder();
133 retVal
.append(timestamp
);
134 retVal
.append(" ns"); //$NON-NLS-1$
135 return retVal
.toString();
139 * Method dateToString.
142 private String
dateToString() {
143 final long timestamp
= getValue();
144 final Date d
= new Date(timestamp
/ 1000000);
145 final DateFormat df
= new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$
146 final long nanos
= (timestamp
% 1000000000);
147 StringBuilder output
= new StringBuilder();
148 output
.append(df
.format(d
));
149 output
.append(String
.format("%09d", nanos
)); //$NON-NLS-1$
150 return output
.toString();
154 * Method toFullDateString.
157 private String
toFullDateString() {
158 final long timestamp
= getValue();
159 final Date d
= new Date(timestamp
/ 1000000);
160 final DateFormat df
= new SimpleDateFormat("yyyy-MM-dd 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 * @see java.lang.Object#hashCode()
172 public int hashCode() {
173 final int prime
= 31;
174 int result
= super.hashCode() * prime
;
175 result
+= ((type
== null) ?
0 : type
.toString().hashCode());
180 * @see java.lang.Object#equals(java.lang.Object)
183 public boolean equals(Object obj
) {
187 if (!super.equals(obj
)) {
190 if (!(obj
instanceof CtfTmfTimestamp
)) {
193 CtfTmfTimestamp other
= (CtfTmfTimestamp
) obj
;
194 if (type
!= other
.type
) {
This page took 0.045332 seconds and 6 git commands to generate.