tmf: Refactor the statistics
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / statistics / model / TmfStatisticsTreeNode.java
CommitLineData
79e08fd0 1/*******************************************************************************
b544077e 2 * Copyright (c) 2011, 2012 Ericsson
013a5f1c 3 *
79e08fd0
BH
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
013a5f1c 8 *
79e08fd0 9 * Contributors:
09667aa4
MD
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)
79e08fd0
BH
13 *******************************************************************************/
14
cfd22ad0 15package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
79e08fd0
BH
16
17import java.util.Collection;
18
6c13869b 19import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;
79e08fd0
BH
20
21/**
013a5f1c
AM
22 * A tree where nodes can be accessed efficiently using paths.
23 *
09667aa4
MD
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.
013a5f1c 27 *
25a042b3 28 * @version 2.0
cfd22ad0 29 * @since 2.0
013a5f1c 30 * @author Mathieu Denis
79e08fd0
BH
31 */
32public class TmfStatisticsTreeNode {
09667aa4
MD
33
34 /**
35 * Value of the node.
36 */
66711dc8 37 protected TmfStatistics fValue;
09667aa4
MD
38
39 /**
40 * Path of the node.
41 */
66711dc8 42 protected TmfFixedArray<String> fPath;
09667aa4
MD
43
44 /**
45 * Corresponding StatisticsData.
46 */
66711dc8 47 protected AbsTmfStatisticsTree fNodes;
09667aa4
MD
48
49 /**
50 * Constructor.
51 *
52 * @param path
53 * Path to the node.
54 * @param nodes
55 * Corresponding StatisticsData.
56 */
25a042b3
MD
57 public TmfStatisticsTreeNode(final TmfFixedArray<String> path,
58 AbsTmfStatisticsTree nodes) {
09667aa4
MD
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)) {
013a5f1c
AM
74 return fNodes.get(new TmfFixedArray<String>(key)) != null;
75 }
09667aa4
MD
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 /**
255224d9 89 * Gets every children of this node even if no event has been registered for a node.
09667aa4 90 *
79e08fd0
BH
91 * @return Direct children of this node.
92 */
93 public Collection<TmfStatisticsTreeNode> getAllChildren() {
94 return fNodes.getAllChildren(fPath);
95 }
09667aa4
MD
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 }
25a042b3
MD
159
160 /**
161 * Resets the number of events in the time range. It doesn't remove any node
162 * and doesn't modify the global event count.
163 *
164 * @since 2.0
165 */
166 public void resetTimeRangeValue() {
167 getValue().resetPartialCount();
168 fNodes.resetTimeRangeValue(fPath);
169 }
09667aa4 170}
This page took 0.055436 seconds and 5 git commands to generate.