analysis: Clean up AlgorithmManager a bit
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 16 Oct 2015 01:34:38 +0000 (21:34 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 24 Nov 2015 20:36:14 +0000 (15:36 -0500)
Change-Id: I092a78d5899bd742acdd002290f67fab06c3126d
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/58290
Reviewed-by: Hudson CI
Reviewed-by: Francis Giraldeau <francis.giraldeau@gmail.com>
analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/criticalpath/AlgorithmManager.java

index 78504c0de59706f8415a3a757f55cbcdbf5a1ede..ed1a2575750b6b21294cfaa48f8898cb5157b6ba 100644 (file)
@@ -9,26 +9,35 @@
 
 package org.eclipse.tracecompass.internal.analysis.graph.core.criticalpath;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.analysis.graph.core.criticalpath.ICriticalPathAlgorithm;
 
 /**
- * Register algorithm
+ * A manager to provide a selection of critical path algorithms
+ *
+ * TODO: Investigate if there is already a facility in Eclipse to replace this
+ * class?
  *
- * FIXME: is there already a facility in Eclipse to replace this class?
  * @author Francis Giraldeau
  *
  */
 public final class AlgorithmManager {
 
-    private static @Nullable AlgorithmManager INSTANCE;
-    private final Map<String, Class<? extends ICriticalPathAlgorithm>> map;
+    private static final AlgorithmManager INSTANCE = new AlgorithmManager();
+    private final Map<String, Class<? extends ICriticalPathAlgorithm>> fMap;
+    private final Map<String, Class<? extends ICriticalPathAlgorithm>> fPublicMap;
+
+
+    static {
+        INSTANCE.register(CriticalPathAlgorithmBounded.class);
+    }
 
     private AlgorithmManager() {
-        map = new HashMap<>();
+        fMap = new HashMap<>();
+        fPublicMap = Collections.unmodifiableMap(fMap);
     }
 
     /**
@@ -37,30 +46,26 @@ public final class AlgorithmManager {
      * @return the instance
      */
     public static AlgorithmManager getInstance() {
-        AlgorithmManager manager = INSTANCE;
-        if (manager == null) {
-            manager = new AlgorithmManager();
-            manager.register(CriticalPathAlgorithmBounded.class);
-            INSTANCE = manager;
-        }
-        return manager;
+        return INSTANCE;
     }
 
     /**
-     * Register a type in the manager
+     * Register an algorithm in the manager
      *
-     * @param type the class to register
+     * @param type
+     *            the class of the algorithm to register
      */
     public void register(Class<? extends ICriticalPathAlgorithm> type) {
-        map.put(type.getSimpleName(), type);
+        fMap.put(type.getSimpleName(), type);
     }
 
     /**
-     * Return registered types
-     * @return the types
+     * Return registered algorithms
+     *
+     * @return an unmodifiable map of the algorithms.
      */
     public Map<String, Class<? extends ICriticalPathAlgorithm>> registeredTypes() {
-        return map;
+        return fPublicMap;
     }
 
 }
This page took 0.026428 seconds and 5 git commands to generate.