diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters')
23 files changed, 128 insertions, 252 deletions
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 cdad8583..05e82152 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -131,10 +131,12 @@ public abstract class AbstractParameter<THIS extends AbstractParameter<THIS, T>, this(optionID, false); } + @SuppressWarnings("unchecked") @Override - public void setDefaultValue(T defaultValue) { + public THIS setDefaultValue(T defaultValue) { this.defaultValue = defaultValue; this.optionalParameter = true; + return (THIS) this; } @Override @@ -142,7 +144,6 @@ public abstract class AbstractParameter<THIS extends AbstractParameter<THIS, T>, return !(defaultValue == null); } - // TODO: can we do this more elegantly? @Override public void useDefaultValue() { setValueInternal(defaultValue); 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 1cea7fac..bd41e139 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 42288738..02545582 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -26,6 +26,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; import java.lang.reflect.InvocationTargetException; import java.util.List; +import de.lmu.ifi.dbs.elki.logging.Logging; import de.lmu.ifi.dbs.elki.logging.LoggingUtil; import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; import de.lmu.ifi.dbs.elki.utilities.FormatUtil; @@ -51,6 +52,11 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz // TODO: turn restrictionClass into a constraint? public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>, Class<? extends C>> { /** + * The class logger. + */ + private static final Logging LOG = Logging.getLogger(ClassParameter.class); + + /** * The restriction class for this class parameter. */ protected Class<C> restrictionClass; @@ -176,7 +182,27 @@ public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>, Clas @Override public String getValuesDescription() { if(restrictionClass != null && restrictionClass != Object.class) { - return restrictionString(); + StringBuilder info = new StringBuilder(); + if(restrictionClass.isInterface()) { + info.append("Implementing "); + } + else { + info.append("Extending "); + } + info.append(restrictionClass.getName()); + info.append(FormatUtil.NEWLINE); + + List<Class<?>> known = getKnownImplementations(); + if(!known.isEmpty()) { + info.append("Known classes (default package " + restrictionClass.getPackage().getName() + "):"); + info.append(FormatUtil.NEWLINE); + for(Class<?> c : known) { + info.append("->").append(FormatUtil.NONBREAKING_SPACE); + info.append(canonicalClassName(c, getRestrictionClass())); + info.append(FormatUtil.NEWLINE); + } + } + return info.toString(); } return ""; } @@ -214,6 +240,9 @@ public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>, Clas throw new WrongParameterValueException(this, getValue().getCanonicalName(), "Error instantiating class - no usable public constructor."); } catch(Exception e) { + if(LOG.isVerbose()) { + LOG.exception("Class initialization failed.", e); + } throw new WrongParameterValueException(this, getValue().getCanonicalName(), "Error instantiating class.", e); } return instance; @@ -243,37 +272,6 @@ public class ClassParameter<C> extends AbstractParameter<ClassParameter<C>, Clas } /** - * Provides a description string listing all classes for the given superclass - * or interface as specified in the properties. - * - * @return a description string listing all classes for the given superclass - * or interface as specified in the properties - */ - public String restrictionString() { - StringBuilder info = new StringBuilder(); - if(restrictionClass.isInterface()) { - info.append("Implementing "); - } - else { - info.append("Extending "); - } - info.append(restrictionClass.getName()); - info.append(FormatUtil.NEWLINE); - - List<Class<?>> known = getKnownImplementations(); - if(!known.isEmpty()) { - info.append("Known classes (default package " + restrictionClass.getPackage().getName() + "):"); - info.append(FormatUtil.NEWLINE); - for(Class<?> c : known) { - info.append("->" + FormatUtil.NONBREAKING_SPACE); - info.append(canonicalClassName(c, getRestrictionClass())); - info.append(FormatUtil.NEWLINE); - } - } - return info.toString(); - } - - /** * Get the "simple" form of a class name. * * @param c Class 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 deleted file mode 100644 index eda54082..00000000 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DistanceParameter.java +++ /dev/null @@ -1,149 +0,0 @@ -package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; - -/* - 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 de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction; -import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; - -/** - * Parameter class for a parameter specifying a double value. - * - * @author Steffi Wanka - * @author Erich Schubert - * - * @param <D> Distance type - */ -public class DistanceParameter<D extends Distance<D>> extends AbstractParameter<DistanceParameter<D>, D> { - /** - * Distance type - */ - D dist; - - /** - * Constructs a double parameter with the given optionID and default value. - * - * @param optionID the unique optionID - * @param dist distance factory - * @param defaultValue the default value for this double parameter - */ - public DistanceParameter(OptionID optionID, D dist, D defaultValue) { - super(optionID, defaultValue); - this.dist = dist; - } - - /** - * Constructs a double parameter with the given optionID and default value. - * - * @param optionID the unique optionID - * @param dist distance factory - * @param defaultValue the default value for this double parameter - */ - public DistanceParameter(OptionID optionID, DistanceFunction<?, D> dist, D defaultValue) { - super(optionID, defaultValue); - this.dist = (dist != null) ? dist.getDistanceFactory() : null; - } - - /** - * Constructs a double parameter with the given optionID and optional flag. - * - * @param optionID the unique id of this parameter - * @param dist distance factory - * @param optional specifies whether this parameter is an optional parameter - */ - public DistanceParameter(OptionID optionID, D dist, boolean optional) { - super(optionID, optional); - this.dist = dist; - } - - /** - * Constructs a double parameter with the given optionID and optional flag. - * - * @param optionID the unique id of this parameter - * @param dist distance factory - * @param optional specifies whether this parameter is an optional parameter - */ - public DistanceParameter(OptionID optionID, DistanceFunction<?, D> dist, boolean optional) { - super(optionID, optional); - this.dist = (dist != null) ? dist.getDistanceFactory() : null; - } - - /** - * Constructs a double parameter with the given optionID. - * - * @param optionID the unique id of this parameter - * @param dist distance factory - */ - public DistanceParameter(OptionID optionID, D dist) { - super(optionID); - this.dist = dist; - } - - /** - * Constructs a double parameter with the given optionID. - * - * @param optionID the unique id of this parameter - * @param dist distance factory - */ - public DistanceParameter(OptionID optionID, DistanceFunction<?, D> dist) { - super(optionID); - this.dist = (dist != null) ? dist.getDistanceFactory() : null; - } - - @Override - public String getValueAsString() { - return getValue().toString(); - } - - @SuppressWarnings("unchecked") - @Override - protected D parseValue(Object obj) throws WrongParameterValueException { - if (dist == null) { - throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a distance value, but the distance was not set!"); - } - if (obj == null) { - throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a distance value, but a null value was given!"); - } - if(dist.nullDistance().getClass().isAssignableFrom(obj.getClass())) { - return (D) dist.nullDistance().getClass().cast(obj); - } - try { - return dist.parseString(obj.toString()); - } - catch(IllegalArgumentException e) { - throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a distance value, read: " + obj + "!\n"); - } - } - - /** - * Returns a string representation of the parameter's type. - * - * @return "<distance>" - */ - @Override - public String getSyntax() { - return "<distance>"; - } -}
\ No newline at end of file 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 84f97734..b5c651c2 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import de.lmu.ifi.dbs.elki.utilities.FormatUtil; +import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.ArrayLikeUtil; 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; @@ -59,7 +60,7 @@ public class DoubleListParameter extends ListParameter<DoubleListParameter, Doub @Override public String getValueAsString() { - return FormatUtil.format(getValue().toArray(new Double[getValue().size()]), LIST_SEP, FormatUtil.NF); + return FormatUtil.format(ArrayLikeUtil.toPrimitiveDoubleArray(getValue()), LIST_SEP); } @SuppressWarnings("unchecked") @@ -68,15 +69,16 @@ public class DoubleListParameter extends ListParameter<DoubleListParameter, Doub try { List<?> l = List.class.cast(obj); // do extra validation: - for (Object o : l) { - if (!(o instanceof Double)) { + for(Object o : l) { + if(!(o instanceof Double)) { throw new WrongParameterValueException("Wrong parameter format for parameter \"" + getName() + "\". Given list contains objects of different type!"); } } // TODO: can we use reflection to get extra checks? // TODO: Should we copy the list? - return (List<Double>)l; - } catch (ClassCastException e) { + return (List<Double>) l; + } + catch(ClassCastException e) { // continue with others } if(obj instanceof String) { @@ -87,6 +89,11 @@ public class DoubleListParameter extends ListParameter<DoubleListParameter, Doub } return doubleValue; } + if(obj instanceof Double) { + ArrayList<Double> doubleValue = new ArrayList<>(1); + doubleValue.add((Double) obj); + return doubleValue; + } throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Double values!"); } @@ -97,11 +104,10 @@ public class DoubleListParameter extends ListParameter<DoubleListParameter, Doub * parameter */ // Unused? - /*public void setDefaultValue(double allListDefaultValue) { - for(int i = 0; i < defaultValue.size(); i++) { - defaultValue.set(i, allListDefaultValue); - } - }*/ + /* + * public void setDefaultValue(double allListDefaultValue) { for(int i = 0; i + * < defaultValue.size(); i++) { defaultValue.set(i, allListDefaultValue); } } + */ /** * Returns a string representation of the parameter's type. 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 efa64370..109d3204 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 22d7dd54..ed86b542 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2011
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -26,6 +26,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; import java.util.ArrayList;
import java.util.Collection;
+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.UnspecifiedParameterException;
@@ -111,16 +112,17 @@ public class EnumParameter<E extends Enum<E>> extends AbstractParameter<EnumPara @Override
protected E parseValue(Object obj) throws ParameterException {
- if (obj == null) {
+ if(obj == null) {
throw new UnspecifiedParameterException(this);
}
- if (enumClass.isInstance(obj)) {
+ if(enumClass.isInstance(obj)) {
return enumClass.cast(obj);
}
- if (obj instanceof String) {
+ if(obj instanceof String) {
try {
return Enum.valueOf(enumClass, (String) obj);
- } catch (IllegalArgumentException ex) {
+ }
+ catch(IllegalArgumentException ex) {
throw new WrongParameterValueException("Enum parameter " + getName() + " is invalid (must be one of [" + joinEnumNames(", ") + "].");
}
}
@@ -133,6 +135,26 @@ public class EnumParameter<E extends Enum<E>> extends AbstractParameter<EnumPara }
/**
+ * This class sometimes provides a list of value descriptions.
+ *
+ * @see de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.AbstractParameter#hasValuesDescription()
+ */
+ @Override
+ public boolean hasValuesDescription() {
+ return true;
+ }
+
+ @Override
+ public String getValuesDescription() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("One of:").append(FormatUtil.NEWLINE);
+ for(String s : getPossibleValues()) {
+ buf.append("->").append(FormatUtil.NONBREAKING_SPACE).append(s).append(FormatUtil.NEWLINE);
+ }
+ return buf.toString();
+ }
+
+ /**
* Get a list of possible values for this enum parameter.
*
* @return list of strings representing possible enum values.
@@ -141,7 +163,7 @@ public class EnumParameter<E extends Enum<E>> extends AbstractParameter<EnumPara // Convert to string array
final E[] enums = enumClass.getEnumConstants();
ArrayList<String> values = new ArrayList<>(enums.length);
- for (E t : enums) {
+ for(E t : enums) {
values.add(t.name());
}
return values;
@@ -157,8 +179,8 @@ public class EnumParameter<E extends Enum<E>> extends AbstractParameter<EnumPara private String joinEnumNames(String separator) {
E[] enumTypes = enumClass.getEnumConstants();
StringBuilder sb = new StringBuilder();
- for (int i = 0; i < enumTypes.length; ++i) {
- if (i > 0) {
+ for(int i = 0; i < enumTypes.length; ++i) {
+ if(i > 0) {
sb.append(separator);
}
sb.append(enumTypes[i].name());
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 9e115dc7..f4301fd7 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 3e9fdc7d..2d2cd43a 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 f9e1a1f1..8c2e35e2 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 cc8327b4..036aaff0 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 3d867770..68c1ff2e 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 df520daa..b10a2779 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -49,9 +49,9 @@ public abstract class ListParameter<THIS extends ListParameter<THIS, T>, T> exte public static final String LIST_SEP = ","; /** - * A pattern defining a ":". + * A pattern defining a ":" or ";". */ - public static final Pattern VECTOR_SPLIT = Pattern.compile(":"); + public static final Pattern VECTOR_SPLIT = Pattern.compile("[:;]"); /** * Vector separator character - ":" @@ -93,7 +93,7 @@ public abstract class ListParameter<THIS extends ListParameter<THIS, T>, T> exte * @return the size of this list parameter. */ public int getListSize() { - if (getValue() == null && isOptional()) { + if(getValue() == null && isOptional()) { return 0; } @@ -106,15 +106,15 @@ public abstract class ListParameter<THIS extends ListParameter<THIS, T>, T> exte */ // TODO: keep? remove? protected String asString() { - if (getValue() == null) { + if(getValue() == null) { return ""; } StringBuilder buffer = new StringBuilder(); buffer.append('['); - for (int i = 0; i < getValue().size(); i++) { + for(int i = 0; i < getValue().size(); i++) { buffer.append(getValue().get(i).toString()); - if (i != getValue().size() - 1) { + if(i != getValue().size() - 1) { buffer.append(','); } } 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 5ab6b487..67995a5d 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 fabdce53..8c7381fd 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectListParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectListParameter.java index ada6239a..96e6a80e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectListParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectListParameter.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectParameter.java index 4166d0a2..34b0ed3e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectParameter.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/ObjectParameter.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 ffacb6d1..8ff5199c 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 @@ -9,7 +9,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -49,8 +49,9 @@ public interface Parameter<T> { * Sets the default value of this parameter. * * @param defaultValue default value of this parameter + * @return the parameter itself, for chaining */ - public abstract void setDefaultValue(T defaultValue); + public abstract Parameter<T> setDefaultValue(T defaultValue); /** * Checks if this parameter has a default value. 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 e3cb4bcf..2e8121ba 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 bf5e0cb0..40fa6d53 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -23,7 +23,7 @@ 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.RandomFactory; +import de.lmu.ifi.dbs.elki.math.random.RandomFactory; 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; 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 dc2a2a32..9dd6ea26 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team 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 43fa0797..51578fb5 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 @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -23,10 +23,13 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters; along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import gnu.trove.list.array.TDoubleArrayList; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector; 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; @@ -39,7 +42,7 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.ParameterConstra * @author Steffi Wanka * @author Erich Schubert */ -public class VectorListParameter extends ListParameter<VectorListParameter, List<Double>> { +public class VectorListParameter extends ListParameter<VectorListParameter, Vector> { /** * Constructs a vector list parameter with the given name and description. * @@ -47,7 +50,7 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List * @param constraint Constraint * @param defaultValue Default value */ - public VectorListParameter(OptionID optionID, ParameterConstraint<List<List<Double>>> constraint, List<List<Double>> defaultValue) { + public VectorListParameter(OptionID optionID, ParameterConstraint<List<Vector>> constraint, List<Vector> defaultValue) { super(optionID, defaultValue); addConstraint(constraint); } @@ -59,7 +62,7 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List * @param constraint Constraint * @param optional Optional flag */ - public VectorListParameter(OptionID optionID, ParameterConstraint<List<List<Double>>> constraint, boolean optional) { + public VectorListParameter(OptionID optionID, ParameterConstraint<List<Vector>> constraint, boolean optional) { super(optionID, optional); addConstraint(constraint); } @@ -70,7 +73,7 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List * @param optionID Option ID * @param constraint Constraint */ - public VectorListParameter(OptionID optionID, ParameterConstraint<List<List<Double>>> constraint) { + public VectorListParameter(OptionID optionID, ParameterConstraint<List<Vector>> constraint) { super(optionID); addConstraint(constraint); } @@ -83,8 +86,8 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List */ // Indiscernible from optionID, constraints /* - * public VectorListParameter(OptionID optionID, List<List<Double>> - * defaultValue) { super(optionID, defaultValue); } + * public VectorListParameter(OptionID optionID, List<Vector> defaultValue) { + * super(optionID, defaultValue); } */ /** @@ -109,17 +112,10 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List @Override public String getValueAsString() { StringBuilder buf = new StringBuilder(); - List<List<Double>> val = getValue(); - Iterator<List<Double>> valiter = val.iterator(); + List<Vector> val = getValue(); + Iterator<Vector> valiter = val.iterator(); while(valiter.hasNext()) { - List<Double> vec = valiter.next(); - Iterator<Double> veciter = vec.iterator(); - while(veciter.hasNext()) { - buf.append(veciter.next().toString()); - if(veciter.hasNext()) { - buf.append(LIST_SEP); - } - } + buf.append(FormatUtil.format(valiter.next().getArrayRef(), LIST_SEP)); // Append separation character if(valiter.hasNext()) { buf.append(VECTOR_SEP); @@ -130,7 +126,7 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List @SuppressWarnings("unchecked") @Override - protected List<List<Double>> parseValue(Object obj) throws ParameterException { + protected List<Vector> parseValue(Object obj) throws ParameterException { try { List<?> l = List.class.cast(obj); // do extra validation: @@ -144,7 +140,7 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List } // TODO: can we use reflection to get extra checks? // TODO: Should we copy the list and vectors? - return (List<List<Double>>) l; + return (List<Vector>) l; } catch(ClassCastException e) { // continue with other attempts. @@ -154,11 +150,12 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List if(vectors.length == 0) { throw new WrongParameterValueException("Wrong parameter format! Given list of vectors for parameter \"" + getName() + "\" is empty!"); } - ArrayList<List<Double>> vecs = new ArrayList<>(); + ArrayList<Vector> vecs = new ArrayList<>(); + TDoubleArrayList vectorCoord = new TDoubleArrayList(); for(String vector : vectors) { + vectorCoord.clear(); String[] coordinates = SPLIT.split(vector); - ArrayList<Double> vectorCoord = new ArrayList<>(); for(String coordinate : coordinates) { try { vectorCoord.add(FormatUtil.parseDouble(coordinate)); @@ -167,11 +164,11 @@ public class VectorListParameter extends ListParameter<VectorListParameter, List throw new WrongParameterValueException("Wrong parameter format! Coordinates of vector \"" + vector + "\" are not valid!"); } } - vecs.add(vectorCoord); + vecs.add(new Vector(vectorCoord.toArray())); } return vecs; } - throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of Double values!"); + throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getName() + "\" requires a list of double values!"); } /** diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/package-info.java index 75d7c5a1..272cb8f2 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/package-info.java @@ -12,7 +12,7 @@ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2013 +Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team |