Search in sources :

Example 1 with ClassInstantiationException

use of de.lmu.ifi.dbs.elki.utilities.exceptions.ClassInstantiationException in project elki by elki-project.

the class AbstractDistributionEstimatorTest method instantiate.

/**
 * This function is not strictly necessary, as all the estimators will have a
 * {@code STATIC} instance that we can use. But this way, we also cover the
 * parameterization API.
 *
 * We also verify the {@link DistributionEstimator#getDistributionClass()}
 * method here.
 *
 * @param cls Class
 * @param <D> Distribution
 * @param <T> Estimator class
 * @return Instance
 */
public static <D extends Distribution, T extends DistributionEstimator<D>> T instantiate(Class<T> cls, Class<D> dist) {
    try {
        T est = ClassGenericsUtil.tryInstantiate(cls, cls, new ListParameterization());
        assertEquals("Estimator has default toString.", -1, est.toString().indexOf('@'));
        assertEquals("Estimator returns unexpected distribution.", dist, est.getDistributionClass());
        return est;
    } catch (ClassInstantiationException e) {
        fail("Could not instantiate");
        return null;
    }
}
Also used : ClassInstantiationException(de.lmu.ifi.dbs.elki.utilities.exceptions.ClassInstantiationException) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)

Aggregations

ClassInstantiationException (de.lmu.ifi.dbs.elki.utilities.exceptions.ClassInstantiationException)1 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)1