diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling')
28 files changed, 219 insertions, 284 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AllOrNoneMustBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AllOrNoneMustBeSetGlobalConstraint.java index a06a06c1..a87af1a8 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AllOrNoneMustBeSetGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AllOrNoneMustBeSetGlobalConstraint.java @@ -24,7 +24,6 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints; */ import java.util.ArrayList; -import java.util.List; import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; @@ -41,7 +40,7 @@ public class AllOrNoneMustBeSetGlobalConstraint implements GlobalParameterConstr /** * List of parameters to be checked */ - private List<Parameter<?>> parameterList; + private Parameter<?>[] parameterList; /** * Constructs a global parameter constraint for testing if either all elements @@ -49,7 +48,7 @@ public class AllOrNoneMustBeSetGlobalConstraint implements GlobalParameterConstr * * @param parameters list of parameters to be checked */ - public AllOrNoneMustBeSetGlobalConstraint(List<Parameter<?>> parameters) { + public AllOrNoneMustBeSetGlobalConstraint(Parameter<?>... parameters) { this.parameterList = parameters; } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.java new file mode 100644 index 00000000..ea1caed9 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.java @@ -0,0 +1,98 @@ +package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2013 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +import java.util.List; + +/** + * Class storing a number of very common constraints. + * + * @author Erich Schubert + */ +public final class CommonConstraints { + /** + * Integer constraint: >= -1 + */ + public static final ParameterConstraint<? super Integer> GREATER_EQUAL_MINUSONE_INT = new GreaterEqualConstraint(-1); + + /** + * Not negative. + */ + public static final ParameterConstraint<? super Integer> GREATER_EQUAL_ZERO_INT = new GreaterEqualConstraint(0); + + /** + * Larger than zero. + */ + public static final ParameterConstraint<? super Integer> GREATER_EQUAL_ONE_INT = new GreaterEqualConstraint(1); + + /** + * Larger than one. + */ + public static final ParameterConstraint<? super Integer> GREATER_THAN_ONE_INT = new GreaterConstraint(1); + + /** + * Not negative. + */ + public static final ParameterConstraint<? super Double> GREATER_EQUAL_ZERO_DOUBLE = new GreaterEqualConstraint(0.); + + /** + * Larger than zero. + */ + public static final ParameterConstraint<? super Double> GREATER_THAN_ZERO_DOUBLE = new GreaterConstraint(0.); + + /** + * Constraint: less than .5 + */ + public static final ParameterConstraint<? super Double> LESS_THAN_HALF_DOUBLE = new LessConstraint(.5); + + /** + * At least 1. + */ + public static final ParameterConstraint<? super Double> GREATER_EQUAL_ONE_DOUBLE = new GreaterEqualConstraint(1.); + + /** + * Larger than one. + */ + public static final ParameterConstraint<? super Double> GREATER_THAN_ONE_DOUBLE = new GreaterConstraint(1.); + + /** + * Less than one. + */ + public static final ParameterConstraint<? super Double> LESS_THAN_ONE_DOUBLE = new LessConstraint(1.); + + /** + * Less or equal than one. + */ + public static final ParameterConstraint<? super Double> LESS_EQUAL_ONE_DOUBLE = new LessEqualConstraint(1.); + + /** + * Constraint for the whole list. + */ + public static final ParameterConstraint<? super List<Integer>> GREATER_EQUAL_ZERO_INT_LIST = new ListEachConstraint<>(GREATER_EQUAL_ZERO_INT); + + /** + * List constraint: >= 1 + */ + public static final ParameterConstraint<? super List<Integer>> GREATER_EQUAL_ONE_INT_LIST = new ListEachConstraint<>(GREATER_EQUAL_ONE_INT); +} diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualSizeGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualSizeGlobalConstraint.java index 2ee7be9c..586b4257 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualSizeGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualSizeGlobalConstraint.java @@ -23,8 +23,6 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints; along with this program. If not, see <http://www.gnu.org/licenses/>. */ -import java.util.List; - import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; @@ -41,7 +39,7 @@ public class EqualSizeGlobalConstraint implements GlobalParameterConstraint { /** * List parameters to be tested */ - private List<ListParameter<?>> parameters; + private ListParameter<?, ?>[] parameters; /** * Creates a global parameter constraint for testing if a number of list @@ -49,7 +47,7 @@ public class EqualSizeGlobalConstraint implements GlobalParameterConstraint { * * @param params list parameters to be tested for equal list sizes */ - public EqualSizeGlobalConstraint(List<ListParameter<?>> params) { + public EqualSizeGlobalConstraint(ListParameter<?, ?>... params) { this.parameters = params; } @@ -63,7 +61,7 @@ public class EqualSizeGlobalConstraint implements GlobalParameterConstraint { boolean first = false; int constraintSize = -1; - for(ListParameter<?> listParam : parameters) { + for(ListParameter<?, ?> listParam : parameters) { if(listParam.isDefined()) { if(!first) { constraintSize = listParam.getListSize(); diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalListSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalListSizeConstraint.java index bcedd342..7c35045e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalListSizeConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalListSizeConstraint.java @@ -39,7 +39,7 @@ public class GlobalListSizeConstraint implements GlobalParameterConstraint { /** * List parameter to be tested. */ - private ListParameter<?> list; + private ListParameter<?, ?> list; /** * Integer parameter specifying the constraint list size. @@ -55,7 +55,7 @@ public class GlobalListSizeConstraint implements GlobalParameterConstraint { * @param v the list parameter to be tested. * @param i integer parameter specifying the constraint list size. */ - public GlobalListSizeConstraint(ListParameter<?> v, IntParameter i) { + public GlobalListSizeConstraint(ListParameter<?, ?> v, IntParameter i) { this.list = v; this.length = i; } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualGlobalConstraint.java index 1216e03b..9fa0ee99 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualGlobalConstraint.java @@ -39,12 +39,12 @@ public class LessEqualGlobalConstraint<T extends Number> implements GlobalParame /** * First number parameter. */ - private NumberParameter<T> first; + private NumberParameter<?, T> first; /** * Second number parameter. */ - private NumberParameter<T> second; + private NumberParameter<?, T> second; /** * Creates a Less-Equal-Than global parameter constraint. @@ -55,7 +55,7 @@ public class LessEqualGlobalConstraint<T extends Number> implements GlobalParame * @param first first number parameter * @param second second number parameter */ - public LessEqualGlobalConstraint(NumberParameter<T> first, NumberParameter<T> second) { + public LessEqualGlobalConstraint(NumberParameter<?, T> first, NumberParameter<?, T> second) { this.first = first; this.second = second; } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessGlobalConstraint.java index a722edab..989f6e29 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessGlobalConstraint.java @@ -39,12 +39,12 @@ public class LessGlobalConstraint<T extends Number> implements GlobalParameterCo /** * First number parameter. */ - private NumberParameter<T> first; + private NumberParameter<?, T> first; /** * Second number parameter. */ - private NumberParameter<T> second; + private NumberParameter<?, T> second; /** * Creates a Less-Than global parameter constraint. That is the value of the @@ -54,7 +54,7 @@ public class LessGlobalConstraint<T extends Number> implements GlobalParameterCo * @param first first number parameter * @param second second number parameter */ - public LessGlobalConstraint(NumberParameter<T> first, NumberParameter<T> second) { + public LessGlobalConstraint(NumberParameter<?, T> first, NumberParameter<?, T> second) { this.first = first; this.second = second; } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/NoDuplicateValueGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/NoDuplicateValueGlobalConstraint.java index 65b427a1..7036ecef 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/NoDuplicateValueGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/NoDuplicateValueGlobalConstraint.java @@ -45,7 +45,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai /** * List of number parameters to be checked. */ - private List<? extends AbstractParameter<?>> parameters; + private List<? extends AbstractParameter<?, ?>> parameters; /** * Constructs a Not-Equal-Value global parameter constraint. That is, the @@ -54,7 +54,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai * * @param parameters list of number parameters to be tested */ - public NoDuplicateValueGlobalConstraint(List<? extends AbstractParameter<?>> parameters) { + public NoDuplicateValueGlobalConstraint(List<? extends AbstractParameter<?, ?>> parameters) { this.parameters = parameters; } @@ -65,7 +65,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai * * @param parameters list of number parameters to be tested */ - public NoDuplicateValueGlobalConstraint(AbstractParameter<?>... parameters) { + public NoDuplicateValueGlobalConstraint(AbstractParameter<?, ?>... parameters) { this.parameters = Arrays.asList(parameters); } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java index e4c5489b..d2106865 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java @@ -15,7 +15,7 @@ * "Distance function to determine the distance between database objects." * ); * }</pre></blockquote> - * (This example is from {@link de.lmu.ifi.dbs.elki.algorithm.AbstractDistanceBasedAlgorithm DistanceBasedAlgorithm}.) + * (This example is from {@link de.lmu.ifi.dbs.elki.algorithm.AbstractDistanceBasedAlgorithm AbstractDistanceBasedAlgorithm}.) * </li> * * <li><b>Parameter Object</b>: To obtain a value, you <em>must</em> use a diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/AbstractParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/AbstractParameter.java index 8e1b48c3..cdad8583 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/AbstractParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/AbstractParameter.java @@ -25,7 +25,6 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; import java.security.InvalidParameterException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import de.lmu.ifi.dbs.elki.logging.LoggingUtil; @@ -49,9 +48,10 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @apiviz.composedOf OptionID * @apiviz.uses ParameterConstraint * + * @param <THIS> type self-reference * @param <T> the type of a possible value (i.e., the type of the option) */ -public abstract class AbstractParameter<T> implements Parameter<T> { +public abstract class AbstractParameter<THIS extends AbstractParameter<THIS, T>, T> implements Parameter<T> { /** * The default value of the parameter (may be null). */ @@ -152,20 +152,24 @@ public abstract class AbstractParameter<T> implements Parameter<T> { @Override public boolean tryDefaultValue() throws UnspecifiedParameterException { // Assume default value instead. - if (hasDefaultValue()) { + if(hasDefaultValue()) { useDefaultValue(); return true; - } else if (isOptional()) { + } + else if(isOptional()) { // Optional is fine, but not successful return false; - } else { + } + else { throw new UnspecifiedParameterException(this); } } + @SuppressWarnings("unchecked") @Override - public void setOptional(boolean opt) { + public THIS setOptional(boolean opt) { this.optionalParameter = opt; + return (THIS) this; } @Override @@ -204,31 +208,32 @@ public abstract class AbstractParameter<T> implements Parameter<T> { // description.append(getParameterType()).append(" "); description.append(shortDescription); description.append(FormatUtil.NEWLINE); - if (hasValuesDescription()) { + if(hasValuesDescription()) { final String valuesDescription = getValuesDescription(); description.append(valuesDescription); - if (!valuesDescription.endsWith(FormatUtil.NEWLINE)) { + if(!valuesDescription.endsWith(FormatUtil.NEWLINE)) { description.append(FormatUtil.NEWLINE); } } - if (hasDefaultValue()) { + if(hasDefaultValue()) { description.append("Default: "); description.append(getDefaultValueAsString()); description.append(FormatUtil.NEWLINE); } - if (constraints != null && !constraints.isEmpty()) { - if (constraints.size() == 1) { + if(constraints != null && !constraints.isEmpty()) { + if(constraints.size() == 1) { description.append("Constraint: "); - } else if (constraints.size() > 1) { + } + else if(constraints.size() > 1) { description.append("Constraints: "); } - for (int i = 0; i < constraints.size(); i++) { + for(int i = 0; i < constraints.size(); i++) { ParameterConstraint<? super T> constraint = constraints.get(i); - if (i > 0) { + if(i > 0) { description.append(", "); } description.append(constraint.getDescription(getName())); - if (i == constraints.size() - 1) { + if(i == constraints.size() - 1) { description.append('.'); } } @@ -245,8 +250,8 @@ public abstract class AbstractParameter<T> implements Parameter<T> { * @throws ParameterException when the object is not valid. */ protected boolean validate(T obj) throws ParameterException { - if (constraints != null) { - for (ParameterConstraint<? super T> cons : this.constraints) { + if(constraints != null) { + for(ParameterConstraint<? super T> cons : this.constraints) { cons.test(obj); } } @@ -276,9 +281,10 @@ public abstract class AbstractParameter<T> implements Parameter<T> { @Override public void setValue(Object obj) throws ParameterException { T val = parseValue(obj); - if (validate(val)) { + if(validate(val)) { setValueInternal(val); - } else { + } + else { throw new InvalidParameterException("Value for option \"" + getName() + "\" did not validate: " + obj.toString()); } } @@ -294,7 +300,7 @@ public abstract class AbstractParameter<T> implements Parameter<T> { @Override public final T getValue() { - if (this.value == null) { + if(this.value == null) { LoggingUtil.warning("Programming error: Parameter#getValue() called for unset parameter \"" + this.optionid.getName() + "\"", new Throwable()); } return this.value; @@ -331,23 +337,13 @@ public abstract class AbstractParameter<T> implements Parameter<T> { return getDefaultValue().toString(); } + @SuppressWarnings("unchecked") @Override - public void addConstraint(ParameterConstraint<? super T> constraint) { - if (constraints == null) { + public THIS addConstraint(ParameterConstraint<? super T> constraint) { + if(constraints == null) { this.constraints = new ArrayList<>(1); } constraints.add(constraint); - } - - /** - * Add a collection of constraints. - * - * @param cs Constraints to add - */ - public void addConstraints(Collection<? extends ParameterConstraint<? super T>> cs) { - if (constraints == null) { - this.constraints = new ArrayList<>(cs.size()); - } - constraints.addAll(cs); + return (THIS) this; } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassListParameter.java index 35cd0573..1cea7fac 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ClassListParameter.java @@ -46,7 +46,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz * @param <C> Class type */ // TODO: Add missing constructors. (ObjectListParameter also!) -public class ClassListParameter<C> extends ListParameter<Class<? extends C>> { +public class ClassListParameter<C> extends ListParameter<ClassListParameter<C>, Class<? extends C>> { /** * The restriction class for the list of class names. */ 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 a0669fca..42288738 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 @@ -49,7 +49,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz */ // TODO: add additional constructors with parameter constraints. // TODO: turn restrictionClass into a constraint? -public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { +public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>, Class<? extends C>> { /** * The restriction class for this class parameter. */ @@ -73,7 +73,7 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { // * ClassParameter<Foo<Bar>>(optionID, (Class<Foo<Bar>>) Foo.class) is an // invalid cast. this.restrictionClass = (Class<C>) restrictionClass; - if (restrictionClass == null) { + if(restrictionClass == null) { LoggingUtil.warning("Restriction class 'null' for parameter '" + optionID + "'", new Throwable()); } } @@ -96,7 +96,7 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { // * ClassParameter<Foo<Bar>>(optionID, (Class<Foo<Bar>>) Foo.class) is an // invalid cast. this.restrictionClass = (Class<C>) restrictionClass; - if (restrictionClass == null) { + if(restrictionClass == null) { LoggingUtil.warning("Restriction class 'null' for parameter '" + optionID + "'", new Throwable()); } } @@ -115,15 +115,15 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { @SuppressWarnings("unchecked") @Override protected Class<? extends C> parseValue(Object obj) throws ParameterException { - if (obj == null) { + if(obj == null) { throw new UnspecifiedParameterException(this); } - if (obj instanceof Class<?>) { + if(obj instanceof Class<?>) { return (Class<? extends C>) obj; } - if (obj instanceof String) { + if(obj instanceof String) { Class<? extends C> clz = InspectionUtil.findImplementation(restrictionClass, (String) obj); - if (clz != null) { + if(clz != null) { return clz; } } @@ -136,13 +136,13 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { */ @Override public boolean validate(Class<? extends C> obj) throws ParameterException { - if (obj == null) { + if(obj == null) { throw new UnspecifiedParameterException(this); } - if (!restrictionClass.isAssignableFrom(obj)) { + if(!restrictionClass.isAssignableFrom(obj)) { throw new WrongParameterValueException(this, obj.getName(), "Given class not a subclass / implementation of " + restrictionClass.getName()); } - if (!super.validate(obj)) { + if(!super.validate(obj)) { return false; } return true; @@ -175,7 +175,7 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { */ @Override public String getValuesDescription() { - if (restrictionClass != null && restrictionClass != Object.class) { + if(restrictionClass != null && restrictionClass != Object.class) { return restrictionString(); } return ""; @@ -199,22 +199,26 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { */ public C instantiateClass(Parameterization config) { try { - if (getValue() == null /* && !optionalParameter */) { + if(getValue() == null /* && !optionalParameter */) { throw new UnusedParameterException("Value of parameter " + getName() + " has not been specified."); } C instance; try { config = config.descend(this); instance = ClassGenericsUtil.tryInstantiate(restrictionClass, getValue(), config); - } catch (InvocationTargetException e) { + } + catch(InvocationTargetException e) { throw new WrongParameterValueException(this, getValue().getCanonicalName(), "Error instantiating class.", e); - } catch (NoSuchMethodException e) { + } + catch(NoSuchMethodException e) { throw new WrongParameterValueException(this, getValue().getCanonicalName(), "Error instantiating class - no usable public constructor."); - } catch (Exception e) { + } + catch(Exception e) { throw new WrongParameterValueException(this, getValue().getCanonicalName(), "Error instantiating class.", e); } return instance; - } catch (ParameterException e) { + } + catch(ParameterException e) { config.reportError(e); return null; } @@ -247,19 +251,20 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { */ public String restrictionString() { StringBuilder info = new StringBuilder(); - if (restrictionClass.isInterface()) { + if(restrictionClass.isInterface()) { info.append("Implementing "); - } else { + } + else { info.append("Extending "); } info.append(restrictionClass.getName()); info.append(FormatUtil.NEWLINE); List<Class<?>> known = getKnownImplementations(); - if (!known.isEmpty()) { + if(!known.isEmpty()) { info.append("Known classes (default package " + restrictionClass.getPackage().getName() + "):"); info.append(FormatUtil.NEWLINE); - for (Class<?> c : known) { + for(Class<?> c : known) { info.append("->" + FormatUtil.NONBREAKING_SPACE); info.append(canonicalClassName(c, getRestrictionClass())); info.append(FormatUtil.NEWLINE); @@ -279,13 +284,13 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { */ public static String canonicalClassName(Class<?> c, Package pkg, String postfix) { String name = c.getName(); - if (pkg != null) { + if(pkg != null) { String prefix = pkg.getName() + "."; - if (name.startsWith(prefix)) { + if(name.startsWith(prefix)) { name = name.substring(prefix.length()); } } - if (postfix != null && name.endsWith(postfix)) { + if(postfix != null && name.endsWith(postfix)) { name = name.substring(0, name.length() - postfix.length()); } return name; @@ -299,7 +304,7 @@ public class ClassParameter<C> extends AbstractParameter<Class<? extends C>> { * @return Simplified class name. */ public static String canonicalClassName(Class<?> c, Class<?> parent) { - if (parent == null) { + if(parent == null) { return canonicalClassName(c, null, InspectionUtil.FACTORY_POSTFIX); } return canonicalClassName(c, parent.getPackage(), InspectionUtil.FACTORY_POSTFIX); diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DistanceParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DistanceParameter.java index e97b6d0e..eda54082 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DistanceParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DistanceParameter.java @@ -36,7 +36,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * * @param <D> Distance type */ -public class DistanceParameter<D extends Distance<D>> extends AbstractParameter<D> { +public class DistanceParameter<D extends Distance<D>> extends AbstractParameter<DistanceParameter<D>, D> { /** * Distance type */ diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java index 89cfc345..84f97734 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java @@ -37,7 +37,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Steffi Wanka * @author Erich Schubert */ -public class DoubleListParameter extends ListParameter<Double> { +public class DoubleListParameter extends ListParameter<DoubleListParameter, Double> { /** * Constructs a list parameter with the given optionID and optional flag. * @@ -83,7 +83,7 @@ public class DoubleListParameter extends ListParameter<Double> { String[] values = SPLIT.split((String) obj); ArrayList<Double> doubleValue = new ArrayList<>(values.length); for(String val : values) { - doubleValue.add(Double.valueOf(val)); + doubleValue.add(FormatUtil.parseDouble(val)); } return doubleValue; } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleParameter.java index 632e1f8c..efa64370 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleParameter.java @@ -23,9 +23,9 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import de.lmu.ifi.dbs.elki.utilities.FormatUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstraint; /** * Parameter class for a parameter specifying a double value. @@ -33,36 +33,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class DoubleParameter extends NumberParameter<Double> { - /** - * Constructs a double parameter with the given optionID, parameter - * constraint, and default value. - * - * @param optionID the unique id of this parameter - * @param defaultValue the default value for this parameter - * @param constraint the constraint of this parameter - * @deprecated Use {@link #addConstraint} instead. - */ - @Deprecated - public DoubleParameter(OptionID optionID, double defaultValue, ParameterConstraint<Number> constraint) { - super(optionID, defaultValue); - addConstraint(constraint); - } - - /** - * Constructs a double parameter with the given optionID, and parameter - * constraint. - * - * @param optionID the unique id of this parameter - * @param constraint the constraint of this parameter - * @deprecated Use {@link #addConstraint} instead. - */ - @Deprecated - public DoubleParameter(OptionID optionID, ParameterConstraint<Number> constraint) { - super(optionID); - addConstraint(constraint); - } - +public class DoubleParameter extends NumberParameter<DoubleParameter, Double> { /** * Constructs a double parameter with the given optionID and default value. * @@ -74,20 +45,6 @@ public class DoubleParameter extends NumberParameter<Double> { } /** - * Constructs a double parameter with the given optionID and default value. - * - * @param optionID the unique optionID - * @param optional Flag to indicate that the parameter is optional - * - * @deprecated Use {@link #setOptional} instead. - */ - @Deprecated - public DoubleParameter(OptionID optionID, boolean optional) { - super(optionID); - setOptional(optional); - } - - /** * Constructs a double parameter with the given optionID. * * @param optionID the unique id of this parameter @@ -103,14 +60,16 @@ public class DoubleParameter extends NumberParameter<Double> { @Override protected Double parseValue(Object obj) throws WrongParameterValueException { - if (obj instanceof Double) { + if(obj instanceof Double) { return (Double) obj; } try { - return Double.valueOf(obj.toString()); - } catch (NullPointerException e) { + return FormatUtil.parseDouble(obj.toString()); + } + catch(NullPointerException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a double value, read: " + obj + "!\n"); - } catch (NumberFormatException e) { + } + catch(NumberFormatException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a double value, read: " + obj + "!\n"); } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/EnumParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/EnumParameter.java index 4d05753c..22d7dd54 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/EnumParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/EnumParameter.java @@ -62,7 +62,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException *
* @param <E> Enum type
*/
-public class EnumParameter<E extends Enum<E>> extends AbstractParameter<E> {
+public class EnumParameter<E extends Enum<E>> extends AbstractParameter<EnumParameter<E>, E> {
/**
* Reference to the actual enum type, for T.valueOf().
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileListParameter.java index eb638298..9e115dc7 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileListParameter.java @@ -38,7 +38,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Steffi Wanka * @author Erich Schubert */ -public class FileListParameter extends ListParameter<File> { +public class FileListParameter extends ListParameter<FileListParameter, File> { /** * Available types of the files: {@link #INPUT_FILES} denotes input files, * {@link #OUTPUT_FILES} denotes output files. diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileParameter.java index ea3fa454..3e9fdc7d 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/FileParameter.java @@ -38,7 +38,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Erich Schubert */ // TODO: turn FileType into a Constraint? -public class FileParameter extends AbstractParameter<File> { +public class FileParameter extends AbstractParameter<FileParameter, File> { /** * Available file types: {@link #INPUT_FILE} denotes an input file, * {@link #OUTPUT_FILE} denotes an output file. diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Flag.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Flag.java index 7587d2a5..f9e1a1f1 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Flag.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Flag.java @@ -37,7 +37,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Steffi Wanka * @author Erich Schubert */ -public class Flag extends AbstractParameter<Boolean> { +public class Flag extends AbstractParameter<Flag, Boolean> { /** * Constant indicating that the flag is set. */ diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntListParameter.java index 93012955..cc8327b4 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntListParameter.java @@ -37,7 +37,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Elke Achtert * @author Erich Schubert */ -public class IntListParameter extends ListParameter<Integer> { +public class IntListParameter extends ListParameter<IntListParameter, Integer> { /** * Constructs an integer list parameter * diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntParameter.java index 30457330..3d867770 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/IntParameter.java @@ -23,10 +23,10 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import de.lmu.ifi.dbs.elki.utilities.FormatUtil; 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.WrongParameterValueException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstraint; /** * Parameter class for a parameter specifying an integer value. @@ -34,51 +34,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class IntParameter extends NumberParameter<Integer> { - /** - * Constructs an integer parameter with the given optionID, parameter - * constraint, and default value. - * - * @param optionID optionID the unique id of the option - * @param defaultValue the default value - * @param constraint the constraint for this integer parameter - * @deprecated Use {@link #addConstraint} instead. - */ - @Deprecated - public IntParameter(OptionID optionID, int defaultValue, ParameterConstraint<Number> constraint) { - super(optionID, Integer.valueOf(defaultValue)); - addConstraint(constraint); - } - - /** - * Constructs an integer parameter with the given optionID, parameter - * constraint, and optional flag. - * - * @param optionID optionID the unique id of the option - * @param constraint the constraint for this integer parameter - * @param optional specifies if this parameter is an optional parameter - * @deprecated Use {@link #addConstraint} instead. - */ - @Deprecated - public IntParameter(OptionID optionID, ParameterConstraint<Number> constraint, boolean optional) { - super(optionID, optional); - addConstraint(constraint); - } - - /** - * Constructs an integer parameter with the given optionID, and parameter - * constraint. - * - * @param optionID optionID the unique id of the option - * @param constraint the constraint for this integer parameter - * @deprecated Use {@link #addConstraint} instead. - */ - @Deprecated - public IntParameter(OptionID optionID, ParameterConstraint<Number> constraint) { - super(optionID); - addConstraint(constraint); - } - +public class IntParameter extends NumberParameter<IntParameter, Integer> { /** * Constructs an integer parameter with the given optionID. * @@ -93,18 +49,6 @@ public class IntParameter extends NumberParameter<Integer> { * Constructs an integer parameter with the given optionID. * * @param optionID optionID the unique id of the option - * @param optional specifies if this parameter is an optional parameter - * @deprecated Use {@link #setOptional} instead. - */ - @Deprecated - public IntParameter(OptionID optionID, boolean optional) { - super(optionID, optional); - } - - /** - * Constructs an integer parameter with the given optionID. - * - * @param optionID optionID the unique id of the option */ public IntParameter(OptionID optionID) { super(optionID); @@ -117,14 +61,17 @@ public class IntParameter extends NumberParameter<Integer> { @Override protected Integer parseValue(Object obj) throws ParameterException { - if (obj instanceof Integer) { + if(obj instanceof Integer) { return (Integer) obj; } try { - return Integer.valueOf(obj.toString()); - } catch (NullPointerException e) { + final String s = obj.toString(); + return (int) FormatUtil.parseLongBase10(s, 0, s.length()); + } + catch(NullPointerException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires an integer value, read: " + obj + "!\n"); - } catch (NumberFormatException e) { + } + catch(NumberFormatException e) { throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires an integer value, read: " + obj + "!\n"); } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ListParameter.java index 119fb121..df520daa 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ListParameter.java @@ -34,9 +34,10 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; * @author Steffi Wanka * @author Erich Schubert * + * @param <THIS> Type self-reference * @param <T> List type */ -public abstract class ListParameter<T> extends AbstractParameter<List<T>> { +public abstract class ListParameter<THIS extends ListParameter<THIS, T>, T> extends AbstractParameter<THIS, List<T>> { /** * A pattern defining a ",". */ diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/LongParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/LongParameter.java index f5d441b5..5ab6b487 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/LongParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/LongParameter.java @@ -26,7 +26,6 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; 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.WrongParameterValueException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstraint; /** * Parameter class for a parameter specifying a long value. @@ -34,22 +33,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class LongParameter extends NumberParameter<Long> { - /** - * Constructs a long parameter with the given optionID, parameter constraint - * and default value. - * - * @param optionID the unique OptionID for this parameter - * @param constraint the parameter constraint for this long parameter - * @param defaultValue the default value - * @deprecated Use {@link #addConstraint} instead! - */ - @Deprecated - public LongParameter(OptionID optionID, ParameterConstraint<Number> constraint, long defaultValue) { - super(optionID, Long.valueOf(defaultValue)); - addConstraint(constraint); - } - +public class LongParameter extends NumberParameter<LongParameter, Long> { /** * Constructs a long parameter with the given optionID and default value. * @@ -68,7 +52,7 @@ public class LongParameter extends NumberParameter<Long> { public LongParameter(OptionID optionID) { super(optionID); } - + @Override public String getValueAsString() { return getValue().toString(); diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/NumberParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/NumberParameter.java index a4448d30..fabdce53 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/NumberParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/NumberParameter.java @@ -30,10 +30,11 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; * * @author Steffi Wanka * @author Erich Schubert - * + * + * @param <THIS> type self-reference * @param <T> the type of a possible value (i.e., the type of the option) */ -public abstract class NumberParameter<T extends Number> extends AbstractParameter<T> { +public abstract class NumberParameter<THIS extends NumberParameter<THIS, T>, T extends Number> extends AbstractParameter<THIS, T> { /** * Constructs a number parameter with the given optionID and default Value. * diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Parameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Parameter.java index 110633b3..ffacb6d1 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Parameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/Parameter.java @@ -80,8 +80,9 @@ public interface Parameter<T> { * Specifies if this parameter is an optional parameter. * * @param opt true if this parameter is optional, false otherwise + * @return the parameter itself, for chaining */ - public abstract void setOptional(boolean opt); + public abstract Parameter<T> setOptional(boolean opt); /** * Checks if this parameter is an optional parameter. @@ -232,6 +233,7 @@ public interface Parameter<T> { * Add an additional constraint. * * @param constraint Constraint to add. + * @return the parameter itself, for chaining */ - public abstract void addConstraint(ParameterConstraint<? super T> constraint); + public abstract Parameter<T> addConstraint(ParameterConstraint<? super T> constraint); } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/PatternParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/PatternParameter.java index b76edbbb..e3cb4bcf 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/PatternParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/PatternParameter.java @@ -37,7 +37,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Steffi Wanka * @author Erich Schubert */ -public class PatternParameter extends AbstractParameter<Pattern> { +public class PatternParameter extends AbstractParameter<PatternParameter, Pattern> { /** * Constructs a pattern parameter with the given optionID, and default value. * diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/RandomParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/RandomParameter.java index 6c0668dd..bf5e0cb0 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/RandomParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/RandomParameter.java @@ -33,7 +33,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * * @author Erich Schubert */ -public class RandomParameter extends AbstractParameter<RandomFactory> { +public class RandomParameter extends AbstractParameter<RandomParameter, RandomFactory> { /** * Seed value, if used */ diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/StringParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/StringParameter.java index 3a9bbf11..dc2a2a32 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/StringParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/StringParameter.java @@ -27,7 +27,6 @@ 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; import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstraint; /** * Parameter class for a parameter specifying a string. @@ -35,38 +34,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class StringParameter extends AbstractParameter<String> { - /** - * Constructs a string parameter with the given optionID, constraints and - * default value. - * - * @param optionID the unique id of the parameter - * @param constraint parameter constraint - * @param defaultValue the default value of the parameter - * - * @deprecated Use {@link #addConstraint} instead! - */ - @Deprecated - public StringParameter(OptionID optionID, ParameterConstraint<String> constraint, String defaultValue) { - super(optionID, defaultValue); - addConstraint(constraint); - } - - /** - * Constructs a string parameter with the given optionID, constraints and - * default value. - * - * @param optionID the unique id of the parameter - * @param constraint parameter constraint - * - * @deprecated Use {@link #addConstraint} instead! - */ - @Deprecated - public StringParameter(OptionID optionID, ParameterConstraint<String> constraint) { - super(optionID); - addConstraint(constraint); - } - +public class StringParameter extends AbstractParameter<StringParameter, String> { /** * Constructs a string parameter with the given optionID, and default value. * diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/VectorListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/VectorListParameter.java index 906bfbd8..43fa0797 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/VectorListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/VectorListParameter.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import de.lmu.ifi.dbs.elki.utilities.FormatUtil; 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.WrongParameterValueException; @@ -38,31 +39,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class VectorListParameter extends ListParameter<List<Double>> { - /** - * Constructs a vector list parameter with the given name and description. - * - * @param optionID Option ID - * @param constraints Constraint - * @param defaultValue Default value - */ - public VectorListParameter(OptionID optionID, List<ParameterConstraint<List<List<Double>>>> constraints, List<List<Double>> defaultValue) { - super(optionID, defaultValue); - addConstraints(constraints); - } - - /** - * Constructs a vector list parameter with the given name and description. - * - * @param optionID Option ID - * @param constraints Constraints - * @param optional Optional flag - */ - public VectorListParameter(OptionID optionID, List<ParameterConstraint<List<List<Double>>>> constraints, boolean optional) { - super(optionID, optional); - addConstraints(constraints); - } - +public class VectorListParameter extends ListParameter<VectorListParameter, List<Double>> { /** * Constructs a vector list parameter with the given name and description. * @@ -139,12 +116,12 @@ public class VectorListParameter extends ListParameter<List<Double>> { Iterator<Double> veciter = vec.iterator(); while(veciter.hasNext()) { buf.append(veciter.next().toString()); - if (veciter.hasNext()) { + if(veciter.hasNext()) { buf.append(LIST_SEP); } } // Append separation character - if (valiter.hasNext()) { + if(valiter.hasNext()) { buf.append(VECTOR_SEP); } } @@ -184,7 +161,7 @@ public class VectorListParameter extends ListParameter<List<Double>> { ArrayList<Double> vectorCoord = new ArrayList<>(); for(String coordinate : coordinates) { try { - vectorCoord.add(Double.valueOf(coordinate)); + vectorCoord.add(FormatUtil.parseDouble(coordinate)); } catch(NumberFormatException e) { throw new WrongParameterValueException("Wrong parameter format! Coordinates of vector \"" + vector + "\" are not valid!"); |