Improve Javadoc for TmfEventsViews
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / model / TmfBaseStatisticsTree.java
CommitLineData
79e08fd0 1/*******************************************************************************
b544077e 2 * Copyright (c) 2011, 2012 Ericsson
79e08fd0
BH
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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:
10 * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial API and Implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.views.statistics.model;
14
15import java.util.Collection;
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.Map;
19import java.util.Set;
20
72f1e62a 21import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
6c13869b 22import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
79e08fd0 23import org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfExtraEventInfo;
79e08fd0
BH
24
25/**
b544077e 26 * Store information about base statistics data.
79e08fd0 27 * <p>This class provides a way to represent statistics data that is compatible to every kind of traces</p>
b544077e
BH
28 *
29 * @version 1.0
30 * @author Mathieu Denis
79e08fd0
BH
31 */
32public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
33
34 /**
35 * <h4>Header for the event types categories.</h4>
36 */
66711dc8 37 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
79e08fd0
BH
38
39 /**
40 * <h4>Indicate that it's a value.</h4>
41 * <p>
42 * Used when checking the possible child node for a node.
43 * </p>
44 * *
45 * <p>
46 * It differentiate a category of a value by being appended to a value.
47 * </p>
48 */
66711dc8 49 protected static final String NODE = "z"; //$NON-NLS-1$
b544077e
BH
50 /**
51 * Root node key.
52 */
66711dc8 53 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
79e08fd0 54
b544077e
BH
55 /**
56 * Default constructor. Creates base statistics tree for counting total
57 * number of events and number of events per event type.
58 */
79e08fd0
BH
59 public TmfBaseStatisticsTree() {
60 super();
61 Map<String, Set<String>> keys = getKeys();
62
63 // //////////// Adding category sets
64 // common
65 keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
66
67 // /////////// Adding value sets
68 // Under a trace
69 Set<String> temp = new HashSet<String>(8);
70 temp.add(HEADER_EVENT_TYPES);
71 keys.put(ROOT_NODE_KEY, temp);
72 // Under an event type
73 temp = new HashSet<String>(16);
74 keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
75
76 // //////////// CREATE root
77 keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
78 getOrCreate(ROOT);
79 }
80
81 /*
82 * (non-Javadoc)
83 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
84 */
85 @Override
86 public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) {
87 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
88
89 if (path.size() % 2 == 0) { // if we are at a Category
90 TmfStatisticsTreeNode current = null;
91 for (String value : getKeys().get(path.get(path.size() - 1))) {
92 current = get(path.append(value));
93 if (current != null && current.getValue().nbEvents != 0)
94 result.add(current);
95 }
96 } else if (path.size() == 1) { // Special case.
97 if (path.equals(ROOT)) // Asking for the root.
98 for (String value : getKeys().get(ROOT.get(0)))
99 result.add(getOrCreate(new TmfFixedArray<String>(value)));
100 else
101 // Get value under the root
102 for (String value : getKeys().get(ROOT_NODE_KEY))
103 result.add(getOrCreate(path.append(value)));
104 } else {// If we are at a value
105 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE)))
106 // Search the parent name + NODE
107 result.add(getOrCreate(path.append(value)));
108 }
109
110 return result;
111 }
112
113 /*
114 * (non-Javadoc)
115 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#getAllChildren(org.eclipse.linuxtools.tmf.util.TmfFixedArray)
116 */
117 @Override
118 public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
119 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
120
121 if (path.size() % 2 == 0) { // if we are at a Category
122 TmfStatisticsTreeNode current = null;
123 for (String value : getKeys().get(path.get(path.size() - 1))) {
124 current = get(path.append(value));
125 if (current != null)
126 result.add(current);
127 }
128 } else if (path.size() == 1) { // Special case.
129 if (path.equals(ROOT)) // Asking for the root.
130 for (String value : getKeys().get(ROOT.get(0)))
131 result.add(getOrCreate(new TmfFixedArray<String>(value)));
132 else
133 // Get value under the root
134 for (String value : getKeys().get(ROOT_NODE_KEY))
135 result.add(getOrCreate(path.append(value)));
136 } else {// If we are at a value
137 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE)))
138 // Search the parent name + NODE
139 result.add(getOrCreate(path.append(value)));
140 }
141 return result;
142 }
143
144 /**
145 * <h4>Get the event types paths.</h4>
146 *
147 * @param event
148 * Event to get the path for.
149 * @param extraInfo
150 * Extra information to pass along with the event
151 * @return Array of FixedArray representing the paths.
152 */
153 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 154 protected TmfFixedArray<String>[] getTypePaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
155 String trace = extraInfo.getTraceName();
156 // String type = event.getType().getTypeId(); // Add too much
157 // informations
158 String type = event.getType().toString();
159
160 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace, HEADER_EVENT_TYPES, type) };
161
162 return paths;
163 }
164
165 /**
166 * <h4>Get the standard paths for an event.</h4>
167 *
168 * @param event
169 * Event to get the path for.
170 * @param extraInfo
171 * Extra information to pass along with the event
172 * @return Array of FixedArray representing the paths.
173 */
174 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 175 protected TmfFixedArray<String>[] getNormalPaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
176 String trace = extraInfo.getTraceName();
177
178 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) };
179 return paths;
180 }
181
182 /*
183 * (non-Javadoc)
184 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#increase(org.eclipse.linuxtools.tmf.event.TmfEvent, org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfEventInfo, int)
185 */
186 @Override
72f1e62a 187 public void increase(ITmfEvent event, ITmfExtraEventInfo extraInfo, int values) {
79e08fd0
BH
188 // Do nothing
189 }
190
191 /*
192 * (non-Javadoc)
193 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerEvent(org.eclipse.linuxtools.tmf.event.TmfEvent, org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfEventInfo)
194 */
195 @Override
72f1e62a 196 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
197 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
198 for (TmfFixedArray<String> path : paths)
199 ++(getOrCreate(path).getValue().nbEvents);
200
201 paths = getTypePaths(event, extraInfo);
202 for (TmfFixedArray<String> path : paths)
203 ++(getOrCreate(path).getValue().nbEvents);
204 }
205
206 /*
207 * (non-Javadoc)
208 * @see org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsData#registerName
209 * (org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfFixedArray)
210 */
211 @Override
212 protected void registerName(TmfFixedArray<String> path) {
213 if (path.size() == 1) {
214 if (!path.equals(ROOT))
215 getKeys().get(ROOT.get(0)).add(path.get(0));
216 } else if (path.size() % 2 != 0)
217 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
218 }
219}
This page took 0.036738 seconds and 5 git commands to generate.