Package org.insa.graphs.algorithm
Class AlgorithmFactory
- java.lang.Object
-
- org.insa.graphs.algorithm.AlgorithmFactory
-
public class AlgorithmFactory extends java.lang.Object
Factory class used to register and retrieve algorithms based on their common ancestor and name.
-
-
Constructor Summary
Constructors Constructor Description AlgorithmFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AbstractAlgorithm<?>
createAlgorithm(java.lang.Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data)
Create an instance of the given algorithm class using the given input data.static java.lang.Class<? extends AbstractAlgorithm<?>>
getAlgorithmClass(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm, java.lang.String name)
Return the algorithm class corresponding to the given base algorithm class and name.static java.util.Set<java.lang.String>
getAlgorithmNames(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm)
Return the list of names corresponding to the registered algorithm classes for the given base algorithm class.static void
registerAlgorithm(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm, java.lang.String name, java.lang.Class<? extends AbstractAlgorithm<?>> algoClass)
Register the given algorithm class with the given name as a child class of the given base algorithm.
-
-
-
Method Detail
-
registerAlgorithm
public static void registerAlgorithm(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm, java.lang.String name, java.lang.Class<? extends AbstractAlgorithm<?>> algoClass)
Register the given algorithm class with the given name as a child class of the given base algorithm.- Parameters:
baseAlgorithm
- Base algorithm class that corresponds to the newly registered algorithm class (e.g., generic algorithm class for the problem).name
- Name for the registered algorithm class.algoClass
- Algorithm class to register.
-
createAlgorithm
public static AbstractAlgorithm<?> createAlgorithm(java.lang.Class<? extends AbstractAlgorithm<?>> algorithm, AbstractInputData data) throws java.lang.Exception
Create an instance of the given algorithm class using the given input data. Assuming algorithm correspond to a class "Algorithm", this function returns an object equivalent to `new Algorithm(data)`.- Parameters:
algorithm
- Class of the algorithm to create.data
- Input data for the algorithm.- Returns:
- A new instance of the given algorithm class using the given data.
- Throws:
java.lang.Exception
- if something wrong happens when constructing the object, i.e. the given input data does not correspond to the given algorithm and/or no constructor that takes a single parameter of type (data.getClass()) exists.
-
getAlgorithmClass
public static java.lang.Class<? extends AbstractAlgorithm<?>> getAlgorithmClass(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm, java.lang.String name)
Return the algorithm class corresponding to the given base algorithm class and name. The algorithm must have been previously registered using registerAlgorithm.- Parameters:
baseAlgorithm
- Base algorithm class for the algorithm to retrieve.name
- Name of the algorithm to retrieve.- Returns:
- Class corresponding to the given name.
- See Also:
registerAlgorithm(java.lang.Class<? extends org.insa.graphs.algorithm.AbstractAlgorithm<?>>, java.lang.String, java.lang.Class<? extends org.insa.graphs.algorithm.AbstractAlgorithm<?>>)
-
getAlgorithmNames
public static java.util.Set<java.lang.String> getAlgorithmNames(java.lang.Class<? extends AbstractAlgorithm<?>> baseAlgorithm)
Return the list of names corresponding to the registered algorithm classes for the given base algorithm class.- Parameters:
baseAlgorithm
- Base algorithm class for the algorithm class names to retrieve.- Returns:
- Names of the currently registered algorithms.
- See Also:
registerAlgorithm(java.lang.Class<? extends org.insa.graphs.algorithm.AbstractAlgorithm<?>>, java.lang.String, java.lang.Class<? extends org.insa.graphs.algorithm.AbstractAlgorithm<?>>)
-
-