1 /*******************************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.core
.event
;
15 import java
.util
.HashMap
;
19 * A central repository for the available event types. Types are managed by
23 * @author Francois Chouinard
27 public final class TmfEventTypeManager
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 // The event type manager singleton
34 private static TmfEventTypeManager fEventTypeManager
= null;
36 // The available types, per context
37 private final Map
<String
, HashMap
<String
, ITmfEventType
>> fEventTypes
;
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
44 * The singleton constructor
46 private TmfEventTypeManager() {
47 fEventTypes
= new HashMap
<String
, HashMap
<String
, ITmfEventType
>>();
51 * @return the TmfEventTypeManager singleton
53 public static synchronized TmfEventTypeManager
getInstance() {
54 if (fEventTypeManager
== null) {
55 fEventTypeManager
= new TmfEventTypeManager();
57 return fEventTypeManager
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Add a context:type pair to the available types
67 * @param context the target context
68 * @param type the type to add
70 public synchronized void add(final String context
, final ITmfEventType type
) {
71 HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
73 types
= new HashMap
<String
, ITmfEventType
>();
75 types
.put(type
.getName(), type
);
76 fEventTypes
.put(context
, types
);
80 * Return the list of currently defined contexts
82 * @return the list of contexts
84 public synchronized String
[] getContexts() {
85 return fEventTypes
.keySet().toArray(new String
[fEventTypes
.size()]);
89 * Return the list of types defined for a given context
91 * @param context the context to look into
92 * @return the list of types defined for that context
94 public synchronized ITmfEventType
[] getTypes(final String context
) {
95 final HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
97 return types
.values().toArray(new ITmfEventType
[types
.size()]);
99 return new ITmfEventType
[0];
103 * Return an event type
105 * @param context the context to look into
106 * @param typeId the type ID
107 * @return the corresponding type
109 public synchronized ITmfEventType
getType(final String context
, final String typeId
) {
110 final HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
112 return types
.get(typeId
);
118 * Remove the types associated to a context
120 * @param context the context to remove
122 public synchronized void clear(final String context
) {
123 fEventTypes
.remove(context
);
127 * Remove all contexts and types
129 public synchronized void clear() {
133 // ------------------------------------------------------------------------
135 // ------------------------------------------------------------------------
138 * @see java.lang.Object#toString()
141 @SuppressWarnings("nls")
142 public String
toString() {
143 return "TmfEventTypeManager [fEventTypes=" + fEventTypes
+ "]";