tmf: Update copyright headers in tmf.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / component / TmfProviderManager.java
CommitLineData
8c8bf09f 1/*******************************************************************************
61759503 2 * Copyright (c) 2009, 2012 Ericsson
6256d8ad 3 *
8c8bf09f
ASL
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
6256d8ad 8 *
8c8bf09f
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
8fd82db5 13package org.eclipse.linuxtools.internal.tmf.core.component;
8c8bf09f
ASL
14
15import java.util.ArrayList;
16import java.util.HashMap;
17import java.util.List;
18import java.util.Map;
19
8fd82db5 20import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
72f1e62a 21import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
8c8bf09f
ASL
22
23/**
8c8bf09f 24 * Singleton that keeps track of the event providers.
6256d8ad 25 *
8fd82db5
FC
26 * @version 1.0
27 * @author Francois Chouinard
8c8bf09f
ASL
28 */
29public class TmfProviderManager {
30
ff4ed569
FC
31 // ------------------------------------------------------------------------
32 // No constructor
33 // ------------------------------------------------------------------------
34
35 private TmfProviderManager() {}
6256d8ad 36
8c8bf09f
ASL
37 // ------------------------------------------------------------------------
38 // Keeps track of the providers for each event type
39 // ------------------------------------------------------------------------
6256d8ad
AM
40
41 private static Map<Class<? extends ITmfEvent>, List<TmfDataProvider>> fProviders =
42 new HashMap<Class<? extends ITmfEvent>, List<TmfDataProvider>>();
8c8bf09f
ASL
43
44 /**
45 * Registers [provider] as a provider of [eventType]
9b749023
AM
46 *
47 * @param eventType The event type
48 * @param provider The data provider
8c8bf09f 49 */
6256d8ad
AM
50 public static <T extends ITmfEvent> void register(Class<T> eventType, TmfDataProvider provider) {
51 if (fProviders.get(eventType) == null) {
52 fProviders.put(eventType, new ArrayList<TmfDataProvider>());
53 }
8c8bf09f
ASL
54 fProviders.get(eventType).add(provider);
55 }
56
57 /**
58 * Re-registers [provider] as a provider of [eventType]
9b749023
AM
59 *
60 * @param eventType The event type
61 * @param provider The data provider
8c8bf09f 62 */
6256d8ad
AM
63 public static <T extends ITmfEvent> void deregister(Class<T> eventType, TmfDataProvider provider) {
64 List<TmfDataProvider> list = fProviders.get(eventType);
8c8bf09f
ASL
65 if (list != null) {
66 list.remove(provider);
6256d8ad
AM
67 if (list.size() == 0) {
68 fProviders.remove(eventType);
69 }
8c8bf09f
ASL
70 }
71 }
72
73 /**
74 * Returns the list of components that provide [eventType]
9b749023
AM
75 *
76 * @param eventType The event type
0d9a6d76 77 * @return the list of components that provide [eventType]
8c8bf09f 78 */
6256d8ad
AM
79 public static TmfDataProvider[] getProviders(Class<? extends ITmfEvent> eventType) {
80 List<TmfDataProvider> list = fProviders.get(eventType);
81 if (list == null) {
82 list = new ArrayList<TmfDataProvider>();
83 }
84 TmfDataProvider[] result = new TmfDataProvider[list.size()];
8c8bf09f
ASL
85 return list.toArray(result);
86 }
87
88 /**
89 * Returns the list of components of type [providerType] that provide [eventType]
9b749023
AM
90 *
91 * @param eventType The event type
92 * @param providerType The data provider
0d9a6d76 93 * @return the list of components of type [providerType] that provide [eventType]
8c8bf09f 94 */
6256d8ad 95 public static TmfDataProvider[] getProviders(Class<? extends ITmfEvent> eventType, Class<? extends TmfDataProvider> providerType) {
0d9a6d76
FC
96 if (providerType == null) {
97 return getProviders(eventType);
fc6ccf6f 98 }
6256d8ad
AM
99 TmfDataProvider[] list = getProviders(eventType);
100 List<TmfDataProvider> result = new ArrayList<TmfDataProvider>();
8c8bf09f 101 if (list != null) {
6256d8ad 102 for (TmfDataProvider provider : list) {
0d9a6d76 103 if (provider.getClass() == providerType) {
8c8bf09f
ASL
104 result.add(provider);
105 }
106 }
107 }
6256d8ad 108 TmfDataProvider[] array = new TmfDataProvider[result.size()];
8c8bf09f
ASL
109 return result.toArray(array);
110 }
111
112}
This page took 0.04704 seconds and 5 git commands to generate.