1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 Ericsson
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
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
;
15 import java
.util
.HashMap
;
19 * Factory class to create and store TMF statistic trees.
21 * Based on a given tree node ID a TMF statistic tree is stored internally. A
22 * root node is created for each tree. Using the tree node ID the statistics
23 * tree can be retrieved.
25 * @author Mathieu Denis
29 public class TmfStatisticsTreeManager
{
32 * Contains the experiment name as the key and the traces data
34 private static final Map
<String
, TmfStatisticsTree
> fTreeInstances
= new HashMap
<>();
37 * Provide a statisticsTree instance per trace
39 * @param traceUniqueId
40 * Unique ID for the trace
41 * @return The root node of the corresponding trace statistics tree
43 public static TmfStatisticsTreeNode
getStatTreeRoot(String traceUniqueId
) {
45 TmfStatisticsTree tree
= getStatTree(traceUniqueId
);
49 return tree
.getRootNode();
53 * Get the tree that's being used for statistics
55 * @param traceUniqueId
56 * Unique ID for the trace
57 * @return the corresponding trace statistics tree
59 public static TmfStatisticsTree
getStatTree(String traceUniqueId
) {
60 if (traceUniqueId
== null) {
64 TmfStatisticsTree tree
= fTreeInstances
.get(traceUniqueId
);
69 * Add the new trace statistics data in the tree. Can be used later on if
70 * the same traces is selected back.
72 * @param traceUniqueId
73 * The name of the trace which will be used as a key to store the
74 * data. Must be different for each traces, otherwise the traces
75 * might be overwritten which would trigger a reload of the same
78 * The information about the trace
79 * @return The newly created root node of the trace statistics tree, or null if something went wrong
81 public static TmfStatisticsTreeNode
addStatsTreeRoot(String traceUniqueId
, TmfStatisticsTree statsData
) {
82 if (traceUniqueId
== null || statsData
== null) {
85 fTreeInstances
.put(traceUniqueId
, statsData
);
86 return statsData
.getRootNode();
90 * Return if the given trace is currently known by the statistics manager.
92 * @param traceUniqueId
93 * The unique ID of the trace
94 * @return true if the trace id is known
96 public static boolean containsTreeRoot(String traceUniqueId
) {
97 return fTreeInstances
.containsKey(traceUniqueId
);
101 * Remove previously registered statistics tree.
103 * @param traceUniqueId
104 * The unique ID of the trace
106 public static void removeStatTreeRoot(String traceUniqueId
) {
107 if (traceUniqueId
!= null && fTreeInstances
.containsKey(traceUniqueId
)) {
108 fTreeInstances
.remove(traceUniqueId
);
113 * Remove all tree and root instances
115 public static void removeAll() {
116 fTreeInstances
.clear();