1 /*******************************************************************************
2 * Copyright (c) 2009 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 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.statistics
.model
;
16 import java
.util
.Collection
;
19 * <h4>A tree where nodes can be accessed efficiently using paths.</h4>
21 * <p>It works like file systems. Each node is identified by a key. A path is an array ({@link FixedArray}) of String. The elements of the array represent the path from the root to this node.</p>
23 public class StatisticsTreeNode
implements Comparable
<StatisticsTreeNode
> {
25 * <h4>Value of the node.</h4>
27 private Statistics fValue
;
29 * <h4>Path of the node.</h4>
31 private FixedArray fPath
;
33 * <h4>Corresponding StatisticsData.</h4>
35 private StatisticsData fNodes
;
37 * <h4>Name of the node.</h4>
39 private String fName
= ""; //$NON-NLS-1$
41 * <h4>Constructor.</h4>
42 * @param path Path to the node.
43 * @param nodes Corresponding StatisticsData.
45 public StatisticsTreeNode(final FixedArray path
, StatisticsData nodes
) {
46 this(path
, nodes
, ""); //$NON-NLS-1$
50 * <h4>Constructor.</h4>
51 * @param path Path to the node.
52 * @param nodes Corresponding StatisticsData.
53 * @param name The name associated with this node.
55 public StatisticsTreeNode(final FixedArray path
, StatisticsData nodes
, String name
) {
59 fValue
= new Statistics();
63 * <h4>Test if a node contain the specified child.</h4>
64 * @param key Name of the child.
65 * @return true: if child with given key is present, false: if no child exists with given key name
67 public boolean containsChild(Integer key
) {
68 if(StatisticsData
.ROOT
== fPath
)
69 return fNodes
.get(new FixedArray(key
)) != null;
70 return (fNodes
.get(fPath
.append(key
)) != null);
73 * <h4>Get the children of this node.</h4>
74 * @return Direct children of this node.
76 public Collection
<StatisticsTreeNode
> getChildren() {
77 return fNodes
.getChildren(fPath
);
80 * <h4>Get the key for this node.</h4>
81 * @return Key associated with this node.
83 public Integer
getKey() {
84 return fPath
.get(fPath
.size() - 1);
87 * <h4>Get the number of children this node have.</h4>
88 * @return Number of direct children of this node.
90 public int getNbChildren() {
91 return fNodes
.getChildren(fPath
).size();
94 * <h4>Return the parent node.</h4>
95 * @return Parent node.
97 public StatisticsTreeNode
getParent() {
98 return fNodes
.getParent(fPath
);
101 * <h4>Get the path of the node.</h4>
102 * @return The path of the node.
104 public FixedArray
getPath() {
108 * <h4>Get the value of this node.</h4>
109 * @return Value associated with this node.
111 public Statistics
getValue() {
115 * <h4>Indicate if the node have children.</h4>
116 * @return True if the node has children.
118 public boolean hasChildren() {
119 return !fNodes
.getChildren(fPath
).isEmpty();
123 * <h4>Start from creation time i.e. keep key and parent but new statistics and no children.</h4>
125 public void reset() {
126 fValue
= new Statistics();
131 * <h4>Set the name of this node.</h4>
133 public void setName (String name
) {
137 * <h4>Get the name of this node.</h4>
138 * @return Name associated with this node.
140 public String
getName() {
145 * <h4>Returns node content as string (full path is not included).</h4>
146 * @return Node content as string.
148 public String
getContent() {
149 return fName
+ ": [nbEvents=" + fValue
.nbEvents
+ //$NON-NLS-1$
150 ", cpuTime=" + fValue
.cpuTime
+ //$NON-NLS-1$
151 ", cumulativeCpuTime=" + fValue
.cumulativeCpuTime
+ //$NON-NLS-1$
152 ", elapsedTime=" + fValue
.elapsedTime
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$
156 * <h4>For sorting purposes (sorting by node name).</h4>
159 public int compareTo(StatisticsTreeNode o
) {
160 return fName
.compareTo(o
.fName
);
This page took 0.041359 seconds and 5 git commands to generate.