Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
20ff3b75 | 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 | |
20ff3b75 | 8 | * |
79e08fd0 BH |
9 | * Contributors: |
10 | * Mathieu Denis (mathieu.denis@polymtl.ca) - Initial API | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.statistics.model; | |
14 | ||
15 | import java.util.HashMap; | |
16 | import java.util.Map; | |
17 | ||
b544077e BH |
18 | /** |
19 | * Factory class to create and store TMF statistic trees. | |
20ff3b75 | 20 | * |
b544077e | 21 | * Based on a given tree node ID a TMF statistic tree is stored internally. |
20ff3b75 AM |
22 | * A root node is created for each tree. Using the tree node ID the statistics |
23 | * tree can be retrieved. | |
24 | * | |
b544077e BH |
25 | * @version 1.0 |
26 | * @author Mathieu Denis | |
27 | * | |
28 | */ | |
79e08fd0 BH |
29 | public class TmfStatisticsTreeRootFactory { |
30 | ||
31 | // ----------------------------------------------------------------------- | |
32 | // Data | |
33 | // ----------------------------------------------------------------------- | |
34 | /** | |
35 | * Contains the experiment name as the key and the traces data | |
36 | */ | |
37 | private static final Map<String, AbsTmfStatisticsTree> fTreeInstances = new HashMap<String, AbsTmfStatisticsTree>(); | |
38 | ||
39 | // ----------------------------------------------------------------------- | |
40 | // Methods | |
41 | // ----------------------------------------------------------------------- | |
42 | ||
43 | /** | |
44 | * Provide a statisticsTree instance per trace | |
20ff3b75 AM |
45 | * |
46 | * @param traceUniqueId | |
47 | * Unique ID for the trace | |
0d9a6d76 | 48 | * @return the corresponding trace statistics tree |
79e08fd0 BH |
49 | */ |
50 | public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) { | |
51 | ||
52 | AbsTmfStatisticsTree tree = getStatTree(traceUniqueId); | |
53 | if (tree == null) { | |
54 | return null; | |
55 | } | |
56 | return tree.getOrCreate(AbsTmfStatisticsTree.ROOT); | |
57 | } | |
58 | ||
59 | /** | |
20ff3b75 AM |
60 | * Get the tree that's being used for statistics |
61 | * | |
79e08fd0 | 62 | * @param traceUniqueId |
20ff3b75 | 63 | * Unique ID for the trace |
0d9a6d76 | 64 | * @return the corresponding trace statistics tree |
79e08fd0 BH |
65 | */ |
66 | public static AbsTmfStatisticsTree getStatTree(String traceUniqueId) { | |
20ff3b75 | 67 | if (traceUniqueId == null) { |
79e08fd0 | 68 | return null; |
20ff3b75 | 69 | } |
79e08fd0 BH |
70 | |
71 | AbsTmfStatisticsTree tree = fTreeInstances.get(traceUniqueId); | |
72 | return tree; | |
73 | } | |
74 | ||
75 | /** | |
20ff3b75 AM |
76 | * Add the new trace statistics data in the tree. Can be used later on if |
77 | * the same traces is selected back. | |
78 | * | |
0d9a6d76 | 79 | * @param traceUniqueId |
20ff3b75 AM |
80 | * The name of the trace which will be used as a key to store the |
81 | * data. Must be different for each traces, otherwise the traces | |
82 | * might be overwritten which would trigger a reload of the same | |
83 | * trace. | |
0d9a6d76 | 84 | * @param statsData |
20ff3b75 | 85 | * The information about the trace |
79e08fd0 BH |
86 | */ |
87 | public static void addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) { | |
20ff3b75 | 88 | if (traceUniqueId == null || statsData == null) { |
79e08fd0 | 89 | return; |
20ff3b75 | 90 | } |
79e08fd0 BH |
91 | |
92 | fTreeInstances.put(traceUniqueId, statsData); | |
93 | // if called for the first time, create the root node | |
94 | statsData.getOrCreate(AbsTmfStatisticsTree.ROOT); | |
95 | } | |
96 | ||
97 | /** | |
20ff3b75 AM |
98 | * Return if the given trace is currently known by the statistics manager. |
99 | * | |
79e08fd0 | 100 | * @param traceUniqueId |
20ff3b75 | 101 | * The unique ID of the trace |
0d9a6d76 | 102 | * @return true if the trace id is known |
79e08fd0 BH |
103 | */ |
104 | public static boolean containsTreeRoot(String traceUniqueId) { | |
105 | return fTreeInstances.containsKey(traceUniqueId); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Remove previously registered statistics tree. | |
20ff3b75 | 110 | * |
79e08fd0 | 111 | * @param traceUniqueId |
20ff3b75 | 112 | * The unique ID of the trace |
79e08fd0 BH |
113 | */ |
114 | public static void removeStatTreeRoot(String traceUniqueId) { | |
115 | if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) { | |
116 | fTreeInstances.remove(traceUniqueId); | |
117 | } | |
118 | } | |
119 | ||
120 | /** | |
121 | * Remove all tree and root instances | |
122 | */ | |
123 | public static void removeAll() { | |
124 | fTreeInstances.clear(); | |
125 | } | |
126 | } |