diff options
author | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:30:32 +0000 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:30:32 +0000 |
commit | c36aa2a8fd31ca5e225ff30278e910070cd2c8c1 (patch) | |
tree | bdfe1a5ccb57999d4d664a2a44121a78c88b19d4 /src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java | |
parent | 89aa1958dbaf9052da0c24706308a2ef8cefa96e (diff) |
Import Upstream version 0.5.0~beta2
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java | 53 |
1 files changed, 20 insertions, 33 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java index 36abc0f7..6b056c03 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassParameter.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2011 + Copyright (C) 2012 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -24,15 +24,12 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; */ import java.lang.reflect.InvocationTargetException; +import java.util.List; import de.lmu.ifi.dbs.elki.logging.LoggingUtil; -import de.lmu.ifi.dbs.elki.properties.IterateKnownImplementations; -import de.lmu.ifi.dbs.elki.properties.Properties; import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; import de.lmu.ifi.dbs.elki.utilities.FormatUtil; import de.lmu.ifi.dbs.elki.utilities.InspectionUtil; -import de.lmu.ifi.dbs.elki.utilities.iterator.IterableIterator; -import de.lmu.ifi.dbs.elki.utilities.iterator.IterableUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; import de.lmu.ifi.dbs.elki.utilities.optionhandling.UnspecifiedParameterException; @@ -46,14 +43,21 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz * @author Steffi Wanka * @author Erich Schubert * - * @apiviz.uses Properties - * @apiviz.uses IterateKnownImplementations + * @apiviz.uses InspectionUtil * * @param <C> Class type */ // TODO: add additional constructors with parameter constraints. // TODO: turn restrictionClass into a constraint? public class ClassParameter<C> extends Parameter<Class<?>, Class<? extends C>> { + /** + * Class loader. + */ + protected static final ClassLoader loader = ClassLoader.getSystemClassLoader(); + + /** + * Factory class postfix. + */ public static final String FACTORY_POSTFIX = "$Factory"; /** @@ -133,26 +137,26 @@ public class ClassParameter<C> extends Parameter<Class<?>, Class<? extends C>> { try { // Try exact class factory first. try { - return (Class<? extends C>) Class.forName(value + FACTORY_POSTFIX); + return (Class<? extends C>) loader.loadClass(value + FACTORY_POSTFIX); } catch(ClassNotFoundException e) { // Ignore, retry } try { - return (Class<? extends C>) Class.forName(value); + return (Class<? extends C>) loader.loadClass(value); } catch(ClassNotFoundException e) { // Ignore, retry } // Try factory for guessed name next try { - return (Class<? extends C>) Class.forName(restrictionClass.getPackage().getName() + "." + value + FACTORY_POSTFIX); + return (Class<? extends C>) loader.loadClass(restrictionClass.getPackage().getName() + "." + value + FACTORY_POSTFIX); } catch(ClassNotFoundException e) { // Ignore, retry } // Last try: guessed name prefix only - return (Class<? extends C>) Class.forName(restrictionClass.getPackage().getName() + "." + value); + return (Class<? extends C>) loader.loadClass(restrictionClass.getPackage().getName() + "." + value); } catch(ClassNotFoundException e) { throw new WrongParameterValueException(this, value, "Given class \"" + value + "\" not found.", e); @@ -269,27 +273,10 @@ public class ClassParameter<C> extends Parameter<Class<?>, Class<? extends C>> { /** * Get an iterator over all known implementations of the class restriction. * - * @return {@link java.lang.Iterable Iterable} and {@link java.util.Iterator - * Iterator} object - */ - public IterableIterator<Class<?>> getKnownImplementations() { - if(InspectionUtil.NONSTATIC_CLASSPATH) { - return IterableUtil.fromIterable(InspectionUtil.cachedFindAllImplementations(getRestrictionClass())); - } - return new IterateKnownImplementations(getRestrictionClass()); - } - - /** - * Returns the class names allowed according to the restriction class of this - * class parameter. - * - * @return class names allowed according to the restriction class defined. + * @return List object */ - public String[] getRestrictionClasses() { - if(restrictionClass != null) { - return Properties.ELKI_PROPERTIES.getProperty(restrictionClass.getName()); - } - return new String[] {}; + public List<Class<?>> getKnownImplementations() { + return InspectionUtil.cachedFindAllImplementations(getRestrictionClass()); } /** @@ -310,8 +297,8 @@ public class ClassParameter<C> extends Parameter<Class<?>, Class<? extends C>> { info.append(restrictionClass.getName()); info.append(FormatUtil.NEWLINE); - IterableIterator<Class<?>> known = getKnownImplementations(); - if(known.hasNext()) { + List<Class<?>> known = getKnownImplementations(); + if(!known.isEmpty()) { info.append("Known classes (default package " + restrictionClass.getPackage().getName() + "):"); info.append(FormatUtil.NEWLINE); for(Class<?> c : known) { |