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 | 9 | * Contributors: |
09667aa4 | 10 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial API |
79e08fd0 BH |
11 | *******************************************************************************/ |
12 | ||
cfd22ad0 | 13 | package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model; |
79e08fd0 BH |
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 | * |
09667aa4 MD |
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 | |
20ff3b75 AM |
23 | * tree can be retrieved. |
24 | * | |
cfd22ad0 MD |
25 | * @version 2.0 |
26 | * @since 2.0 | |
b544077e | 27 | * @author Mathieu Denis |
b544077e | 28 | */ |
79e08fd0 BH |
29 | public class TmfStatisticsTreeRootFactory { |
30 | ||
79e08fd0 BH |
31 | /** |
32 | * Contains the experiment name as the key and the traces data | |
33 | */ | |
34 | private static final Map<String, AbsTmfStatisticsTree> fTreeInstances = new HashMap<String, AbsTmfStatisticsTree>(); | |
35 | ||
79e08fd0 BH |
36 | /** |
37 | * Provide a statisticsTree instance per trace | |
20ff3b75 AM |
38 | * |
39 | * @param traceUniqueId | |
40 | * Unique ID for the trace | |
0d9a6d76 | 41 | * @return the corresponding trace statistics tree |
79e08fd0 BH |
42 | */ |
43 | public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) { | |
44 | ||
45 | AbsTmfStatisticsTree tree = getStatTree(traceUniqueId); | |
46 | if (tree == null) { | |
47 | return null; | |
48 | } | |
49 | return tree.getOrCreate(AbsTmfStatisticsTree.ROOT); | |
50 | } | |
51 | ||
52 | /** | |
20ff3b75 AM |
53 | * Get the tree that's being used for statistics |
54 | * | |
79e08fd0 | 55 | * @param traceUniqueId |
20ff3b75 | 56 | * Unique ID for the trace |
0d9a6d76 | 57 | * @return the corresponding trace statistics tree |
79e08fd0 BH |
58 | */ |
59 | public static AbsTmfStatisticsTree getStatTree(String traceUniqueId) { | |
20ff3b75 | 60 | if (traceUniqueId == null) { |
79e08fd0 | 61 | return null; |
20ff3b75 | 62 | } |
79e08fd0 BH |
63 | |
64 | AbsTmfStatisticsTree tree = fTreeInstances.get(traceUniqueId); | |
65 | return tree; | |
66 | } | |
67 | ||
68 | /** | |
20ff3b75 AM |
69 | * Add the new trace statistics data in the tree. Can be used later on if |
70 | * the same traces is selected back. | |
71 | * | |
0d9a6d76 | 72 | * @param traceUniqueId |
20ff3b75 AM |
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 | |
76 | * trace. | |
0d9a6d76 | 77 | * @param statsData |
20ff3b75 | 78 | * The information about the trace |
8b60cb37 | 79 | * @return The newly created root node of the trace statistics tree, or null if something went wrong |
79e08fd0 | 80 | */ |
8b60cb37 | 81 | public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) { |
20ff3b75 | 82 | if (traceUniqueId == null || statsData == null) { |
8b60cb37 | 83 | return null; |
20ff3b75 | 84 | } |
79e08fd0 BH |
85 | fTreeInstances.put(traceUniqueId, statsData); |
86 | // if called for the first time, create the root node | |
8b60cb37 | 87 | return statsData.getOrCreate(AbsTmfStatisticsTree.ROOT); |
79e08fd0 BH |
88 | } |
89 | ||
90 | /** | |
20ff3b75 AM |
91 | * Return if the given trace is currently known by the statistics manager. |
92 | * | |
79e08fd0 | 93 | * @param traceUniqueId |
20ff3b75 | 94 | * The unique ID of the trace |
0d9a6d76 | 95 | * @return true if the trace id is known |
79e08fd0 BH |
96 | */ |
97 | public static boolean containsTreeRoot(String traceUniqueId) { | |
98 | return fTreeInstances.containsKey(traceUniqueId); | |
99 | } | |
100 | ||
101 | /** | |
102 | * Remove previously registered statistics tree. | |
20ff3b75 | 103 | * |
79e08fd0 | 104 | * @param traceUniqueId |
20ff3b75 | 105 | * The unique ID of the trace |
79e08fd0 BH |
106 | */ |
107 | public static void removeStatTreeRoot(String traceUniqueId) { | |
108 | if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) { | |
109 | fTreeInstances.remove(traceUniqueId); | |
110 | } | |
111 | } | |
112 | ||
113 | /** | |
114 | * Remove all tree and root instances | |
115 | */ | |
116 | public static void removeAll() { | |
117 | fTreeInstances.clear(); | |
118 | } | |
119 | } |