use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class FileListParameter method parseValue.
@SuppressWarnings("unchecked")
@Override
protected List<File> parseValue(Object obj) throws ParameterException {
try {
List<?> l = List.class.cast(obj);
// do extra validation:
for (Object o : l) {
if (!(o instanceof File)) {
throw new WrongParameterValueException(this, obj.toString(), "expected a List<File> or a String.");
}
}
// TODO: can we use reflection to get extra checks?
return (List<File>) l;
} catch (ClassCastException e) {
// continue with others
}
if (obj instanceof String) {
String[] values = SPLIT.split((String) obj);
ArrayList<File> fileValue = new ArrayList<>(values.length);
for (String val : values) {
fileValue.add(new File(val));
}
return fileValue;
}
throw new WrongParameterValueException(this, obj.toString(), "expected a String containing file names.");
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class ObjectListParameter method instantiateClasses.
@Override
public List<C> instantiateClasses(Parameterization config) {
if (instances == null) {
// instantiateClasses will descend itself.
instances = super.instantiateClasses(config);
} else {
Parameterization cfg = null;
for (int i = 0; i < instances.size(); i++) {
if (instances.get(i) == null) {
Class<? extends C> cls = getValue().get(i);
try {
// Descend at most once, and only when needed
cfg = (cfg == null) ? config.descend(this) : null;
C instance = ClassGenericsUtil.tryInstantiate(restrictionClass, cls, cfg);
instances.set(i, instance);
} catch (Exception e) {
config.reportError(new WrongParameterValueException(this, cls.getName(), e.getMessage(), e));
}
}
}
}
return new ArrayList<>(instances);
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class ObjectListParameter method parseValue.
@SuppressWarnings("unchecked")
@Override
protected List<Class<? extends C>> parseValue(Object obj) throws ParameterException {
if (obj == null) {
throw new UnspecifiedParameterException(this);
}
if (List.class.isInstance(obj)) {
List<?> l = (List<?>) obj;
ArrayList<C> inst = new ArrayList<>(l.size());
ArrayList<Class<? extends C>> classes = new ArrayList<>(l.size());
for (Object o : l) {
// does the given objects class fit?
if (restrictionClass.isInstance(o)) {
inst.add((C) o);
classes.add((Class<? extends C>) o.getClass());
} else if (o instanceof Class) {
if (restrictionClass.isAssignableFrom((Class<?>) o)) {
inst.add(null);
classes.add((Class<? extends C>) o);
} else {
throw new WrongParameterValueException(this, ((Class<?>) o).getName(), "Given class not a subclass / implementation of " + restrictionClass.getName());
}
} else {
throw new WrongParameterValueException(this, o.getClass().getName(), "Given instance not an implementation of " + restrictionClass.getName());
}
}
this.instances = inst;
return super.parseValue(classes);
}
// Did we get a single instance?
try {
C inst = restrictionClass.cast(obj);
this.instances = Arrays.asList(inst);
return super.parseValue(inst.getClass());
} catch (ClassCastException e) {
// Continue
}
return super.parseValue(obj);
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class LoggingTabPanel method configureStep.
@Override
protected synchronized void configureStep(Parameterization config) {
StringParameter debugParam = //
new StringParameter(AbstractApplication.Parameterizer.DEBUG_ID).setOptional(true);
Flag verboseFlag = new Flag(AbstractApplication.Parameterizer.VERBOSE_ID);
// Verbose mode is a lot simpler
if (config.grab(verboseFlag) && verboseFlag.isTrue()) {
LoggingConfiguration.setVerbose(Level.VERBOSE);
}
// FIXME: add second level of verbosity!
if (config.grab(debugParam)) {
try {
AbstractApplication.Parameterizer.parseDebugParameter(debugParam);
} catch (WrongParameterValueException e) {
de.lmu.ifi.dbs.elki.logging.LoggingUtil.exception(e);
}
}
}
use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class ClassListParameter method instantiateClasses.
/**
* Returns a list of new instances for the value (i.e., the class name) of
* this class list parameter. The instances have the type of the restriction
* class of this class list parameter.
* <p/>
* If the Class for the class names is not found, the instantiation is tried
* using the package of the restriction class as package of the class name.
*
* @param config Parameterization to use (if Parameterizable))
* @return a list of new instances for the value of this class list parameter
*/
public List<C> instantiateClasses(Parameterization config) {
config = config.descend(this);
List<C> instances = new ArrayList<>();
if (getValue() == null) {
config.reportError(new UnspecifiedParameterException(this));
// empty list.
return instances;
}
for (Class<? extends C> cls : getValue()) {
// in sync!
try {
instances.add(ClassGenericsUtil.tryInstantiate(restrictionClass, cls, config));
} catch (Exception e) {
config.reportError(new WrongParameterValueException(this, cls.getName(), e.getMessage(), e));
}
}
return instances;
}
Aggregations