Class ELKIBuilder<T>

  • Type Parameters:
    T - Class to build.

    public final class ELKIBuilder<T>
    extends java.lang.Object
    Builder utility class.

    This class delegates to ListParameterization and ClassGenericsUtil, but may be easier to use in many cases.

    You will often need to specify the type T, because of nested generics. This is because of the way generics are implemented in Java, and we cannot easily resolve this; you have to give the type explicitly.

    Example: RStarTreeFactory<DoubleVector> indexfactory = new ELKIBuilder<RStarTreeFactory<DoubleVector>>(RStarTreeFactory.class) .with(AbstractPageFileFactory.Par.PAGE_SIZE_ID, 512) .with(RStarTreeFactory.Par.BULK_SPLIT_ID, SortTileRecursiveBulkSplit.class) .build(); with new ELKIBuilder<RStarTreeFactory<DoubleVector>> this code is fine, whereas new ELKIBuilder<> will cause an unchecked cast warning, because you are, in fact, casting a RStarTreeFactory (without generics) into a RStarTreeFactory<DoubleVector> here.

    Since:
    0.7.5
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<? super T> clazz
      Class to build.
      private static Logging LOG
      Class logger.
      private ListParameterization p
      Parameter list.
    • Constructor Summary

      Constructors 
      Constructor Description
      ELKIBuilder​(java.lang.Class<? super T> clazz)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <C extends T>
      C
      build()
      Instantiate, consuming the parameter list.
      ELKIBuilder<T> with​(OptionID opt)
      Add a flag to the builder.
      ELKIBuilder<T> with​(OptionID opt, java.lang.Object value)
      Add an option to the builder.
      ELKIBuilder<T> with​(java.lang.String opt)
      Add a flag to the builder.
      ELKIBuilder<T> with​(java.lang.String opt, java.lang.Object value)
      Add an option to the builder.
      • Methods inherited from class java.lang.Object

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

      • LOG

        private static final Logging LOG
        Class logger.
      • clazz

        private java.lang.Class<? super T> clazz
        Class to build.
    • Constructor Detail

      • ELKIBuilder

        public ELKIBuilder​(java.lang.Class<? super T> clazz)
        Constructor.

        You will often need to specify the type T, because of nested generics. This is because of the way generics are implemented in Java, and we cannot easily resolve this; you have to give the type explicitly.

        Example: RStarTreeFactory<DoubleVector> indexfactory = new ELKIBuilder<RStarTreeFactory<DoubleVector>>(RStarTreeFactory.class) .with(AbstractPageFileFactory.Par.PAGE_SIZE_ID, 512) .with(RStarTreeFactory.Par.BULK_SPLIT_ID, SortTileRecursiveBulkSplit.class) .build(); with new ELKIBuilder<RStarTreeFactory<DoubleVector>> this code is fine, whereas new ELKIBuilder<> will cause an unchecked cast warning, because you are, in fact, casting a RStarTreeFactory (without generics) into a RStarTreeFactory<DoubleVector> here.

        Parameters:
        clazz - Class
    • Method Detail

      • with

        public ELKIBuilder<T> with​(OptionID opt,
                                   java.lang.Object value)
        Add an option to the builder.
        Parameters:
        opt - Option ID (usually found in the Parameterizer class)
        value - Value
        Returns:
        The same builder
      • with

        public ELKIBuilder<T> with​(OptionID opt)
        Add a flag to the builder.
        Parameters:
        opt - Option ID (usually found in the Parameterizer class)
        Returns:
        The same builder
      • with

        public ELKIBuilder<T> with​(java.lang.String opt,
                                   java.lang.Object value)
        Add an option to the builder.
        Parameters:
        opt - Option ID (usually found in the Parameterizer class)
        value - Value
        Returns:
        The same builder
      • with

        public ELKIBuilder<T> with​(java.lang.String opt)
        Add a flag to the builder.
        Parameters:
        opt - Option ID (usually found in the Parameterizer class)
        Returns:
        The same builder
      • build

        public <C extends T> C build()
        Instantiate, consuming the parameter list.

        This will throw an AbortException if the parameters are incomplete, or build() is called twice.

        We lose some type safety here, for convenience. The type <C> is meant to be <T> with generics added only, which is necessary because generics are implemented by erasure in Java.

        Type Parameters:
        C - Output type
        Returns:
        Instance