Commit | Line | Data |
---|---|---|
51480ca2 FG |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 École Polytechnique de Montréal | |
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 | ||
10 | package org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath; | |
11 | ||
12 | import java.util.HashMap; | |
13 | import java.util.Map; | |
14 | ||
15 | import org.eclipse.jdt.annotation.Nullable; | |
16 | import org.eclipse.tracecompass.analysis.graph.core.criticalpath.ICriticalPathAlgorithm; | |
17 | ||
18 | /** | |
19 | * Register algorithm | |
20 | * | |
21 | * FIXME: is there already a facility in Eclipse to replace this class? | |
22 | * @author Francis Giraldeau | |
23 | * | |
24 | */ | |
25 | public final class AlgorithmManager { | |
26 | ||
27 | private static @Nullable AlgorithmManager INSTANCE; | |
28 | private final Map<String, Class<? extends ICriticalPathAlgorithm>> map; | |
29 | ||
30 | private AlgorithmManager() { | |
31 | map = new HashMap<>(); | |
32 | } | |
33 | ||
34 | /** | |
35 | * Get the singleton instance | |
36 | * | |
37 | * @return the instance | |
38 | */ | |
39 | public static AlgorithmManager getInstance() { | |
40 | AlgorithmManager manager = INSTANCE; | |
41 | if (manager == null) { | |
42 | manager = new AlgorithmManager(); | |
43 | manager.register(CriticalPathAlgorithmBounded.class); | |
44 | INSTANCE = manager; | |
45 | } | |
46 | return manager; | |
47 | } | |
48 | ||
49 | /** | |
50 | * Register a type in the manager | |
51 | * | |
52 | * @param type the class to register | |
53 | */ | |
54 | public void register(Class<? extends ICriticalPathAlgorithm> type) { | |
55 | map.put(type.getSimpleName(), type); | |
56 | } | |
57 | ||
58 | /** | |
59 | * Return registered types | |
60 | * @return the types | |
61 | */ | |
62 | public Map<String, Class<? extends ICriticalPathAlgorithm>> registeredTypes() { | |
63 | return map; | |
64 | } | |
65 | ||
66 | } |