Class AbstractFactory<T>

java.lang.Object
org.moeaframework.core.spi.AbstractFactory<T>
Type Parameters:
T - the generic type of the provider
All Implemented Interfaces:
Iterable<T>
Direct Known Subclasses:
AlgorithmFactory, OperatorFactory, ProblemFactory

public class AbstractFactory<T> extends Object implements Iterable<T>
Abstract factory for service providers. This contains convenience methods for enumerating the providers using a ServiceLoader along with explicit providers registered with addProvider(T).
  • Constructor Details

    • AbstractFactory

      public AbstractFactory(Class<T> type)
      Constructs a new factory for the given type.
      Parameters:
      type - the class of the provider
  • Method Details

    • addProvider

      public void addProvider(T provider)
      Adds a provider to this factory. Subsequent calls to enumerate the providers will include this provider.
      Parameters:
      provider - the new provider
    • iterator

      public Iterator<T> iterator()
      Returns an iterator of all registered providers.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      the iterator of all registered providers
    • hasProvider

      public boolean hasProvider(String name)
      Returns true if this factory contains a provider with the given name. This will match either the class' fully-qualified name or simple name.
      Parameters:
      name - the class name, either simple or including the package
      Returns:
      true if this factory contains the provider; false otherwise