Merge master in TmfTraceModel
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTimestamp.java
1 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
2
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5 import java.util.Date;
6
7 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
8 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
9
10 public class CtfTmfTimestamp extends TmfTimestamp implements ITmfTimestamp {
11
12 final private CtfTmfTrace fTrace;
13
14 public CtfTmfTimestamp(long timestamp, CtfTmfTrace trace) {
15 fTrace = trace;
16 fValue = timestamp;
17 fScale = (byte) -9;
18 }
19
20 /* (non-Javadoc)
21 * @see java.lang.Object#hashCode()
22 */
23 @Override
24 public int hashCode() {
25 final int prime = 31;
26 int result = super.hashCode();
27 result = (prime * result) + ((fTrace == null) ? 0 : fTrace.hashCode());
28 return result;
29 }
30
31 /* (non-Javadoc)
32 * @see java.lang.Object#equals(java.lang.Object)
33 */
34 @Override
35 public boolean equals(Object obj) {
36 if (this == obj) {
37 return true;
38 }
39 if (!super.equals(obj)) {
40 return false;
41 }
42 if (!(obj instanceof CtfTmfTimestamp)) {
43 return false;
44 }
45 CtfTmfTimestamp other = (CtfTmfTimestamp) obj;
46 if (fTrace == null) {
47 if (other.fTrace != null) {
48 return false;
49 }
50 } else if (!fTrace.equals(other.fTrace)) {
51 return false;
52 }
53 return true;
54 }
55
56 /*
57 * (non-Javadoc)
58 *
59 * @see java.lang.Object#toString()
60 */
61 @Override
62 public String toString() {
63 final long timestamp = fValue;
64 final Date d = new Date(timestamp / 1000000);
65 final DateFormat df = new SimpleDateFormat("HH:mm:ss."); //$NON-NLS-1$
66 final long nanos = (timestamp % 1000000000);
67 StringBuilder output = new StringBuilder();
68 output.append(df.format(d));
69 output.append(String.format("%09d", nanos)); //$NON-NLS-1$
70 return output.toString();
71 }
72
73 public String toFullDateString(){
74 final long timestamp = fValue;
75 final Date d = new Date(timestamp / 1000000);
76 final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss."); //$NON-NLS-1$
77 final long nanos = (timestamp % 1000000000);
78 StringBuilder output = new StringBuilder();
79 output.append(df.format(d));
80 output.append(String.format("%09d", nanos)); //$NON-NLS-1$
81 return output.toString();
82 }
83
84 }
This page took 0.031336 seconds and 5 git commands to generate.