Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / statistics / model / TmfStatisticsTreeNode.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
3 *
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
8 *
9 * Contributors:
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 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
16
17 import java.util.Collection;
18
19 import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
20
21 /**
22 * A tree where nodes can be accessed efficiently using paths.
23 *
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.
27 *
28 * @version 2.0
29 * @since 2.0
30 * @author Mathieu Denis
31 */
32 public class TmfStatisticsTreeNode {
33
34 /**
35 * Value of the node.
36 */
37 protected TmfStatistics fValue;
38
39 /**
40 * Path of the node.
41 */
42 protected TmfFixedArray<String> fPath;
43
44 /**
45 * Corresponding StatisticsData.
46 */
47 protected AbsTmfStatisticsTree fNodes;
48
49 /**
50 * Constructor.
51 *
52 * @param path
53 * Path to the node.
54 * @param nodes
55 * Corresponding StatisticsData.
56 */
57 public TmfStatisticsTreeNode(final TmfFixedArray<String> path,
58 AbsTmfStatisticsTree nodes) {
59 fPath = path;
60 fNodes = nodes;
61 fValue = new TmfStatistics();
62 }
63
64 /**
65 * Test if a node contain the specified child.
66 *
67 * @param key
68 * Name of the child.
69 * @return true: if child with given key is present, false: if no child
70 * exists with given key name
71 */
72 public boolean containsChild(String key) {
73 if (AbsTmfStatisticsTree.ROOT.equals(fPath)) {
74 return fNodes.get(new TmfFixedArray<String>(key)) != null;
75 }
76 return (fNodes.get(fPath.append(key)) != null);
77 }
78
79 /**
80 * Get the children of this node.
81 *
82 * @return Direct children of this node.
83 */
84 public Collection<TmfStatisticsTreeNode> getChildren() {
85 return fNodes.getChildren(fPath);
86 }
87
88 /**
89 * Gets every children of this node even if no event has been registered for a node.
90 *
91 * @return Direct children of this node.
92 */
93 public Collection<TmfStatisticsTreeNode> getAllChildren() {
94 return fNodes.getAllChildren(fPath);
95 }
96
97 /**
98 * Get the key for this node.
99 *
100 * @return Key associated with this node.
101 */
102 public String getKey() {
103 return fPath.get(fPath.size() - 1);
104 }
105
106 /**
107 * Get the number of children this node have.
108 *
109 * @return Number of direct children of this node.
110 */
111 public int getNbChildren() {
112 return fNodes.getChildren(fPath).size();
113 }
114
115 /**
116 * Return the parent node.
117 *
118 * @return Parent node.
119 */
120 public TmfStatisticsTreeNode getParent() {
121 return fNodes.getParent(fPath);
122 }
123
124 /**
125 * Get the path of the node.
126 *
127 * @return The path of the node.
128 */
129 public TmfFixedArray<String> getPath() {
130 return fPath;
131 }
132
133 /**
134 * Get the value of this node.
135 *
136 * @return Value associated with this node.
137 */
138 public TmfStatistics getValue() {
139 return fValue;
140 }
141
142 /**
143 * Indicate if the node have children.
144 *
145 * @return True if the node has children.
146 */
147 public boolean hasChildren() {
148 return !fNodes.getChildren(fPath).isEmpty();
149 }
150
151 /**
152 * Start from creation time i.e. keep key and parent but new statistics and
153 * no children.
154 */
155 public void reset() {
156 fValue = new TmfStatistics();
157 fNodes.reset(fPath);
158 }
159
160 /**
161 * Resets the global number of events. It doesn't remove any node
162 * and doesn't modify the partial event count.
163 *
164 * Works recursively.
165 *
166 * @since 2.0
167 */
168 public void resetGlobalValue() {
169 getValue().resetTotalCount();
170 fNodes.resetGlobalValue(fPath);
171 }
172
173 /**
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.
176 *
177 * Works recursively.
178 *
179 * @since 2.0
180 */
181 public void resetTimeRangeValue() {
182 getValue().resetPartialCount();
183 fNodes.resetTimeRangeValue(fPath);
184 }
185 }
This page took 0.034554 seconds and 6 git commands to generate.