1 /*******************************************************************************
2 * Copyright (c) 2011, 2013 Ericsson
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
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
11 * Alexandre Montplaisir - Merge TmfBaseStatisticsTree and AbsStatisticsTree
12 * Move the tree structure logic into the nodes
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
;
19 * Base class for the statistics storage. It allow to implement a tree structure
20 * while avoiding the need to run through the tree each time you need to add a
21 * node at a given place.
23 * @author Mathieu Denis
27 public class TmfStatisticsTree
{
29 /** Header for the event type categories. */
30 public static final String HEADER_EVENT_TYPES
= Messages
.TmfStatisticsData_EventTypes
;
32 /** Root node of this tree */
33 private final TmfStatisticsTreeNode rootNode
;
36 * Default constructor. Creates base statistics tree for counting total
37 * number of events and number of events per event type.
39 public TmfStatisticsTree() {
40 rootNode
= new TmfStatisticsTreeNode(this, null, new String
[0]);
44 * Retrieve the root node of this tree.
46 * @return The root node
48 public TmfStatisticsTreeNode
getRootNode() {
57 * @return The node, or null if it doesn't current exist in the tree.
59 public TmfStatisticsTreeNode
getNode(String
... path
) {
60 TmfStatisticsTreeNode curNode
= rootNode
;
61 for (String pathElem
: path
) {
62 curNode
= curNode
.getChild(pathElem
);
63 if (curNode
== null) {
64 /* The requested path doesn't exist, return null */
72 * Get or create a node.
76 * @return The requested node. Will be created if it didn't exist.
78 public TmfStatisticsTreeNode
getOrCreateNode(String
... path
) {
79 TmfStatisticsTreeNode curNode
= rootNode
;
80 TmfStatisticsTreeNode nextNode
;
81 for (String pathElem
: path
) {
82 nextNode
= curNode
.getChild(pathElem
);
83 if (nextNode
== null) {
84 nextNode
= curNode
.addChild(pathElem
);
92 * Set the value to display in the "total" cells. This means the row
93 * indicating the total count of events for a trace.
96 * The name of the trace (will be used as a sub-tree in the view)
98 * Is this a for a global or a time range request? Determines if
99 * this goes in the Global column or the Selected Time Range one.
101 * The value to display
103 public void setTotal(String traceName
, boolean isGlobal
, long qty
) {
104 String
[][] paths
= getNormalPaths(traceName
);
105 for (String path
[] : paths
) {
106 getOrCreateNode(path
).getValues().setValue(isGlobal
, qty
);
111 * Set the value to display in the "Type count" cells. These are the counts
112 * for each event types.
115 * The name of the trace (will be used as a sub-tree in the view)
119 * Is this a for a global or a time range request? Determines if
120 * this goes in the Global column or the Selected Time Range one.
122 * The value to display
124 public void setTypeCount(String traceName
, String type
, boolean isGlobal
, long qty
) {
125 String
[][] paths
= getTypePaths(traceName
, type
);
126 for (String
[] path
: paths
) {
127 getOrCreateNode(path
).getValues().setValue(isGlobal
, qty
);
132 * Get the event types paths.
135 * The name of the trace (will be used as a sub-tree in the view)
138 * @return Array of arrays representing the paths
140 protected String
[][] getTypePaths(String traceName
, String type
) {
141 String
[][] paths
= { new String
[] {traceName
, HEADER_EVENT_TYPES
, type
} };
146 * Get the standard paths for an event.
149 * The name of the trace (will be used as a sub-tree in the view)
150 * @return Array of arrays representing the paths
152 protected String
[][] getNormalPaths(String traceName
) {
153 String
[][] paths
= { new String
[] { traceName
} };
158 * Function to merge many string more efficiently.
162 * @return A new string containing all the strings.
164 protected static String
mergeString(String
... strings
) {
165 StringBuilder builder
= new StringBuilder();
166 for (String s
: strings
) {
169 return builder
.toString();