tmf: Refactor TMF statistics
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / statistics / model / TmfStatisticsTreeManager.java
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.viewers.statistics.model;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19 * Factory class to create and store TMF statistic trees.
20 *
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.
24 *
25 * @version 2.0
26 * @since 2.0
27 * @author Mathieu Denis
28 */
29 public class TmfStatisticsTreeManager {
30
31 /**
32 * Contains the experiment name as the key and the traces data
33 */
34 private static final Map<String, TmfStatisticsTree> fTreeInstances = new HashMap<String, TmfStatisticsTree>();
35
36 /**
37 * Provide a statisticsTree instance per trace
38 *
39 * @param traceUniqueId
40 * Unique ID for the trace
41 * @return The root node of the corresponding trace statistics tree
42 */
43 public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
44
45 TmfStatisticsTree tree = getStatTree(traceUniqueId);
46 if (tree == null) {
47 return null;
48 }
49 return tree.getOrCreate(TmfStatisticsTree.ROOT);
50 }
51
52 /**
53 * Get the tree that's being used for statistics
54 *
55 * @param traceUniqueId
56 * Unique ID for the trace
57 * @return the corresponding trace statistics tree
58 */
59 public static TmfStatisticsTree getStatTree(String traceUniqueId) {
60 if (traceUniqueId == null) {
61 return null;
62 }
63
64 TmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
65 return tree;
66 }
67
68 /**
69 * Add the new trace statistics data in the tree. Can be used later on if
70 * the same traces is selected back.
71 *
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
76 * trace.
77 * @param statsData
78 * The information about the trace
79 * @return The newly created root node of the trace statistics tree, or null if something went wrong
80 */
81 public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, TmfStatisticsTree statsData) {
82 if (traceUniqueId == null || statsData == null) {
83 return null;
84 }
85 fTreeInstances.put(traceUniqueId, statsData);
86 // if called for the first time, create the root node
87 return statsData.getOrCreate(TmfStatisticsTree.ROOT);
88 }
89
90 /**
91 * Return if the given trace is currently known by the statistics manager.
92 *
93 * @param traceUniqueId
94 * The unique ID of the trace
95 * @return true if the trace id is known
96 */
97 public static boolean containsTreeRoot(String traceUniqueId) {
98 return fTreeInstances.containsKey(traceUniqueId);
99 }
100
101 /**
102 * Remove previously registered statistics tree.
103 *
104 * @param traceUniqueId
105 * The unique ID of the trace
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 }
This page took 0.034608 seconds and 6 git commands to generate.