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
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfFixedArray
;
22 * A tree where nodes can be accessed efficiently using paths.
24 * It works like file systems. Each node is identified by a key. A path is an
25 * array ({@link TmfFixedArray}) of String. The elements of the array represent
26 * the path from the root to this node.
30 * @author Mathieu Denis
32 public class TmfStatisticsTreeNode
{
37 protected TmfStatistics fValue
;
42 protected TmfFixedArray
<String
> fPath
;
45 * Corresponding StatisticsData.
47 protected AbsTmfStatisticsTree fNodes
;
55 * Corresponding StatisticsData.
57 public TmfStatisticsTreeNode(final TmfFixedArray
<String
> path
,
58 AbsTmfStatisticsTree nodes
) {
61 fValue
= new TmfStatistics();
65 * Test if a node contain the specified child.
69 * @return true: if child with given key is present, false: if no child
70 * exists with given key name
72 public boolean containsChild(String key
) {
73 if (AbsTmfStatisticsTree
.ROOT
.equals(fPath
)) {
74 return fNodes
.get(new TmfFixedArray
<String
>(key
)) != null;
76 return (fNodes
.get(fPath
.append(key
)) != null);
80 * Get the children of this node.
82 * @return Direct children of this node.
84 public Collection
<TmfStatisticsTreeNode
> getChildren() {
85 return fNodes
.getChildren(fPath
);
89 * Gets every children of this node even if no event has been registered for a node.
91 * @return Direct children of this node.
93 public Collection
<TmfStatisticsTreeNode
> getAllChildren() {
94 return fNodes
.getAllChildren(fPath
);
98 * Get the key for this node.
100 * @return Key associated with this node.
102 public String
getKey() {
103 return fPath
.get(fPath
.size() - 1);
107 * Get the number of children this node have.
109 * @return Number of direct children of this node.
111 public int getNbChildren() {
112 return fNodes
.getChildren(fPath
).size();
116 * Return the parent node.
118 * @return Parent node.
120 public TmfStatisticsTreeNode
getParent() {
121 return fNodes
.getParent(fPath
);
125 * Get the path of the node.
127 * @return The path of the node.
129 public TmfFixedArray
<String
> getPath() {
134 * Get the value of this node.
136 * @return Value associated with this node.
138 public TmfStatistics
getValue() {
143 * Indicate if the node have children.
145 * @return True if the node has children.
147 public boolean hasChildren() {
148 return !fNodes
.getChildren(fPath
).isEmpty();
152 * Start from creation time i.e. keep key and parent but new statistics and
155 public void reset() {
156 fValue
= new TmfStatistics();
161 * Resets the global number of events. It doesn't remove any node
162 * and doesn't modify the partial event count.
168 public void resetGlobalValue() {
169 getValue().resetTotalCount();
170 fNodes
.resetGlobalValue(fPath
);
174 * Resets the number of events in the time range. It doesn't remove any node
175 * and doesn't modify the global event count.
181 public void resetTimeRangeValue() {
182 getValue().resetPartialCount();
183 fNodes
.resetTimeRangeValue(fPath
);