1 /*******************************************************************************
2 * Copyright (c) 2011 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
.views
.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.
26 * @author Mathieu Denis
29 public class TmfStatisticsTreeRootFactory
{
32 * Contains the experiment name as the key and the traces data
34 private static final Map
<String
, AbsTmfStatisticsTree
> fTreeInstances
= new HashMap
<String
, AbsTmfStatisticsTree
>();
37 * Provide a statisticsTree instance per trace
39 * @param traceUniqueId
40 * Unique ID for the trace
41 * @return the corresponding trace statistics tree
43 public static TmfStatisticsTreeNode
getStatTreeRoot(String traceUniqueId
) {
45 AbsTmfStatisticsTree tree
= getStatTree(traceUniqueId
);
49 return tree
.getOrCreate(AbsTmfStatisticsTree
.ROOT
);
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 AbsTmfStatisticsTree
getStatTree(String traceUniqueId
) {
60 if (traceUniqueId
== null) {
64 AbsTmfStatisticsTree 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
80 public static void addStatsTreeRoot(String traceUniqueId
, AbsTmfStatisticsTree statsData
) {
81 if (traceUniqueId
== null || statsData
== null) {
85 fTreeInstances
.put(traceUniqueId
, statsData
);
86 // if called for the first time, create the root node
87 statsData
.getOrCreate(AbsTmfStatisticsTree
.ROOT
);
91 * Return if the given trace is currently known by the statistics manager.
93 * @param traceUniqueId
94 * The unique ID of the trace
95 * @return true if the trace id is known
97 public static boolean containsTreeRoot(String traceUniqueId
) {
98 return fTreeInstances
.containsKey(traceUniqueId
);
102 * Remove previously registered statistics tree.
104 * @param traceUniqueId
105 * The unique ID of the trace
107 public static void removeStatTreeRoot(String traceUniqueId
) {
108 if (traceUniqueId
!= null && fTreeInstances
.containsKey(traceUniqueId
)) {
109 fTreeInstances
.remove(traceUniqueId
);
114 * Remove all tree and root instances
116 public static void removeAll() {
117 fTreeInstances
.clear();