Fix tabs/spaces for ITmfEvent
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEventTypeManager.java
CommitLineData
d06468c7
FC
1/*******************************************************************************
2 * Copyright (c) 2012 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.core.event;
14
15import java.util.HashMap;
16
4918b8f2 17
d06468c7
FC
18/**
19 * <b><u>TmfEventTypeManager</u></b>
20 * <p>
21 * The TmfEventTypeManager acts as a central repository for the available
4c564a2d 22 * event types. Types are managed in their context space.
d06468c7
FC
23 * <p>
24 */
25public final class TmfEventTypeManager {
26
27 // ------------------------------------------------------------------------
28 // Attributes
29 // ------------------------------------------------------------------------
30
31 // The event type manager singleton
32 private static TmfEventTypeManager fEventTypeManager = null;
33
34 // The available types, per context
085d898f 35 private final HashMap<String, HashMap<String, ITmfEventType>> fEventTypes;
d06468c7
FC
36
37 // ------------------------------------------------------------------------
38 // Constructors
39 // ------------------------------------------------------------------------
40
d7dbf09a
FC
41 /**
42 * The singleton constructor
43 */
d06468c7
FC
44 private TmfEventTypeManager() {
45 fEventTypes = new HashMap<String, HashMap<String, ITmfEventType>>();
46 }
47
d7dbf09a
FC
48 /**
49 * @return the TmfEventTypeManager singleton
50 */
d06468c7 51 public static synchronized TmfEventTypeManager getInstance() {
085d898f 52 if (fEventTypeManager == null)
d06468c7 53 fEventTypeManager = new TmfEventTypeManager();
d06468c7
FC
54 return fEventTypeManager;
55 }
56
57 // ------------------------------------------------------------------------
58 // Operations
59 // ------------------------------------------------------------------------
60
61 /**
62 * Add a context:type pair to the available types
63 *
64 * @param context the target context
65 * @param type the type to add
66 */
085d898f 67 public synchronized void add(final String context, final ITmfEventType type) {
d06468c7 68 HashMap<String, ITmfEventType> types = fEventTypes.get(context);
085d898f 69 if (types == null)
d06468c7 70 types = new HashMap<String, ITmfEventType>();
4c564a2d 71 types.put(type.getName(), type);
d06468c7
FC
72 fEventTypes.put(context, types);
73 }
74
75 /**
76 * Return the list of currently defined contexts
77 *
78 * @return the list of contexts
79 */
80 public synchronized String[] getContexts() {
81 return fEventTypes.keySet().toArray(new String[fEventTypes.size()]);
82 }
83
84 /**
85 * Return the list of types defined for a given context
86 *
87 * @param context the context to look into
88 * @return the list of types defined for that context
89 */
085d898f
FC
90 public synchronized ITmfEventType[] getTypes(final String context) {
91 final HashMap<String, ITmfEventType> types = fEventTypes.get(context);
92 if (types != null)
d06468c7 93 return types.values().toArray(new ITmfEventType[types.size()]);
d06468c7
FC
94 return null;
95 }
96
97 /**
98 * Return an event type
99 *
100 * @param context the context to look into
101 * @param typeId the type ID
102 * @return the corresponding type
103 */
085d898f
FC
104 public synchronized ITmfEventType getType(final String context, final String typeId) {
105 final HashMap<String, ITmfEventType> types = fEventTypes.get(context);
106 if (types != null)
d06468c7 107 return types.get(typeId);
d06468c7
FC
108 return null;
109 }
110
111 /**
112 * Remove the types associated to a context
113 *
114 * @param context the context to remove
115 */
085d898f 116 public synchronized void clear(final String context) {
d06468c7
FC
117 fEventTypes.remove(context);
118 }
119
120 /**
121 * Remove all contexts and types
122 */
123 public synchronized void clear() {
124 fEventTypes.clear();
125 }
126
127 // ------------------------------------------------------------------------
128 // Object
129 // ------------------------------------------------------------------------
130
d7dbf09a
FC
131 /* (non-Javadoc)
132 * @see java.lang.Object#toString()
133 */
d06468c7
FC
134 @Override
135 @SuppressWarnings("nls")
136 public String toString() {
137 return "TmfEventTypeManager [fEventTypes=" + fEventTypes + "]";
138 }
139
140}
This page took 0.043644 seconds and 5 git commands to generate.