Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 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.views.statistics.model; | |
16 | ||
17 | import java.util.Collection; | |
18 | ||
6c13869b | 19 | import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray; |
79e08fd0 BH |
20 | |
21 | /** | |
22 | * <h4>A tree where nodes can be accessed efficiently using paths.</h4> | |
23 | * | |
24 | * <p>It works like file systems. Each node is identified by a key. A path is an array ({@link TmfFixedArray}) of String. The elements of the array represent the path from the root to this node.</p> | |
25 | */ | |
26 | public class TmfStatisticsTreeNode { | |
27 | /** | |
28 | * <h4>Value of the node.</h4> | |
29 | */ | |
66711dc8 | 30 | protected TmfStatistics fValue; |
79e08fd0 BH |
31 | /** |
32 | * <h4>Path of the node.</h4> | |
33 | */ | |
66711dc8 | 34 | protected TmfFixedArray<String> fPath; |
79e08fd0 BH |
35 | /** |
36 | * <h2>Corresponding StatisticsData.</h2> | |
37 | */ | |
66711dc8 | 38 | protected AbsTmfStatisticsTree fNodes; |
79e08fd0 BH |
39 | /** |
40 | * <h4>Constructor.</h4> | |
41 | * @param path Path to the node. | |
42 | * @param nodes Corresponding StatisticsData. | |
43 | */ | |
44 | public TmfStatisticsTreeNode(final TmfFixedArray<String> path, AbsTmfStatisticsTree nodes) { | |
45 | fPath = path; | |
46 | fNodes = nodes; | |
47 | fValue = new TmfStatistics(); | |
48 | } | |
49 | /** | |
50 | * <h4>Test if a node contain the specified child.</h4> | |
51 | * @param key Name of the child. | |
52 | * @return true: if child with given key is present, false: if no child exists with given key name | |
53 | */ | |
54 | public boolean containsChild(String key) { | |
55 | if(AbsTmfStatisticsTree.ROOT.equals(fPath)) | |
56 | return fNodes.get(new TmfFixedArray<String>(key)) != null; | |
57 | return (fNodes.get(fPath.append(key)) != null); | |
58 | } | |
59 | /** | |
60 | * <h4>Get the children of this node.</h4> | |
61 | * @return Direct children of this node. | |
62 | */ | |
63 | public Collection<TmfStatisticsTreeNode> getChildren() { | |
64 | return fNodes.getChildren(fPath); | |
65 | } | |
66 | /** | |
67 | * <h4>Get the children of this node.</h4> | |
68 | * @return Direct children of this node. | |
69 | */ | |
70 | public Collection<TmfStatisticsTreeNode> getAllChildren() { | |
71 | return fNodes.getAllChildren(fPath); | |
72 | } | |
73 | /** | |
74 | * <h4>Get the key for this node.</h4> | |
75 | * @return Key associated with this node. | |
76 | */ | |
77 | public String getKey() { | |
78 | return fPath.get(fPath.size() - 1); | |
79 | } | |
80 | /** | |
81 | * <h4>Get the number of children this node have.</h4> | |
82 | * @return Number of direct children of this node. | |
83 | */ | |
84 | public int getNbChildren() { | |
85 | return fNodes.getChildren(fPath).size(); | |
86 | } | |
87 | /** | |
88 | * <h4>Return the parent node.</h4> | |
89 | * @return Parent node. | |
90 | */ | |
91 | public TmfStatisticsTreeNode getParent() { | |
92 | return fNodes.getParent(fPath); | |
93 | } | |
94 | /** | |
95 | * <h4>Get the path of the node.</h4> | |
96 | * @return The path of the node. | |
97 | */ | |
98 | public TmfFixedArray<String> getPath() { | |
99 | return fPath; | |
100 | } | |
101 | /** | |
102 | * <h4>Get the value of this node.</h4> | |
103 | * @return Value associated with this node. | |
104 | */ | |
105 | public TmfStatistics getValue() { | |
106 | return fValue; | |
107 | } | |
108 | /** | |
109 | * <h4>Indicate if the node have children.</h4> | |
110 | * @return True if the node has children. | |
111 | */ | |
112 | public boolean hasChildren() { | |
113 | return !fNodes.getChildren(fPath).isEmpty(); | |
114 | } | |
115 | /** | |
116 | * <h4>Start from creation time i.e. keep key and parent but new statistics and no children.</h4> | |
117 | */ | |
118 | public void reset() { | |
119 | fValue = new TmfStatistics(); | |
120 | fNodes.reset(fPath); | |
121 | } | |
122 | } |