Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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 | * Yann N. Dauphin (dhaemon@gmail.com) - Implementation for stats | |
11 | *******************************************************************************/ | |
9dbeec54 | 12 | |
6e512b93 ASL |
13 | package org.eclipse.linuxtools.lttng.ui.views.statistics.model; |
14 | ||
15 | import java.util.HashMap; | |
16 | import java.util.Map; | |
17 | ||
18 | public class StatisticsTreeRootFactory { | |
9dbeec54 FC |
19 | |
20 | // ----------------------------------------------------------------------- | |
6e512b93 | 21 | // Data |
9dbeec54 | 22 | // ----------------------------------------------------------------------- |
6e512b93 | 23 | |
9dbeec54 | 24 | private static final Map<String, StatisticsData> fTreeInstances = new HashMap<String, StatisticsData>(); |
6e512b93 | 25 | |
9dbeec54 | 26 | // ----------------------------------------------------------------------- |
6e512b93 | 27 | // Methods |
9dbeec54 | 28 | // ----------------------------------------------------------------------- |
6e512b93 ASL |
29 | |
30 | /** | |
31 | * Provide a statisticsTree instance per trace | |
32 | * | |
33 | * @return | |
34 | */ | |
35 | public static StatisticsTreeNode getStatTreeRoot(String traceUniqueId) { | |
9dbeec54 FC |
36 | return getStatTree(traceUniqueId).getOrCreate(StatisticsData.ROOT); |
37 | } | |
38 | public static StatisticsData getStatTree(String traceUniqueId) { | |
39 | if(traceUniqueId == null) | |
6e512b93 | 40 | return null; |
6e512b93 | 41 | |
9dbeec54 FC |
42 | StatisticsData tree = fTreeInstances.get(traceUniqueId); |
43 | if(tree == null) { | |
44 | tree = new KernelStatisticsData(traceUniqueId); // NOTE | |
45 | fTreeInstances.put(traceUniqueId, tree); | |
46 | } | |
6e512b93 ASL |
47 | return tree; |
48 | } | |
6e512b93 ASL |
49 | /** |
50 | * @param traceUniqueId | |
51 | * @return | |
52 | */ | |
53 | public static boolean containsTreeRoot(String traceUniqueId) { | |
9dbeec54 | 54 | return fTreeInstances.containsKey(traceUniqueId); |
6e512b93 ASL |
55 | } |
56 | ||
57 | /** | |
58 | * Remove previously registered statistics tree. | |
59 | * @param traceUniqueId | |
60 | */ | |
61 | public static void removeStatTreeRoot(String traceUniqueId) { | |
9dbeec54 FC |
62 | if (traceUniqueId != null && fTreeInstances.containsKey(traceUniqueId)) { |
63 | fTreeInstances.remove(traceUniqueId); | |
6e512b93 ASL |
64 | } |
65 | } | |
66 | ||
67 | /** | |
9dbeec54 | 68 | * Remove all tree and root instances |
6e512b93 ASL |
69 | */ |
70 | public static void removeAll() { | |
9dbeec54 | 71 | fTreeInstances.clear(); |
6e512b93 ASL |
72 | } |
73 | } |