1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 import com
.google
.common
.collect
.ImmutableSet
;
22 * A central repository for the available event types. Types are managed by
26 * @author Francois Chouinard
30 public final class TmfEventTypeManager
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
36 // The event type manager singleton
37 private static TmfEventTypeManager fEventTypeManager
= null;
39 // The available types, per context
40 private final Map
<String
, HashMap
<String
, ITmfEventType
>> fEventTypes
;
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
47 * The singleton constructor
49 private TmfEventTypeManager() {
50 fEventTypes
= new HashMap
<>();
54 * @return the TmfEventTypeManager singleton
56 public static synchronized TmfEventTypeManager
getInstance() {
57 if (fEventTypeManager
== null) {
58 fEventTypeManager
= new TmfEventTypeManager();
60 return fEventTypeManager
;
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
68 * Add a context:type pair to the available types
70 * @param context the target context
71 * @param type the type to add
73 public synchronized void add(final String context
, final ITmfEventType type
) {
74 HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
76 types
= new HashMap
<>();
78 types
.put(type
.getName(), type
);
79 fEventTypes
.put(context
, types
);
83 * Return the list of currently defined contexts
85 * @return the list of contexts
87 public synchronized String
[] getContexts() {
88 return fEventTypes
.keySet().toArray(new String
[fEventTypes
.size()]);
92 * Return the list of types defined for a given context
94 * @param context the context to look into
95 * @return the list of types defined for that context
98 public synchronized Set
<ITmfEventType
> getTypes(final String context
) {
99 final HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
101 return ImmutableSet
.copyOf(types
.values());
103 return ImmutableSet
.of();
107 * Return an event type
109 * @param context the context to look into
110 * @param typeId the type ID
111 * @return the corresponding type
113 public synchronized ITmfEventType
getType(final String context
, final String typeId
) {
114 final HashMap
<String
, ITmfEventType
> types
= fEventTypes
.get(context
);
116 return types
.get(typeId
);
122 * Remove the types associated to a context
124 * @param context the context to remove
126 public synchronized void clear(final String context
) {
127 fEventTypes
.remove(context
);
131 * Remove all contexts and types
133 public synchronized void clear() {
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 @SuppressWarnings("nls")
143 public String
toString() {
144 return "TmfEventTypeManager [fEventTypes=" + fEventTypes
+ "]";