diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints')
7 files changed, 114 insertions, 19 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); } |