Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
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 | |
8 | * | |
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 | ||
18 | public class TmfStatisticsTreeRootFactory { | |
19 | ||
20 | // ----------------------------------------------------------------------- | |
21 | // Data | |
22 | // ----------------------------------------------------------------------- | |
23 | /** | |
24 | * Contains the experiment name as the key and the traces data | |
25 | */ | |
26 | private static final Map<String, AbsTmfStatisticsTree> fTreeInstances = new HashMap<String, AbsTmfStatisticsTree>(); | |
27 | ||
28 | // ----------------------------------------------------------------------- | |
29 | // Methods | |
30 | // ----------------------------------------------------------------------- | |
31 | ||
32 | /** | |
33 | * Provide a statisticsTree instance per trace | |
34 | * | |
35 | * @return | |
36 | */ | |
37 | public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) { | |
38 | ||
39 | AbsTmfStatisticsTree tree = getStatTree(traceUniqueId); | |
40 | if (tree == null) { | |
41 | return null; | |
42 | } | |
43 | return tree.getOrCreate(AbsTmfStatisticsTree.ROOT); | |
44 | } | |
45 | ||
46 | /** | |
47 | * | |
48 | * @param traceUniqueId | |
49 | * @return | |
50 | */ | |
51 | public static AbsTmfStatisticsTree getStatTree(String traceUniqueId) { | |
52 | if (traceUniqueId == null) | |
53 | return null; | |
54 | ||
55 | AbsTmfStatisticsTree tree = fTreeInstances.get(traceUniqueId); | |
56 | return tree; | |
57 | } | |
58 | ||
59 | /** | |
60 | * Add the new trace statistics data in the tree. Can be used later on if the same traces is selected back. | |
61 | * | |
62 | * @param experimentName | |
63 | * the name of the trace which will be used as a key to store the data. Must be different for each traces, otherwise the traces might | |
64 | * be overwritten which would trigger a reload of the same trace. | |
65 | * @param data | |
66 | * the information about the trace | |
67 | */ | |
68 | public static void addStatsTreeRoot(String traceUniqueId, AbsTmfStatisticsTree statsData) { | |
69 | if (traceUniqueId == null || statsData == null) | |
70 | return; | |
71 | ||
72 | fTreeInstances.put(traceUniqueId, statsData); | |
73 | // if called for the first time, create the root node | |
74 | statsData.getOrCreate(AbsTmfStatisticsTree.ROOT); | |
75 | } | |
76 | ||
77 | /** | |
78 | * | |
79 | * @param traceUniqueId | |
80 | * @return | |
81 | */ | |
82 | public static boolean containsTreeRoot(String traceUniqueId) { | |
83 | return fTreeInstances.containsKey(traceUniqueId); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Remove previously registered statistics tree. | |
88 | * | |
89 | * @param traceUniqueId | |
90 | */ | |
91 | public static void removeStatTreeRoot(String traceUniqueId) { | |
92 | if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) { | |
93 | fTreeInstances.remove(traceUniqueId); | |
94 | } | |
95 | } | |
96 | ||
97 | /** | |
98 | * Remove all tree and root instances | |
99 | */ | |
100 | public static void removeAll() { | |
101 | fTreeInstances.clear(); | |
102 | } | |
103 | } |