Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 95a4dcd011e6a4f8dc6f7aaa1e842eb6a86e241b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************************************
 * Copyright (c) 2011, 2012 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Yann N. Dauphin <dhaemon@gmail.com> - Implementation for stats
 *   Francois Godin <copelnug@gmail.com> - Re-design for new stats structure
 *   Mathieu Denis <mathieu.denis@polymtl.ca> - Re-design for new stats structure (2)
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;

import java.util.Collection;

import org.eclipse.linuxtools.tmf.core.util.TmfFixedArray;

/**
 * A tree where nodes can be accessed efficiently using paths.
 *
 * 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.
 *
 * @version 2.0
 * @since 2.0
 * @author Mathieu Denis
 */
public class TmfStatisticsTreeNode {

    /**
     * Value of the node.
     */
    protected TmfStatistics fValue;

    /**
     * Path of the node.
     */
    protected TmfFixedArray<String> fPath;

    /**
     * Corresponding StatisticsData.
     */
    protected AbsTmfStatisticsTree fNodes;

    /**
     * Constructor.
     *
     * @param path
     *            Path to the node.
     * @param nodes
     *            Corresponding StatisticsData.
     */
    public TmfStatisticsTreeNode(final TmfFixedArray<String> path,
            AbsTmfStatisticsTree nodes) {
        fPath = path;
        fNodes = nodes;
        fValue = new TmfStatistics();
    }

    /**
     * Test if a node contain the specified child.
     *
     * @param key
     *            Name of the child.
     * @return true: if child with given key is present, false: if no child
     *         exists with given key name
     */
    public boolean containsChild(String key) {
        if (AbsTmfStatisticsTree.ROOT.equals(fPath)) {
            return fNodes.get(new TmfFixedArray<String>(key)) != null;
        }
        return (fNodes.get(fPath.append(key)) != null);
    }

    /**
     * Get the children of this node.
     *
     * @return Direct children of this node.
     */
    public Collection<TmfStatisticsTreeNode> getChildren() {
        return fNodes.getChildren(fPath);
    }

    /**
     * Get the children of this node.
     *
     * @return Direct children of this node.
     */
    public Collection<TmfStatisticsTreeNode> getAllChildren() {
        return fNodes.getAllChildren(fPath);
    }

    /**
     * Get the key for this node.
     *
     * @return Key associated with this node.
     */
    public String getKey() {
        return fPath.get(fPath.size() - 1);
    }

    /**
     * Get the number of children this node have.
     *
     * @return Number of direct children of this node.
     */
    public int getNbChildren() {
        return fNodes.getChildren(fPath).size();
    }

    /**
     * Return the parent node.
     *
     * @return Parent node.
     */
    public TmfStatisticsTreeNode getParent() {
        return fNodes.getParent(fPath);
    }

    /**
     * Get the path of the node.
     *
     * @return The path of the node.
     */
    public TmfFixedArray<String> getPath() {
        return fPath;
    }

    /**
     * Get the value of this node.
     *
     * @return Value associated with this node.
     */
    public TmfStatistics getValue() {
        return fValue;
    }

    /**
     * Indicate if the node have children.
     *
     * @return True if the node has children.
     */
    public boolean hasChildren() {
        return !fNodes.getChildren(fPath).isEmpty();
    }

    /**
     * Start from creation time i.e. keep key and parent but new statistics and
     * no children.
     */
    public void reset() {
        fValue = new TmfStatistics();
        fNodes.reset(fPath);
    }

    /**
     * Resets the number of events in the time range. It doesn't remove any node
     * and doesn't modify the global event count.
     *
     * @since 2.0
     */
    public void resetTimeRangeValue() {
        getValue().resetPartialCount();
        fNodes.resetTimeRangeValue(fPath);
    }
}

Back to the top