tmf: Refactor TMF 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
79e08fd0 19/**
013a5f1c
AM
20 * A tree where nodes can be accessed efficiently using paths.
21 *
09667aa4 22 * It works like file systems. Each node is identified by a key. A path is an
5673a177
AM
23 * array of String. The elements of the array represent the path from the root
24 * to this node.
013a5f1c 25 *
25a042b3 26 * @version 2.0
cfd22ad0 27 * @since 2.0
013a5f1c 28 * @author Mathieu Denis
79e08fd0
BH
29 */
30public class TmfStatisticsTreeNode {
09667aa4
MD
31
32 /**
33 * Value of the node.
34 */
89c06060 35 protected TmfStatisticsValues fValues;
09667aa4
MD
36
37 /**
38 * Path of the node.
39 */
5673a177 40 protected String[] fPath;
09667aa4
MD
41
42 /**
43 * Corresponding StatisticsData.
44 */
36033ff0 45 protected TmfStatisticsTree fNodes;
09667aa4
MD
46
47 /**
48 * Constructor.
49 *
50 * @param path
51 * Path to the node.
52 * @param nodes
53 * Corresponding StatisticsData.
54 */
36033ff0 55 public TmfStatisticsTreeNode(TmfStatisticsTree nodes, final String... path) {
09667aa4
MD
56 fPath = path;
57 fNodes = nodes;
89c06060 58 fValues = new TmfStatisticsValues();
09667aa4
MD
59 }
60
61 /**
62 * Test if a node contain the specified child.
63 *
64 * @param key
65 * Name of the child.
66 * @return true: if child with given key is present, false: if no child
67 * exists with given key name
68 */
69 public boolean containsChild(String key) {
36033ff0 70 if (TmfStatisticsTree.ROOT.equals(fPath)) {
5673a177 71 return fNodes.get(key) != null;
013a5f1c 72 }
5673a177
AM
73
74 String[] childPath = new String[fPath.length + 1];
75 System.arraycopy(fPath, 0, childPath, 0, fPath.length);
76 childPath[fPath.length] = key;
77 return (fNodes.get(childPath) != null);
09667aa4
MD
78 }
79
80 /**
81 * Get the children of this node.
82 *
83 * @return Direct children of this node.
84 */
85 public Collection<TmfStatisticsTreeNode> getChildren() {
86 return fNodes.getChildren(fPath);
87 }
88
89 /**
255224d9 90 * Gets every children of this node even if no event has been registered for a node.
09667aa4 91 *
79e08fd0
BH
92 * @return Direct children of this node.
93 */
94 public Collection<TmfStatisticsTreeNode> getAllChildren() {
95 return fNodes.getAllChildren(fPath);
96 }
09667aa4
MD
97
98 /**
99 * Get the key for this node.
100 *
101 * @return Key associated with this node.
102 */
103 public String getKey() {
5673a177 104 return fPath[fPath.length - 1];
09667aa4
MD
105 }
106
107 /**
108 * Get the number of children this node have.
109 *
110 * @return Number of direct children of this node.
111 */
112 public int getNbChildren() {
113 return fNodes.getChildren(fPath).size();
114 }
115
116 /**
117 * Return the parent node.
118 *
119 * @return Parent node.
120 */
121 public TmfStatisticsTreeNode getParent() {
122 return fNodes.getParent(fPath);
123 }
124
125 /**
126 * Get the path of the node.
127 *
128 * @return The path of the node.
129 */
5673a177 130 public String[] getPath() {
09667aa4
MD
131 return fPath;
132 }
133
134 /**
135 * Get the value of this node.
136 *
137 * @return Value associated with this node.
138 */
89c06060
AM
139 public TmfStatisticsValues getValues() {
140 return fValues;
09667aa4
MD
141 }
142
143 /**
144 * Indicate if the node have children.
145 *
146 * @return True if the node has children.
147 */
148 public boolean hasChildren() {
149 return !fNodes.getChildren(fPath).isEmpty();
150 }
151
152 /**
153 * Start from creation time i.e. keep key and parent but new statistics and
154 * no children.
155 */
156 public void reset() {
89c06060 157 fValues = new TmfStatisticsValues();
09667aa4
MD
158 fNodes.reset(fPath);
159 }
25a042b3 160
73fbf6be
MD
161 /**
162 * Resets the global number of events. It doesn't remove any node
163 * and doesn't modify the partial event count.
164 *
165 * Works recursively.
166 *
167 * @since 2.0
168 */
169 public void resetGlobalValue() {
89c06060 170 getValues().resetTotalCount();
73fbf6be
MD
171 fNodes.resetGlobalValue(fPath);
172 }
173
25a042b3
MD
174 /**
175 * Resets the number of events in the time range. It doesn't remove any node
176 * and doesn't modify the global event count.
177 *
eeb388b1
MD
178 * Works recursively.
179 *
25a042b3
MD
180 * @since 2.0
181 */
182 public void resetTimeRangeValue() {
89c06060 183 getValues().resetPartialCount();
25a042b3
MD
184 fNodes.resetTimeRangeValue(fPath);
185 }
09667aa4 186}
This page took 0.039874 seconds and 5 git commands to generate.