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