Class AlgorithmFactory


  • public class AlgorithmFactory
    extends java.lang.Object
    Factory class used to register and retrieve algorithms based on their common ancestor and name.
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AlgorithmFactory

        public AlgorithmFactory()
    • 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.