tmf: Update Javadoc throughout tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / model / TmfBaseStatisticsTree.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
13 package org.eclipse.linuxtools.tmf.ui.views.statistics.model;
14
15 import java.util.Collection;
16 import java.util.HashSet;
17 import java.util.LinkedList;
18 import java.util.Map;
19 import java.util.Set;
20
21 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22 import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
23 import org.eclipse.linuxtools.tmf.ui.views.statistics.ITmfExtraEventInfo;
24
25 /**
26 * Store information about base statistics data.
27 *
28 * This class provides a way to represent statistics data that is compatible
29 * with every type of trace.
30 *
31 * @version 1.0
32 * @author Mathieu Denis
33 */
34 public class TmfBaseStatisticsTree extends AbsTmfStatisticsTree {
35
36 /**
37 * <h4>Header for the event types categories.</h4>
38 */
39 public static final String HEADER_EVENT_TYPES = Messages.TmfStatisticsData_EventTypes;
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 */
51 protected static final String NODE = "z"; //$NON-NLS-1$
52 /**
53 * Root node key.
54 */
55 protected static final String ROOT_NODE_KEY = mergeString(ROOT.get(0), NODE);
56
57 /**
58 * Default constructor. Creates base statistics tree for counting total
59 * number of events and number of events per event type.
60 */
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));
95 if (current != null && current.getValue().nbEvents != 0) {
96 result.add(current);
97 }
98 }
99 } else if (path.size() == 1) { // Special case.
100 if (path.equals(ROOT)) {
101 for (String value : getKeys().get(ROOT.get(0))) {
102 result.add(getOrCreate(new TmfFixedArray<String>(value)));
103 }
104 } else {
105 // Get value under the root
106 for (String value : getKeys().get(ROOT_NODE_KEY)) {
107 result.add(getOrCreate(path.append(value)));
108 }
109 }
110 } else {// If we are at a value
111 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
112 // Search the parent name + NODE
113 result.add(getOrCreate(path.append(value)));
114 }
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));
132 if (current != null) {
133 result.add(current);
134 }
135 }
136 } else if (path.size() == 1) { // Special case.
137 if (path.equals(ROOT)) {
138 for (String value : getKeys().get(ROOT.get(0))) {
139 result.add(getOrCreate(new TmfFixedArray<String>(value)));
140 }
141 } else {
142 // Get value under the root
143 for (String value : getKeys().get(ROOT_NODE_KEY)) {
144 result.add(getOrCreate(path.append(value)));
145 }
146 }
147 } else {// If we are at a value
148 for (String value : getKeys().get(mergeString(path.get(path.size() - 2), NODE))) {
149 // Search the parent name + NODE
150 result.add(getOrCreate(path.append(value)));
151 }
152 }
153 return result;
154 }
155
156 /**
157 * <h4>Get the event types paths.</h4>
158 *
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" })
166 protected TmfFixedArray<String>[] getTypePaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
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>
179 *
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" })
187 protected TmfFixedArray<String>[] getNormalPaths(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
188 String trace = extraInfo.getTraceName();
189
190 TmfFixedArray[] paths = { new TmfFixedArray<String>(trace) };
191 return paths;
192 }
193
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
199 public void increase(ITmfEvent event, ITmfExtraEventInfo extraInfo, int values) {
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
208 public void registerEvent(ITmfEvent event, ITmfExtraEventInfo extraInfo) {
209 TmfFixedArray<String>[] paths = getNormalPaths(event, extraInfo);
210 for (TmfFixedArray<String> path : paths) {
211 ++(getOrCreate(path).getValue().nbEvents);
212 }
213
214 paths = getTypePaths(event, extraInfo);
215 for (TmfFixedArray<String> path : paths) {
216 ++(getOrCreate(path).getValue().nbEvents);
217 }
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) {
228 if (!path.equals(ROOT)) {
229 getKeys().get(ROOT.get(0)).add(path.get(0));
230 }
231 } else if (path.size() % 2 != 0) {
232 getKeys().get(path.get(path.size() - 2)).add(path.get(path.size() - 1));
233 }
234 }
235 }
This page took 0.036312 seconds and 5 git commands to generate.