diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints')
17 files changed, 479 insertions, 249 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 42209d87..c2448ba5 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 @@ -23,8 +23,8 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; @@ -33,9 +33,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter; /** * Global parameter constraint specifying that either all elements of a list of - * parameters ( - * {@link de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter}) - * must be set, or none of them. + * parameters ({@link Parameter}) must be set, or none of them. * * @author Steffi Wanka */ @@ -43,7 +41,7 @@ public class AllOrNoneMustBeSetGlobalConstraint implements GlobalParameterConstr /** * List of parameters to be checked */ - private List<Parameter<?, ?>> parameterList; + private List<Parameter<?>> parameterList; /** * Constructs a global parameter constraint for testing if either all elements @@ -51,7 +49,7 @@ public class AllOrNoneMustBeSetGlobalConstraint implements GlobalParameterConstr * * @param parameters list of parameters to be checked */ - public AllOrNoneMustBeSetGlobalConstraint(List<Parameter<?, ?>> parameters) { + public AllOrNoneMustBeSetGlobalConstraint(List<Parameter<?>> parameters) { this.parameterList = parameters; } @@ -62,10 +60,10 @@ public class AllOrNoneMustBeSetGlobalConstraint implements GlobalParameterConstr @Override public void test() throws ParameterException { - Vector<String> set = new Vector<String>(); - Vector<String> notSet = new Vector<String>(); + ArrayList<String> set = new ArrayList<String>(); + ArrayList<String> notSet = new ArrayList<String>(); - for(Parameter<?, ?> p : parameterList) { + for(Parameter<?> p : parameterList) { if(p.isDefined()) { set.add(p.getName()); } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualStringConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualStringConstraint.java index ad567fa1..4c4a8de3 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualStringConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualStringConstraint.java @@ -57,16 +57,16 @@ public class EqualStringConstraint implements ParameterConstraint<String> { } private String constraintStrings() { - StringBuffer buffer = new StringBuffer(); - buffer.append("["); + StringBuilder buffer = new StringBuilder(); + buffer.append('['); for(int i = 0; i < testStrings.length; i++) { buffer.append(testStrings[i]); if(i != testStrings.length - 1) { - buffer.append(","); + buffer.append(','); } } - buffer.append("]"); + buffer.append(']'); return buffer.toString(); } 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 b30a45d9..1bad7d00 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 @@ -71,7 +71,7 @@ public class GlobalListSizeConstraint implements GlobalParameterConstraint { return; } - if(list.getListSize() != length.getValue()) { + if(list.getListSize() != length.getValue().intValue()) { throw new WrongParameterValueException("Global Parameter Constraint Error." + "\nThe size of the list parameter \"" + list.getName() + "\" must be " + length.getValue() + ", current size is " + list.getListSize() + ". The value is defined by the integer parameter " + length.getName() + ".\n"); } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalVectorListElementSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalVectorListElementSizeConstraint.java index 740d9545..6bc9fd2d 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalVectorListElementSizeConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalVectorListElementSizeConstraint.java @@ -75,7 +75,7 @@ public class GlobalVectorListElementSizeConstraint implements GlobalParameterCon } for(List<Double> vec : vector.getValue()) { - if(vec.size() != size.getValue()) { + if(vec.size() != size.getValue().intValue()) { throw new WrongParameterValueException("Global Parameter Constraint Error.\n" + "The vectors of vector list parameter " + vector.getName() + " have not the required dimension of " + size.getValue() + " given by integer parameter " + size.getName() + "."); } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterConstraint.java index 22cc50f9..17a9a54d 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterConstraint.java @@ -28,42 +28,63 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter; /** - * Represents a parameter constraint for testing if the value of the - * number parameter ({@link NumberParameter}) - * tested is greater than the specified constraint value. - * + * Represents a parameter constraint for testing if the value of the number + * parameter ({@link NumberParameter}) tested is greater than the specified + * constraint value. + * * @author Steffi Wanka */ public class GreaterConstraint extends AbstractNumberConstraint<Number> { - /** - * Creates a Greater-Than-Number parameter constraint. - * <p/> - * That is, the value of the number - * parameter has to be greater than the given constraint value. - * - * @param constraintValue the constraint value - */ - public GreaterConstraint(Number constraintValue) { - super(constraintValue); - } + /** + * Creates a Greater-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter has to be greater than the given + * constraint value. + * + * @param constraintValue the constraint value + */ + public GreaterConstraint(Number constraintValue) { + super(constraintValue); + } - /** - * Checks if the number value given by the number parameter is greater than - * the constraint value. If not, a parameter exception is thrown. - * - */ - @Override - public void test(Number t) throws ParameterException { - if (t.doubleValue() <= constraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error:\n" - + "The parameter value specified has to be greater than " - + constraintValue.toString() + - ". (current value: " + t.doubleValue() + ")\n"); - } - } + /** + * Creates a Greater-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter has to be greater than the given + * constraint value. + * + * @param constraintValue the constraint value + */ + public GreaterConstraint(int constraintValue) { + super(Integer.valueOf(constraintValue)); + } - @Override - public String getDescription(String parameterName) { - return parameterName + " > " + constraintValue; + /** + * Creates a Greater-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter has to be greater than the given + * constraint value. + * + * @param constraintValue the constraint value + */ + public GreaterConstraint(double constraintValue) { + super(Double.valueOf(constraintValue)); + } + + /** + * Checks if the number value given by the number parameter is greater than + * the constraint value. If not, a parameter exception is thrown. + * + */ + @Override + public void test(Number t) throws ParameterException { + if (t.doubleValue() <= constraintValue.doubleValue()) { + throw new WrongParameterValueException("Parameter Constraint Error:\n" + "The parameter value specified has to be greater than " + constraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); } + } + + @Override + public String getDescription(String parameterName) { + return parameterName + " > " + constraintValue; + } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterEqualConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterEqualConstraint.java index 26145620..7eb0de83 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterEqualConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterEqualConstraint.java @@ -28,45 +28,64 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter; /** - * Represents a Greater-Equal-Than-Number parameter constraint. The - * value of the number parameter ({@link NumberParameter}) - * tested has to be greater equal than the specified - * constraint value. - * + * Represents a Greater-Equal-Than-Number parameter constraint. The value of the + * number parameter ({@link NumberParameter}) tested has to be greater equal + * than the specified constraint value. + * * @author Steffi Wanka */ public class GreaterEqualConstraint extends AbstractNumberConstraint<Number> { - /** - * Creates a Greater-Equal parameter constraint. - * <p/> - * That is, the value of the number - * parameter given has to be greater equal than the constraint value given. - * - * @param constraintValue the constraint value - */ - public GreaterEqualConstraint(Number constraintValue) { - super(constraintValue); - } + /** + * Creates a Greater-Equal parameter constraint. + * <p/> + * That is, the value of the number parameter given has to be greater equal + * than the constraint value given. + * + * @param constraintValue the constraint value + */ + public GreaterEqualConstraint(Number constraintValue) { + super(constraintValue); + } - /** - * Checks if the number value given by the number parameter is - * greater equal than the constraint - * value. If not, a parameter exception is thrown. - * - */ - @Override - public void test(Number t) throws ParameterException { - if (t.doubleValue() < constraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" - + "The parameter value specified has to be greater equal than " - + constraintValue.toString() + - ". (current value: " + t.doubleValue() + ")\n"); - } - } + /** + * Creates a Greater-Equal parameter constraint. + * <p/> + * That is, the value of the number parameter given has to be greater equal + * than the constraint value given. + * + * @param constraintValue the constraint value + */ + public GreaterEqualConstraint(int constraintValue) { + super(Integer.valueOf(constraintValue)); + } - @Override - public String getDescription(String parameterName) { - return parameterName + " >= " + constraintValue; + /** + * Creates a Greater-Equal parameter constraint. + * <p/> + * That is, the value of the number parameter given has to be greater equal + * than the constraint value given. + * + * @param constraintValue the constraint value + */ + public GreaterEqualConstraint(double constraintValue) { + super(Double.valueOf(constraintValue)); + } + + /** + * Checks if the number value given by the number parameter is greater equal + * than the constraint value. If not, a parameter exception is thrown. + * + */ + @Override + public void test(Number t) throws ParameterException { + if (t.doubleValue() < constraintValue.doubleValue()) { + throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be greater equal than " + constraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); } + } + + @Override + public String getDescription(String parameterName) { + return parameterName + " >= " + constraintValue; + } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java index f9e93a5b..db6a1ed8 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java @@ -37,7 +37,10 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException * @author Steffi Wanka * * @apiviz.uses de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter + * + * @deprecated Use two constraints instead. */ +@Deprecated public class IntervalConstraint implements ParameterConstraint<Number> { /** * Available interval boundary types types: @@ -110,6 +113,56 @@ public class IntervalConstraint implements ParameterConstraint<Number> { } /** + * Creates an IntervalConstraint parameter constraint. + * <p/> + * That is, the value of the number parameter given has to be greater than (or + * equal to, if specified) than the specified low constraint value and less + * than (or equal to, if specified) than the specified high constraint value. + * + * @param lowConstraintValue the low constraint value (left interval boundary) + * @param lowBoundary the interval boundary for the low constraint value (see {@link IntervalBoundary}) + * @param highConstraintValue the high constraint value (right interval + * boundary) + * @param highBoundary the interval boundary for the high constraint value + * (see {@link IntervalBoundary}) + */ + public IntervalConstraint(int lowConstraintValue, IntervalBoundary lowBoundary, int highConstraintValue, IntervalBoundary highBoundary) { + if(lowConstraintValue >= highConstraintValue) { + throw new IllegalArgumentException("Left interval boundary is greater than " + "or equal to right interval boundary!"); + } + + this.lowConstraintValue = Integer.valueOf(lowConstraintValue); + this.lowBoundary = lowBoundary; + this.highConstraintValue = Integer.valueOf(highConstraintValue); + this.highBoundary = highBoundary; + } + + /** + * Creates an IntervalConstraint parameter constraint. + * <p/> + * That is, the value of the number parameter given has to be greater than (or + * equal to, if specified) than the specified low constraint value and less + * than (or equal to, if specified) than the specified high constraint value. + * + * @param lowConstraintValue the low constraint value (left interval boundary) + * @param lowBoundary the interval boundary for the low constraint value (see {@link IntervalBoundary}) + * @param highConstraintValue the high constraint value (right interval + * boundary) + * @param highBoundary the interval boundary for the high constraint value + * (see {@link IntervalBoundary}) + */ + public IntervalConstraint(double lowConstraintValue, IntervalBoundary lowBoundary, double highConstraintValue, IntervalBoundary highBoundary) { + if(lowConstraintValue >= highConstraintValue) { + throw new IllegalArgumentException("Left interval boundary is greater than " + "or equal to right interval boundary!"); + } + + this.lowConstraintValue = Double.valueOf(lowConstraintValue); + this.lowBoundary = lowBoundary; + this.highConstraintValue = Double.valueOf(highConstraintValue); + this.highBoundary = highBoundary; + } + + /** * Checks if the number value given by the number parameter is greater equal * than the constraint value. If not, a parameter exception is thrown. * diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessConstraint.java index 0994425e..a8369304 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessConstraint.java @@ -28,41 +28,64 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter; /** - * Represents a Less-Than-Number parameter constraint. The value of the - * number parameter ({@link NumberParameter}) tested has to be less than the specified constraint value. - * + * Represents a Less-Than-Number parameter constraint. The value of the number + * parameter ({@link NumberParameter}) tested has to be less than the specified + * constraint value. + * * @author Steffi Wanka */ public class LessConstraint extends AbstractNumberConstraint<Number> { - /** - * Creates a Less-Than-Number parameter constraint. - * <p/> - * That is, the value of the number - * parameter tested has to be less than the constraint value given. - * - * @param constraintValue the constraint value - */ - public LessConstraint(Number constraintValue) { - super(constraintValue); - } + /** + * Creates a Less-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter tested has to be less than the + * constraint value given. + * + * @param constraintValue the constraint value + */ + public LessConstraint(Number constraintValue) { + super(constraintValue); + } - /** - * Checks if the number value given by the number parameter is less than the constraint value. - * If not, a parameter exception is thrown. - * - */ - @Override - public void test(Number t) throws ParameterException { - if (t.doubleValue() >= constraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" - + "The parameter value specified has to be less than " + constraintValue.toString() - + ". (current value: " + t.doubleValue() + ")\n"); - } - } + /** + * Creates a Less-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter tested has to be less than the + * constraint value given. + * + * @param constraintValue the constraint value + */ + public LessConstraint(int constraintValue) { + super(Integer.valueOf(constraintValue)); + } - @Override - public String getDescription(String parameterName) { - return parameterName + " < " + constraintValue; + /** + * Creates a Less-Than-Number parameter constraint. + * <p/> + * That is, the value of the number parameter tested has to be less than the + * constraint value given. + * + * @param constraintValue the constraint value + */ + public LessConstraint(double constraintValue) { + super(Double.valueOf(constraintValue)); + } + + /** + * Checks if the number value given by the number parameter is less than the + * constraint value. If not, a parameter exception is thrown. + * + */ + @Override + public void test(Number t) throws ParameterException { + if (t.doubleValue() >= constraintValue.doubleValue()) { + throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be less than " + constraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); } + } + + @Override + public String getDescription(String parameterName) { + return parameterName + " < " + constraintValue; + } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualConstraint.java index 712630e8..e35381b3 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualConstraint.java @@ -29,40 +29,61 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter; /** * Represents a Less-Equal-Than-Number parameter constraint. The value of the - * number parameter ({@link NumberParameter}) tested has to be less equal than the specified constraint - * value. - * + * number parameter ({@link NumberParameter}) tested has to be less equal than + * the specified constraint value. + * * @author Steffi Wanka */ public class LessEqualConstraint extends AbstractNumberConstraint<Number> { - /** - * Creates a Less-Equal-Than-Number parameter constraint. - * <p/> - * That is, the value of - * the appropriate number parameter has to be less equal than the given constraint value. - * - * @param constraintValue the constraint value - */ - public LessEqualConstraint(Number constraintValue) { - super(constraintValue); - } + /** + * Creates a Less-Equal-Than-Number parameter constraint. + * <p/> + * That is, the value of the appropriate number parameter has to be less equal + * than the given constraint value. + * + * @param constraintValue the constraint value + */ + public LessEqualConstraint(Number constraintValue) { + super(constraintValue); + } - /** - * Checks if the number value given by the number parameter is less equal than - * the constraint value. If not, a parameter exception is thrown. - * - */ - @Override - public void test(Number t) throws ParameterException { - if (t.doubleValue() > constraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" - + "The parameter value specified has to be less equal than " - + constraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); - } - } + /** + * Creates a Less-Equal-Than-Number parameter constraint. + * <p/> + * That is, the value of the appropriate number parameter has to be less equal + * than the given constraint value. + * + * @param constraintValue the constraint value + */ + public LessEqualConstraint(double constraintValue) { + super(Double.valueOf(constraintValue)); + } - @Override - public String getDescription(String parameterName) { - return parameterName + " <= " + constraintValue; + /** + * Creates a Less-Equal-Than-Number parameter constraint. + * <p/> + * That is, the value of the appropriate number parameter has to be less equal + * than the given constraint value. + * + * @param constraintValue the constraint value + */ + public LessEqualConstraint(int constraintValue) { + super(Integer.valueOf(constraintValue)); + } + + /** + * Checks if the number value given by the number parameter is less equal than + * the constraint value. If not, a parameter exception is thrown. + */ + @Override + public void test(Number t) throws ParameterException { + if (t.doubleValue() > constraintValue.doubleValue()) { + throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be less equal than " + constraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); } + } + + @Override + public String getDescription(String parameterName) { + return parameterName + " <= " + constraintValue; + } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.java new file mode 100644 index 00000000..7dab4006 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.java @@ -0,0 +1,90 @@ +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) 2012 + 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.ArrayList; +import java.util.List; + +import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; + +/** + * Applies constraints to all elements of a list. + * + * @author Erich Schubert + * + * @apiviz.composedOf ParameterConstraint oneway 1 n + */ +public class ListEachConstraint<T> implements ParameterConstraint<List<T>> { + /** + * Constraints + */ + private List<ParameterConstraint<? super T>> constraints; + + /** + * Constructor. + */ + public ListEachConstraint() { + super(); + this.constraints = new ArrayList<ParameterConstraint<? super T>>(); + } + + /** + * Constructor. + * + * @param constraint Constraint to apply to all elements + */ + public ListEachConstraint(ParameterConstraint<? super T> constraint) { + super(); + this.constraints = new ArrayList<ParameterConstraint<? super T>>(1); + this.constraints.add(constraint); + } + + /** + * Add a constraint to this operator. + * + * @param constraint Constraint + */ + public void addConstraint(ParameterConstraint<? super T> constraint) { + this.constraints.add(constraint); + } + + @Override + public void test(List<T> t) throws ParameterException { + for (T e : t) { + for (ParameterConstraint<? super T> c : constraints) { + c.test(e); + } + } + } + + @Override + public String getDescription(String parameterName) { + final String all = "all elements of " + parameterName; + StringBuilder b = new StringBuilder(); + for (ParameterConstraint<? super T> c : constraints) { + b.append(c.getDescription(all)); + } + return b.toString(); + } +} diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListGreaterEqualConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListGreaterEqualConstraint.java deleted file mode 100644 index 0f33b9b2..00000000 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListGreaterEqualConstraint.java +++ /dev/null @@ -1,74 +0,0 @@ -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) 2012 - 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 de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; - -import java.util.List; - -/** - * Represents a Greater-Equal-Than-Number parameter constraint for a list of number values. - * All values of the list parameter ({@link de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ListParameter}) - * tested have to be greater than or equal to the specified constraint value. - * - * @author Elke Achtert - * @param <N> Number type - */ -public class ListGreaterEqualConstraint<N extends Number> extends AbstractNumberConstraint<List<N>> { - /** - * Creates a Greater-Equal-Than-Number parameter constraint. - * <p/> - * That is, all values of the list parameter - * tested have to be greater than or equal to the specified constraint value. - * - * @param constraintValue parameter constraint value - */ - public ListGreaterEqualConstraint(N constraintValue) { - super(constraintValue); - } - - /** - * Checks if all number values of the specified list parameter - * are greater than or equal to the constraint value. - * If not, a parameter exception is thrown. - * - */ - @Override - public void test(List<N> t) throws ParameterException { - for (Number n : t) { - if (n.doubleValue() < constraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" - + "The parameter values specified have to be greater than or equal to " + constraintValue.toString() - + ". (current value: " + t + ")\n"); - } - } - } - - @Override - public String getDescription(String parameterName) { - return "all elements of " + parameterName + " < " + constraintValue; - } - -} diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.java new file mode 100644 index 00000000..6545cc9d --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.java @@ -0,0 +1,78 @@ +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) 2012 + 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.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; + +/** + * Parameter constraint specifying that a parameter list + * is not allowed to have duplicate values. + * + * @author Arthur Zimek + */ +public class ListParameterNoDuplicateValueConstraint<T extends Object> implements ParameterConstraint<List<T>> { + + /** + * Constructs a Not-Equal-Value parameter constraint. That is, the + * elements of a list of parameter values are not allowed to have equal + * values. + * + */ + public ListParameterNoDuplicateValueConstraint() { + } + + + + /** + * Checks if the elements of the list of parameter values do have different + * values. If not, a parameter exception is thrown. + * + */ + @Override + public void test(List<T> list) throws ParameterException { + Set<T> values = new HashSet<T>(); + + for(T pv : list) { + if(!values.add(pv)) { + Object[] parametervaluesarr = list.toArray(); + throw new WrongParameterValueException("Global Parameter Constraint Error:\n" + "Parameter values must have different values. Current values: " + Arrays.deepToString(parametervaluesarr) + ".\n"); + } + } + } + + @Override + public String getDescription(String parameterName) { + return "Values for parameter "+parameterName+" must have different values."; + } + + + + +}
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListSizeConstraint.java index f2ef2069..82b3ae7e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListSizeConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListSizeConstraint.java @@ -37,10 +37,8 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ListParameter; * @author Steffi Wanka * * @apiviz.uses de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.ListParameter - * - * @param <T> Parameter type */ -public class ListSizeConstraint<T> implements ParameterConstraint<List<T>> { +public class ListSizeConstraint implements ParameterConstraint<List<?>> { /** * The list size constraint. */ @@ -63,7 +61,7 @@ public class ListSizeConstraint<T> implements ParameterConstraint<List<T>> { * equal to the list size constraint specified. */ @Override - public void test(List<T> t) throws ParameterException { + public void test(List<?> t) throws ParameterException { if(t.size() != sizeConstraint) { throw new WrongParameterValueException("Parameter Constraint Error.\n" + "List parameter has not the required size. (Requested size: " + +sizeConstraint + ", current size: " + t.size() + ").\n"); } 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 04472fa5..39ab2680 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 @@ -32,6 +32,7 @@ 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; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.AbstractParameter; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter; /** @@ -44,7 +45,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai /** * List of number parameters to be checked. */ - private List<? extends Parameter<?, ?>> parameters; + private List<? extends AbstractParameter<?>> parameters; /** * Constructs a Not-Equal-Value global parameter constraint. That is, the @@ -53,7 +54,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai * * @param parameters list of number parameters to be tested */ - public NoDuplicateValueGlobalConstraint(List<? extends Parameter<?, ?>> parameters) { + public NoDuplicateValueGlobalConstraint(List<? extends AbstractParameter<?>> parameters) { this.parameters = parameters; } @@ -64,7 +65,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai * * @param parameters list of number parameters to be tested */ - public NoDuplicateValueGlobalConstraint(Parameter<?, ?>... parameters) { + public NoDuplicateValueGlobalConstraint(AbstractParameter<?>... parameters) { this.parameters = Arrays.asList(parameters); } @@ -77,7 +78,7 @@ public class NoDuplicateValueGlobalConstraint implements GlobalParameterConstrai public void test() throws ParameterException { Set<Object> numbers = new HashSet<Object>(); - for(Parameter<?, ?> param : parameters) { + for(Parameter<?> param : parameters) { if(param.isDefined()) { if(!numbers.add(param.getValue())) { throw new WrongParameterValueException("Global Parameter Constraint Error:\n" + "Parameters " + OptionUtil.optionsNamesToString(parameters) + " must have different values. Current values: " + OptionUtil.parameterNamesAndValuesToString(parameters) + ".\n"); diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OneMustBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OneMustBeSetGlobalConstraint.java index 1c8c6b94..c0109ac5 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OneMustBeSetGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OneMustBeSetGlobalConstraint.java @@ -41,7 +41,7 @@ public class OneMustBeSetGlobalConstraint implements GlobalParameterConstraint { /** * List of parameters to be checked. */ - private List<Parameter<?,?>> parameters; + private List<Parameter<?>> parameters; /** * Creates a One-Must-Be-Set global parameter constraint. That is, at least @@ -49,7 +49,7 @@ public class OneMustBeSetGlobalConstraint implements GlobalParameterConstraint { * * @param params list of parameters */ - public OneMustBeSetGlobalConstraint(List<Parameter<?,?>> params) { + public OneMustBeSetGlobalConstraint(List<Parameter<?>> params) { parameters = params; } @@ -60,8 +60,8 @@ public class OneMustBeSetGlobalConstraint implements GlobalParameterConstraint { */ @Override public void test() throws ParameterException { - for(Parameter<?,?> p : parameters) { - if(p.isDefined()) { + for (Parameter<?> p : parameters) { + if (p.isDefined()) { return; } } @@ -72,4 +72,4 @@ public class OneMustBeSetGlobalConstraint implements GlobalParameterConstraint { public String getDescription() { return "At least one of the parameters " + OptionUtil.optionsNamesToString(parameters) + " has to be set."; } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java index 74a1955b..22db8511 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java @@ -23,8 +23,8 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import java.util.ArrayList; import java.util.List; -import java.util.Vector; import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; @@ -42,7 +42,7 @@ public class OnlyOneIsAllowedToBeSetGlobalConstraint implements GlobalParameterC /** * List of parameters to be checked. */ - private List<Parameter<?, ?>> parameters; + private List<Parameter<?>> parameters; /** * Constructs a global parameter constraint for testing if only one parameter @@ -50,23 +50,22 @@ public class OnlyOneIsAllowedToBeSetGlobalConstraint implements GlobalParameterC * * @param params list of parameters to be checked */ - public OnlyOneIsAllowedToBeSetGlobalConstraint(List<Parameter<?, ?>> params) { + public OnlyOneIsAllowedToBeSetGlobalConstraint(List<Parameter<?>> params) { parameters = params; } /** * Checks if only one parameter of a list of parameters is set. If not, a * parameter exception is thrown. - * */ @Override public void test() throws ParameterException { - Vector<String> set = new Vector<String>(); - for(Parameter<?, ?> p : parameters) { + ArrayList<String> set = new ArrayList<String>(); + for(Parameter<?> p : parameters) { if(p.isDefined()) { // FIXME: Retire the use of this constraint for Flags! if(p instanceof Flag) { - if (((Flag)p).getValue()) { + if (((Flag)p).getValue().booleanValue()) { set.add(p.getName()); } } else { diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterFlagGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterFlagGlobalConstraint.java index befc0788..ff2e6675 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterFlagGlobalConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterFlagGlobalConstraint.java @@ -28,26 +28,28 @@ import java.util.List; import de.lmu.ifi.dbs.elki.utilities.optionhandling.ParameterException; import de.lmu.ifi.dbs.elki.utilities.optionhandling.UnusedParameterException; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Flag; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.AbstractParameter; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter; /** * Global parameter constraint describing the dependency of a parameter ( - * {@link Parameter}) on a given flag ({@link Flag}). Depending on the status of - * the flag the parameter is tested for keeping its constraints or not. + * {@link AbstractParameter}) on a given flag ({@link Flag}). Depending on the + * status of the flag the parameter is tested for keeping its constraints or + * not. * * @author Steffi Wanka * * @apiviz.uses de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Flag - * @apiviz.uses de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter + * @apiviz.uses + * de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter * - * @param <C> Constraint type * @param <S> Parameter type */ -public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalParameterConstraint { +public class ParameterFlagGlobalConstraint<S> implements GlobalParameterConstraint { /** * Parameter possibly to be checked. */ - private Parameter<S,C> param; + private Parameter<S> param; /** * Flag the checking of the parameter constraints is dependent on. @@ -62,7 +64,7 @@ public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalPara /** * List of parameter constraints. */ - private List<ParameterConstraint<S>> cons; + private List<ParameterConstraint<? super S>> cons; /** * Constructs a global parameter constraint specifying that the testing of the @@ -70,12 +72,13 @@ public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalPara * the status of the flag given. * * @param p parameter possibly to be checked - * @param c a list of parameter constraints, if the value is null, the parameter is just tested if it is set. + * @param c a list of parameter constraints, if the value is null, the + * parameter is just tested if it is set. * @param f flag controlling the checking of the parameter constraints * @param flagConstraint indicates at which status of the flag the parameter * is to be checked */ - public ParameterFlagGlobalConstraint(Parameter<S, C> p, List<ParameterConstraint<S>> c, Flag f, boolean flagConstraint) { + public ParameterFlagGlobalConstraint(Parameter<S> p, List<ParameterConstraint<? super S>> c, Flag f, boolean flagConstraint) { param = p; flag = f; this.flagConstraint = flagConstraint; @@ -91,9 +94,9 @@ public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalPara @Override public void test() throws ParameterException { // only check constraints of param if flag is set - if(flagConstraint == flag.getValue()) { + if(flagConstraint == flag.getValue().booleanValue()) { if(cons != null) { - for(ParameterConstraint<? super C> c : cons) { + for(ParameterConstraint<? super S> c : cons) { c.test(param.getValue()); } } @@ -107,14 +110,14 @@ public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalPara @Override public String getDescription() { - StringBuffer description = new StringBuffer(); + StringBuilder description = new StringBuilder(); if(flagConstraint) { description.append("If ").append(flag.getName()); description.append(" is set, the following constraints for parameter "); description.append(param.getName()).append(" have to be fullfilled: "); if(cons != null) { for(int i = 0; i < cons.size(); i++) { - ParameterConstraint<? super C> c = cons.get(i); + ParameterConstraint<? super S> c = cons.get(i); if(i > 0) { description.append(", "); } @@ -122,7 +125,7 @@ public class ParameterFlagGlobalConstraint<S, C extends S> implements GlobalPara } } else { - description.append(param.getName()+" must be set."); + description.append(param.getName()).append(" must be set."); } } return description.toString(); |