Commit | Line | Data |
---|---|---|
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 | ||
15 | package org.eclipse.linuxtools.tmf.ui.views.statistics.model; | |
16 | ||
17 | import java.util.Collection; | |
18 | ||
6c13869b | 19 | import 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 |
013a5f1c | 29 | * @author Mathieu Denis |
79e08fd0 BH |
30 | */ |
31 | public class TmfStatisticsTreeNode { | |
09667aa4 MD |
32 | |
33 | /** | |
34 | * Value of the node. | |
35 | */ | |
66711dc8 | 36 | protected TmfStatistics fValue; |
09667aa4 MD |
37 | |
38 | /** | |
39 | * Path of the node. | |
40 | */ | |
66711dc8 | 41 | protected TmfFixedArray<String> fPath; |
09667aa4 MD |
42 | |
43 | /** | |
44 | * Corresponding StatisticsData. | |
45 | */ | |
66711dc8 | 46 | protected AbsTmfStatisticsTree fNodes; |
09667aa4 MD |
47 | |
48 | /** | |
49 | * Constructor. | |
50 | * | |
51 | * @param path | |
52 | * Path to the node. | |
53 | * @param nodes | |
54 | * Corresponding StatisticsData. | |
55 | */ | |
25a042b3 MD |
56 | public TmfStatisticsTreeNode(final TmfFixedArray<String> path, |
57 | AbsTmfStatisticsTree nodes) { | |
09667aa4 MD |
58 | fPath = path; |
59 | fNodes = nodes; | |
60 | fValue = new TmfStatistics(); | |
61 | } | |
62 | ||
63 | /** | |
64 | * Test if a node contain the specified child. | |
65 | * | |
66 | * @param key | |
67 | * Name of the child. | |
68 | * @return true: if child with given key is present, false: if no child | |
69 | * exists with given key name | |
70 | */ | |
71 | public boolean containsChild(String key) { | |
72 | if (AbsTmfStatisticsTree.ROOT.equals(fPath)) { | |
013a5f1c AM |
73 | return fNodes.get(new TmfFixedArray<String>(key)) != null; |
74 | } | |
09667aa4 MD |
75 | return (fNodes.get(fPath.append(key)) != null); |
76 | } | |
77 | ||
78 | /** | |
79 | * Get the children of this node. | |
80 | * | |
81 | * @return Direct children of this node. | |
82 | */ | |
83 | public Collection<TmfStatisticsTreeNode> getChildren() { | |
84 | return fNodes.getChildren(fPath); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Get the children of this node. | |
89 | * | |
79e08fd0 BH |
90 | * @return Direct children of this node. |
91 | */ | |
92 | public Collection<TmfStatisticsTreeNode> getAllChildren() { | |
93 | return fNodes.getAllChildren(fPath); | |
94 | } | |
09667aa4 MD |
95 | |
96 | /** | |
97 | * Get the key for this node. | |
98 | * | |
99 | * @return Key associated with this node. | |
100 | */ | |
101 | public String getKey() { | |
102 | return fPath.get(fPath.size() - 1); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Get the number of children this node have. | |
107 | * | |
108 | * @return Number of direct children of this node. | |
109 | */ | |
110 | public int getNbChildren() { | |
111 | return fNodes.getChildren(fPath).size(); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Return the parent node. | |
116 | * | |
117 | * @return Parent node. | |
118 | */ | |
119 | public TmfStatisticsTreeNode getParent() { | |
120 | return fNodes.getParent(fPath); | |
121 | } | |
122 | ||
123 | /** | |
124 | * Get the path of the node. | |
125 | * | |
126 | * @return The path of the node. | |
127 | */ | |
128 | public TmfFixedArray<String> getPath() { | |
129 | return fPath; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Get the value of this node. | |
134 | * | |
135 | * @return Value associated with this node. | |
136 | */ | |
137 | public TmfStatistics getValue() { | |
138 | return fValue; | |
139 | } | |
140 | ||
141 | /** | |
142 | * Indicate if the node have children. | |
143 | * | |
144 | * @return True if the node has children. | |
145 | */ | |
146 | public boolean hasChildren() { | |
147 | return !fNodes.getChildren(fPath).isEmpty(); | |
148 | } | |
149 | ||
150 | /** | |
151 | * Start from creation time i.e. keep key and parent but new statistics and | |
152 | * no children. | |
153 | */ | |
154 | public void reset() { | |
155 | fValue = new TmfStatistics(); | |
156 | fNodes.reset(fPath); | |
157 | } | |
25a042b3 MD |
158 | |
159 | /** | |
160 | * Resets the number of events in the time range. It doesn't remove any node | |
161 | * and doesn't modify the global event count. | |
162 | * | |
163 | * @since 2.0 | |
164 | */ | |
165 | public void resetTimeRangeValue() { | |
166 | getValue().resetPartialCount(); | |
167 | fNodes.resetTimeRangeValue(fPath); | |
168 | } | |
09667aa4 | 169 | } |