summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java27
1 files changed, 19 insertions, 8 deletions
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 22db8511..bdd55572 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
@@ -4,7 +4,7 @@ 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
+ Copyright (C) 2013
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -24,6 +24,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints;
*/
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionUtil;
@@ -55,17 +56,27 @@ public class OnlyOneIsAllowedToBeSetGlobalConstraint implements GlobalParameterC
}
/**
+ * Constructs a global parameter constraint for testing if only one parameter
+ * of a list of parameters is set.
+ *
+ * @param params list of parameters to be checked
+ */
+ public OnlyOneIsAllowedToBeSetGlobalConstraint(Parameter<?>... params) {
+ parameters = Arrays.asList(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 {
- ArrayList<String> set = new ArrayList<String>();
- for(Parameter<?> p : parameters) {
- if(p.isDefined()) {
+ ArrayList<String> set = new ArrayList<>();
+ for (Parameter<?> p : parameters) {
+ if (p.isDefined()) {
// FIXME: Retire the use of this constraint for Flags!
- if(p instanceof Flag) {
- if (((Flag)p).getValue().booleanValue()) {
+ if (p instanceof Flag) {
+ if (((Flag) p).getValue().booleanValue()) {
set.add(p.getName());
}
} else {
@@ -73,7 +84,7 @@ public class OnlyOneIsAllowedToBeSetGlobalConstraint implements GlobalParameterC
}
}
}
- if(set.size() > 1) {
+ if (set.size() > 1) {
throw new WrongParameterValueException("Global Parameter Constraint Error.\n" + "Only one of the parameters " + OptionUtil.optionsNamesToString(parameters) + " is allowed to be set. " + "Parameters currently set: " + set.toString());
}
}
@@ -82,4 +93,4 @@ public class OnlyOneIsAllowedToBeSetGlobalConstraint implements GlobalParameterC
public String getDescription() {
return "Only one of the parameters " + OptionUtil.optionsNamesToString(parameters) + " is allowed to be set.";
}
-} \ No newline at end of file
+}