T
- Class to build.public final class ELKIBuilder<T>
extends java.lang.Object
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.Parameterizer.PAGE_SIZE_ID, 512)
.with(RStarTreeFactory.Parameterizer.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.Modifier and Type | Field and Description |
---|---|
private java.lang.Class<? super T> |
clazz
Class to build.
|
private static Logging |
LOG
Class logger.
|
private ListParameterization |
p
Parameter list.
|
Constructor and Description |
---|
ELKIBuilder(java.lang.Class<? super T> clazz)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
<C extends T> |
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.
|
private static final Logging LOG
private java.lang.Class<? super T> clazz
private ListParameterization p
public ELKIBuilder(java.lang.Class<? super T> clazz)
RStarTreeFactory<DoubleVector> indexfactory =
new ELKIBuilder<RStarTreeFactory<DoubleVector>>(RStarTreeFactory.class)
.with(AbstractPageFileFactory.Parameterizer.PAGE_SIZE_ID, 512)
.with(RStarTreeFactory.Parameterizer.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.clazz
- Classpublic ELKIBuilder<T> with(OptionID opt, java.lang.Object value)
opt
- Option ID (usually found in the Parameterizer class)value
- Valuepublic ELKIBuilder<T> with(OptionID opt)
opt
- Option ID (usually found in the Parameterizer class)public ELKIBuilder<T> with(java.lang.String opt, java.lang.Object value)
opt
- Option ID (usually found in the Parameterizer class)value
- Valuepublic ELKIBuilder<T> with(java.lang.String opt)
opt
- Option ID (usually found in the Parameterizer class)public <C extends T> C build()
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.C
- Output typeCopyright © 2019 ELKI Development Team. License information.