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