Convert Windows line delimiters to Unix.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / 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 9 * Contributors:
09667aa4 10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API and Implementation
79e08fd0
BH
11 *******************************************************************************/
12
cfd22ad0 13package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
79e08fd0
BH
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;
cfd22ad0 23import org.eclipse.linuxtools.tmf.ui.viewers.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 *
25a042b3 31 * @version 2.0
b544077e 32 * @author Mathieu Denis
cfd22ad0 33 * @since 2.0
79e08fd0
BH
34 */
35public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
36
37 /**
25a042b3 38 * Header for the event type categories.
79e08fd0 39 */
66711dc8 40 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
79e08fd0
BH
41
42 /**
09667aa4
MD
43 * Indicate that it's a value.
44 *
79e08fd0 45 * Used when checking the possible child node for a node.
09667aa4 46 *
79e08fd0 47 * It differentiate a category of a value by being appended to a value.
79e08fd0 48 */
66711dc8 49 protected static final String NODE = "z"; //$NON-NLS-1$
09667aa4 50
b544077e
BH
51 /**
52 * Root node key.
53 */
66711dc8 54 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
79e08fd0 55
b544077e
BH
56 /**
57 * Default constructor. Creates base statistics tree for counting total
58 * number of events and number of events per event type.
59 */
79e08fd0
BH
60 public TmfBaseStatisticsTree() {
61 super();
62 Map<String, Set<String>> keys = getKeys();
63
64 // //////////// Adding category sets
65 // common
66 keys.put(HEADER_EVENT_TYPES, new HashSet<String>());
67
68 // /////////// Adding value sets
69 // Under a trace
70 Set<String> temp = new HashSet<String>(8);
71 temp.add(HEADER_EVENT_TYPES);
72 keys.put(ROOT_NODE_KEY, temp);
73 // Under an event type
74 temp = new HashSet<String>(16);
75 keys.put(mergeString(HEADER_EVENT_TYPES, NODE), temp);
76
77 // //////////// CREATE root
78 keys.put(ROOT.get(0), new HashSet<String>(2)); // 1 trace at the time
79 getOrCreate(ROOT);
80 }
81
82 /*
83 * (non-Javadoc)
09667aa4 84 *
cfd22ad0
MD
85 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getChildren
86 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
87 */
88 @Override
89 public Collection<TmfStatisticsTreeNode> getChildren(TmfFixedArray<String> path) {
90 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
91
92 if (path.size() % 2 == 0) { // if we are at a Category
93 TmfStatisticsTreeNode current = null;
94 for (String value : getKeys().get(path.get(path.size() - 1))) {
95 current = get(path.append(value));
25a042b3 96 if (current != null && current.getValue().getTotal() != 0) {
79e08fd0 97 result.add(current);
013a5f1c 98 }
79e08fd0
BH
99 }
100 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
101 if (path.equals(ROOT)) {
102 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 103 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
104 }
105 } else {
79e08fd0 106 // Get value under the root
013a5f1c 107 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 108 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
109 }
110 }
79e08fd0 111 } else {// If we are at a value
013a5f1c 112 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
113 // Search the parent name + NODE
114 result.add(getOrCreate(path.append(value)));
013a5f1c 115 }
79e08fd0
BH
116 }
117
118 return result;
119 }
120
121 /*
122 * (non-Javadoc)
09667aa4 123 *
cfd22ad0
MD
124 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#getAllChildren
125 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
126 */
127 @Override
128 public Collection<TmfStatisticsTreeNode> getAllChildren(TmfFixedArray<String> path) {
129 LinkedList<TmfStatisticsTreeNode> result = new LinkedList<TmfStatisticsTreeNode>();
130
131 if (path.size() % 2 == 0) { // if we are at a Category
132 TmfStatisticsTreeNode current = null;
133 for (String value : getKeys().get(path.get(path.size() - 1))) {
134 current = get(path.append(value));
013a5f1c 135 if (current != null) {
79e08fd0 136 result.add(current);
013a5f1c 137 }
79e08fd0
BH
138 }
139 } else if (path.size() == 1) { // Special case.
013a5f1c
AM
140 if (path.equals(ROOT)) {
141 for (String value : getKeys().get(ROOT.get(0))) {
79e08fd0 142 result.add(getOrCreate(new TmfFixedArray<String>(value)));
013a5f1c
AM
143 }
144 } else {
79e08fd0 145 // Get value under the root
013a5f1c 146 for (String value : getKeys().get(ROOT_NODE_KEY)) {
79e08fd0 147 result.add(getOrCreate(path.append(value)));
013a5f1c
AM
148 }
149 }
79e08fd0 150 } else {// If we are at a value
013a5f1c 151 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
79e08fd0
BH
152 // Search the parent name + NODE
153 result.add(getOrCreate(path.append(value)));
013a5f1c 154 }
79e08fd0
BH
155 }
156 return result;
157 }
158
25a042b3
MD
159 /*
160 * (non-Javadoc)
161 *
cfd22ad0
MD
162 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#increase
163 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo, int)
25a042b3
MD
164 */
165 @Override
73fbf6be
MD
166 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo, int values) {
167 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
168 for (TmfFixedArray<String> path : paths) {
169 getOrCreate(path).getValue().incrementTotal(values);
170 }
171
172 paths = getTypePaths(event, extraInfo);
173 for (TmfFixedArray<String> path : paths) {
174 getOrCreate(path).getValue().incrementTotal(values);
175 }
25a042b3
MD
176 }
177
178 /*
179 * (non-Javadoc)
180 *
cfd22ad0
MD
181 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerEvent
182 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo)
25a042b3
MD
183 */
184 @Override
185 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
186 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
187 for (TmfFixedArray<String> path : paths) {
188 getOrCreate(path).getValue().incrementTotal();
189 }
190
191 paths = getTypePaths(event, extraInfo);
192 for (TmfFixedArray<String> path : paths) {
193 getOrCreate(path).getValue().incrementTotal();
194 }
195 }
196
73fbf6be
MD
197 @Override
198 public void registerEventInTimeRange(ITmfEvent event, ITmfExtraEventInfo extraInfo, int qty) {
199 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
200 for (TmfFixedArray<String> path : paths) {
201 getOrCreate(path).getValue().incrementPartial(qty);
202 }
203
204 paths = getTypePaths(event, extraInfo);
205 for (TmfFixedArray<String> path : paths) {
206 getOrCreate(path).getValue().incrementPartial(qty);
207 }
208 }
209
25a042b3
MD
210 /*
211 * (non-Javadoc)
212 *
cfd22ad0
MD
213 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerEventInTimeRange
214 * (org.eclipse.linuxtools.tmf.core.event.ITmfEvent, org.eclipse.linuxtools.tmf.ui.viewers.statistics.ITmfExtraEventInfo)
25a042b3
MD
215 */
216 @Override
217 public void registerEventInTimeRange(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
218 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
219 for (TmfFixedArray<String> path : paths) {
220 getOrCreate(path).getValue().incrementPartial();
221 }
222
223 paths = getTypePaths(event, extraInfo);
224 for (TmfFixedArray<String> path : paths) {
225 getOrCreate(path).getValue().incrementPartial();
226 }
227 }
228
79e08fd0 229 /**
09667aa4 230 * Get the event types paths.
013a5f1c 231 *
79e08fd0
BH
232 * @param event
233 * Event to get the path for.
234 * @param extraInfo
235 * Extra information to pass along with the event
236 * @return Array of FixedArray representing the paths.
237 */
238 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 239 protected TmfFixedArray<String>[] getTypePaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0 240 String trace = extraInfo.getTraceName();
14fb7589
MD
241 // Take only the event type name
242 String type = event.getType().getName();
79e08fd0
BH
243
244 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace, HEADER_EVENT_TYPES, type) };
245
246 return paths;
247 }
248
249 /**
09667aa4 250 * Get the standard paths for an event.
013a5f1c 251 *
79e08fd0
BH
252 * @param event
253 * Event to get the path for.
254 * @param extraInfo
255 * Extra information to pass along with the event
256 * @return Array of FixedArray representing the paths.
257 */
258 @SuppressWarnings({ "rawtypes", "unchecked" })
72f1e62a 259 protected TmfFixedArray<String>[] getNormalPaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
79e08fd0
BH
260 String trace = extraInfo.getTraceName();
261
262 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) };
263 return paths;
264 }
013a5f1c 265
79e08fd0
BH
266 /*
267 * (non-Javadoc)
09667aa4 268 *
cfd22ad0
MD
269 * @see org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.AbsTmfStatisticsTree#registerName
270 * (org.eclipse.linuxtools.tmf.core.util.TmfFixedArray)
79e08fd0
BH
271 */
272 @Override
273 protected void registerName(TmfFixedArray<String> path) {
274 if (path.size() == 1) {
013a5f1c 275 if (!path.equals(ROOT)) {
79e08fd0 276 getKeys().get(ROOT.get(0)).add(path.get(0));
013a5f1c
AM
277 }
278 } else if (path.size() % 2 != 0) {
79e08fd0 279 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
013a5f1c 280 }
79e08fd0
BH
281 }
282}
This page took 0.04413 seconds and 5 git commands to generate.