ctf: Fix some Sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / CTFClock.java
CommitLineData
866e5b51
FC
1/*******************************************************************************
2 * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
3 *
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
8 *
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.ctf.core.event;
14
15import java.util.HashMap;
0594c61c 16import java.util.Map;
866e5b51 17
07002e0a 18/**
be6df2d8 19 * Clock description used in CTF traces
07002e0a 20 */
866e5b51
FC
21public class CTFClock {
22
0594c61c
AM
23 private static final long ONE_BILLION_L = 1000000000L;
24 private static final double ONE_BILLION_D = 1000000000.0;
25
1d7277f3
MK
26 private static final String NAME = "name"; //$NON-NLS-1$
27 private static final String FREQ = "freq"; //$NON-NLS-1$
28 private static final String OFFSET = "offset"; //$NON-NLS-1$
29
30 private long clockOffset = 0;
31 private double clockScale = 1.0;
32 private double clockAntiScale = 1.0;
33
07002e0a
MK
34 /**
35 * Field properties.
36 */
0594c61c 37 private final Map<String, Object> properties = new HashMap<String, Object>();
07002e0a
MK
38 /**
39 * Field name.
40 */
866e5b51 41 private String name;
1d7277f3 42 private boolean isScaled = false;
866e5b51 43
be6df2d8
AM
44 /**
45 * Default constructor
46 */
1d7277f3
MK
47 public CTFClock() {
48 }
be6df2d8 49
07002e0a
MK
50 /**
51 * Method addAttribute.
1d7277f3
MK
52 *
53 * @param key
54 * String
55 * @param value
56 * Object
07002e0a 57 */
866e5b51
FC
58 public void addAttribute(String key, Object value) {
59 this.properties.put(key, value);
1d7277f3 60 if (key.equals(NAME)) {
866e5b51
FC
61 this.name = (String) value;
62 }
1d7277f3
MK
63 if (key.equals(FREQ)) {
64 /*
65 * Long is converted to a double. the double is then dividing
66 * another double that double is saved. this is precise as long as
67 * the long is under 53 bits long. this is ok as long as we don't
68 * have a system with a frequency of > 1 600 000 000 GHz with
69 * 200 ppm precision
70 */
0594c61c
AM
71 isScaled = !((Long) getProperty(FREQ)).equals(ONE_BILLION_L);
72 clockScale = ONE_BILLION_D / ((Long) getProperty(FREQ)).doubleValue();
1d7277f3
MK
73 clockAntiScale = 1.0 / clockScale;
74
75 }
76 if (key.equals(OFFSET)) {
77 clockOffset = (Long) getProperty(OFFSET);
78 }
866e5b51
FC
79 }
80
07002e0a
MK
81 /**
82 * Method getName.
1d7277f3 83 *
07002e0a
MK
84 * @return String
85 */
866e5b51
FC
86 public String getName() {
87 return name;
88 }
89
07002e0a
MK
90 /**
91 * Method getProperty.
1d7277f3
MK
92 *
93 * @param key
94 * String
07002e0a
MK
95 * @return Object
96 */
866e5b51
FC
97 public Object getProperty(String key) {
98 return properties.get(key);
99 }
100
1d7277f3
MK
101 /**
102 * @return the clockOffset
965d6fb2 103 * @since 2.0
1d7277f3
MK
104 */
105 public long getClockOffset() {
106 return clockOffset;
107 }
108
109 /**
110 * @return the clockScale
965d6fb2 111 * @since 2.0
1d7277f3
MK
112 */
113 public double getClockScale() {
114 return clockScale;
115 }
116
117 /**
118 * @return the clockAntiScale
965d6fb2 119 * @since 2.0
1d7277f3
MK
120 */
121 public double getClockAntiScale() {
122 return clockAntiScale;
123 }
124
125 /**
126 * @return is the clock in ns or cycles?
965d6fb2 127 * @since 2.0
1d7277f3
MK
128 */
129 public boolean isClockScaled() {
130 return isScaled;
131 }
132
866e5b51 133}
This page took 0.037827 seconds and 5 git commands to generate.