analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / viewers / statistics / model / TmfStatisticsTreeManager.java
CommitLineData
79e08fd0 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2011, 2014 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
2bdf0193 13package org.eclipse.tracecompass.tmf.ui.viewers.statistics.model;
79e08fd0
BH
14
15import java.util.HashMap;
16import 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 *
7588c810 25 * @author Mathieu Denis
b544077e 26 */
36033ff0 27public class TmfStatisticsTreeManager {
79e08fd0 28
79e08fd0
BH
29 /**
30 * Contains the experiment name as the key and the traces data
31 */
507b1336 32 private static final Map<String, TmfStatisticsTree> fTreeInstances = new HashMap<>();
79e08fd0 33
79e08fd0
BH
34 /**
35 * Provide a statisticsTree instance per trace
20ff3b75
AM
36 *
37 * @param traceUniqueId
38 * Unique ID for the trace
eeb388b1 39 * @return The root node of the corresponding trace statistics tree
79e08fd0
BH
40 */
41 public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
42
36033ff0 43 TmfStatisticsTree tree = getStatTree(traceUniqueId);
79e08fd0
BH
44 if (tree == null) {
45 return null;
46 }
7588c810 47 return tree.getRootNode();
79e08fd0
BH
48 }
49
50 /**
20ff3b75
AM
51 * Get the tree that's being used for statistics
52 *
79e08fd0 53 * @param traceUniqueId
20ff3b75 54 * Unique ID for the trace
0d9a6d76 55 * @return the corresponding trace statistics tree
79e08fd0 56 */
36033ff0 57 public static TmfStatisticsTree getStatTree(String traceUniqueId) {
20ff3b75 58 if (traceUniqueId == null) {
79e08fd0 59 return null;
20ff3b75 60 }
79e08fd0 61
36033ff0 62 TmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
79e08fd0
BH
63 return tree;
64 }
65
66 /**
20ff3b75
AM
67 * Add the new trace statistics data in the tree. Can be used later on if
68 * the same traces is selected back.
69 *
0d9a6d76 70 * @param traceUniqueId
20ff3b75
AM
71 * The name of the trace which will be used as a key to store the
72 * data. Must be different for each traces, otherwise the traces
73 * might be overwritten which would trigger a reload of the same
74 * trace.
0d9a6d76 75 * @param statsData
20ff3b75 76 * The information about the trace
8b60cb37 77 * @return The newly created root node of the trace statistics tree, or null if something went wrong
79e08fd0 78 */
36033ff0 79 public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, TmfStatisticsTree statsData) {
20ff3b75 80 if (traceUniqueId == null || statsData == null) {
8b60cb37 81 return null;
20ff3b75 82 }
79e08fd0 83 fTreeInstances.put(traceUniqueId, statsData);
7588c810 84 return statsData.getRootNode();
79e08fd0
BH
85 }
86
87 /**
20ff3b75
AM
88 * Return if the given trace is currently known by the statistics manager.
89 *
79e08fd0 90 * @param traceUniqueId
20ff3b75 91 * The unique ID of the trace
0d9a6d76 92 * @return true if the trace id is known
79e08fd0
BH
93 */
94 public static boolean containsTreeRoot(String traceUniqueId) {
95 return fTreeInstances.containsKey(traceUniqueId);
96 }
97
98 /**
99 * Remove previously registered statistics tree.
20ff3b75 100 *
79e08fd0 101 * @param traceUniqueId
20ff3b75 102 * The unique ID of the trace
79e08fd0
BH
103 */
104 public static void removeStatTreeRoot(String traceUniqueId) {
105 if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) {
106 fTreeInstances.remove(traceUniqueId);
107 }
108 }
109
110 /**
111 * Remove all tree and root instances
112 */
113 public static void removeAll() {
114 fTreeInstances.clear();
115 }
116}
This page took 0.081906 seconds and 5 git commands to generate.