1 /*******************************************************************************
2 * Copyright (c) 2011 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
.views
.statistics
.model
;
17 import java
.util
.Collection
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfFixedArray
;
22 * <h4>A tree where nodes can be accessed efficiently using paths.</h4>
24 * <p>It works like file systems. Each node is identified by a key. A path is an array ({@link TmfFixedArray}) of String. The elements of the array represent the path from the root to this node.</p>
26 public class TmfStatisticsTreeNode
{
28 * <h4>Value of the node.</h4>
30 protected TmfStatistics fValue
;
32 * <h4>Path of the node.</h4>
34 protected TmfFixedArray
<String
> fPath
;
36 * <h2>Corresponding StatisticsData.</h2>
38 protected AbsTmfStatisticsTree fNodes
;
40 * <h4>Constructor.</h4>
41 * @param path Path to the node.
42 * @param nodes Corresponding StatisticsData.
44 public TmfStatisticsTreeNode(final TmfFixedArray
<String
> path
, AbsTmfStatisticsTree nodes
) {
47 fValue
= new TmfStatistics();
50 * <h4>Test if a node contain the specified child.</h4>
51 * @param key Name of the child.
52 * @return true: if child with given key is present, false: if no child exists with given key name
54 public boolean containsChild(String key
) {
55 if(AbsTmfStatisticsTree
.ROOT
.equals(fPath
))
56 return fNodes
.get(new TmfFixedArray
<String
>(key
)) != null;
57 return (fNodes
.get(fPath
.append(key
)) != null);
60 * <h4>Get the children of this node.</h4>
61 * @return Direct children of this node.
63 public Collection
<TmfStatisticsTreeNode
> getChildren() {
64 return fNodes
.getChildren(fPath
);
67 * <h4>Get the children of this node.</h4>
68 * @return Direct children of this node.
70 public Collection
<TmfStatisticsTreeNode
> getAllChildren() {
71 return fNodes
.getAllChildren(fPath
);
74 * <h4>Get the key for this node.</h4>
75 * @return Key associated with this node.
77 public String
getKey() {
78 return fPath
.get(fPath
.size() - 1);
81 * <h4>Get the number of children this node have.</h4>
82 * @return Number of direct children of this node.
84 public int getNbChildren() {
85 return fNodes
.getChildren(fPath
).size();
88 * <h4>Return the parent node.</h4>
89 * @return Parent node.
91 public TmfStatisticsTreeNode
getParent() {
92 return fNodes
.getParent(fPath
);
95 * <h4>Get the path of the node.</h4>
96 * @return The path of the node.
98 public TmfFixedArray
<String
> getPath() {
102 * <h4>Get the value of this node.</h4>
103 * @return Value associated with this node.
105 public TmfStatistics
getValue() {
109 * <h4>Indicate if the node have children.</h4>
110 * @return True if the node has children.
112 public boolean hasChildren() {
113 return !fNodes
.getChildren(fPath
).isEmpty();
116 * <h4>Start from creation time i.e. keep key and parent but new statistics and no children.</h4>
118 public void reset() {
119 fValue
= new TmfStatistics();