1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 * Yann N. Dauphin <dhaemon@gmail.com> - Implementation for stats
11 * Francois Godin <copelnug@gmail.com> - Re-design for new stats structure
12 * Mathieu Denis <mathieu.denis@polymtl.ca> - Re-design for new stats structure (2)
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
;
17 import java
.util
.Collection
;
20 * A tree where nodes can be accessed efficiently using paths.
22 * It works like file systems. Each node is identified by a key. A path is an
23 * array of String. The elements of the array represent the path from the root
28 * @author Mathieu Denis
30 public class TmfStatisticsTreeNode
{
35 protected TmfStatisticsValues fValues
;
40 protected String
[] fPath
;
43 * Corresponding StatisticsData.
45 protected TmfStatisticsTree fNodes
;
53 * Corresponding StatisticsData.
55 public TmfStatisticsTreeNode(TmfStatisticsTree nodes
, final String
... path
) {
58 fValues
= new TmfStatisticsValues();
62 * Test if a node contain the specified child.
66 * @return true: if child with given key is present, false: if no child
67 * exists with given key name
69 public boolean containsChild(String key
) {
70 if (TmfStatisticsTree
.ROOT
.equals(fPath
)) {
71 return fNodes
.get(key
) != null;
74 String
[] childPath
= new String
[fPath
.length
+ 1];
75 System
.arraycopy(fPath
, 0, childPath
, 0, fPath
.length
);
76 childPath
[fPath
.length
] = key
;
77 return (fNodes
.get(childPath
) != null);
81 * Get the children of this node.
83 * @return Direct children of this node.
85 public Collection
<TmfStatisticsTreeNode
> getChildren() {
86 return fNodes
.getChildren(fPath
);
90 * Gets every children of this node even if no event has been registered for a node.
92 * @return Direct children of this node.
94 public Collection
<TmfStatisticsTreeNode
> getAllChildren() {
95 return fNodes
.getAllChildren(fPath
);
99 * Get the key for this node.
101 * @return Key associated with this node.
103 public String
getKey() {
104 return fPath
[fPath
.length
- 1];
108 * Get the number of children this node have.
110 * @return Number of direct children of this node.
112 public int getNbChildren() {
113 return fNodes
.getChildren(fPath
).size();
117 * Return the parent node.
119 * @return Parent node.
121 public TmfStatisticsTreeNode
getParent() {
122 return fNodes
.getParent(fPath
);
126 * Get the path of the node.
128 * @return The path of the node.
130 public String
[] getPath() {
135 * Get the value of this node.
137 * @return Value associated with this node.
139 public TmfStatisticsValues
getValues() {
144 * Indicate if the node have children.
146 * @return True if the node has children.
148 public boolean hasChildren() {
149 return !fNodes
.getChildren(fPath
).isEmpty();
153 * Start from creation time i.e. keep key and parent but new statistics and
156 public void reset() {
157 fValues
= new TmfStatisticsValues();
162 * Resets the global number of events. It doesn't remove any node
163 * and doesn't modify the partial event count.
169 public void resetGlobalValue() {
170 getValues().resetTotalCount();
171 fNodes
.resetGlobalValue(fPath
);
175 * Resets the number of events in the time range. It doesn't remove any node
176 * and doesn't modify the global event count.
182 public void resetTimeRangeValue() {
183 getValues().resetPartialCount();
184 fNodes
.resetTimeRangeValue(fPath
);