Copyright header update, 2015 edition
[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
cfd22ad0
MD
26 * @version 2.0
27 * @since 2.0
b544077e 28 */
36033ff0 29public class TmfStatisticsTreeManager {
79e08fd0 30
79e08fd0
BH
31 /**
32 * Contains the experiment name as the key and the traces data
33 */
507b1336 34 private static final Map<String, TmfStatisticsTree> fTreeInstances = new HashMap<>();
79e08fd0 35
79e08fd0
BH
36 /**
37 * Provide a statisticsTree instance per trace
20ff3b75
AM
38 *
39 * @param traceUniqueId
40 * Unique ID for the trace
eeb388b1 41 * @return The root node of the corresponding trace statistics tree
79e08fd0
BH
42 */
43 public static TmfStatisticsTreeNode getStatTreeRoot(String traceUniqueId) {
44
36033ff0 45 TmfStatisticsTree tree = getStatTree(traceUniqueId);
79e08fd0
BH
46 if (tree == null) {
47 return null;
48 }
7588c810 49 return tree.getRootNode();
79e08fd0
BH
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 58 */
36033ff0 59 public static TmfStatisticsTree getStatTree(String traceUniqueId) {
20ff3b75 60 if (traceUniqueId == null) {
79e08fd0 61 return null;
20ff3b75 62 }
79e08fd0 63
36033ff0 64 TmfStatisticsTree tree = fTreeInstances.get(traceUniqueId);
79e08fd0
BH
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 */
36033ff0 81 public static TmfStatisticsTreeNode addStatsTreeRoot(String traceUniqueId, TmfStatisticsTree statsData) {
20ff3b75 82 if (traceUniqueId == null || statsData == null) {
8b60cb37 83 return null;
20ff3b75 84 }
79e08fd0 85 fTreeInstances.put(traceUniqueId, statsData);
7588c810 86 return statsData.getRootNode();
79e08fd0
BH
87 }
88
89 /**
20ff3b75
AM
90 * Return if the given trace is currently known by the statistics manager.
91 *
79e08fd0 92 * @param traceUniqueId
20ff3b75 93 * The unique ID of the trace
0d9a6d76 94 * @return true if the trace id is known
79e08fd0
BH
95 */
96 public static boolean containsTreeRoot(String traceUniqueId) {
97 return fTreeInstances.containsKey(traceUniqueId);
98 }
99
100 /**
101 * Remove previously registered statistics tree.
20ff3b75 102 *
79e08fd0 103 * @param traceUniqueId
20ff3b75 104 * The unique ID of the trace
79e08fd0
BH
105 */
106 public static void removeStatTreeRoot(String traceUniqueId) {
107 if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) {
108 fTreeInstances.remove(traceUniqueId);
109 }
110 }
111
112 /**
113 * Remove all tree and root instances
114 */
115 public static void removeAll() {
116 fTreeInstances.clear();
117 }
118}
This page took 0.070704 seconds and 5 git commands to generate.