diff options
author | Erich Schubert <erich@debian.org> | 2014-10-31 03:43:51 +0100 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2019-03-09 22:30:40 +0000 |
commit | 596d8876dca5627dd76e8c23bf40a24cc305eeed (patch) | |
tree | d269ddb46561469f6b1fff67b19e0cd2b4608f5b /src/de/lmu/ifi/dbs/elki/utilities/optionhandling | |
parent | ee31d687b1a0e2f2f1e6e71375c7cc3b094919b8 (diff) | |
parent | 337087b668d3a54f3afee3a9adb597a32e9f7e94 (diff) |
Import Debian changes 0.6.5~20141030-1
elki (0.6.5~20141030-1) unstable; urgency=medium
* New upstream beta release
* Urgency medium: 0.6.0 suffers from a performance issue with duplicates.
* Repackaged tarball from .jar to .tar.bz2
* Add dependency on libsvm3-java
* Enable line numbers for debugging (ant debuglevel)
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling')
71 files changed, 308 insertions, 668 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/AbstractParameterizer.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/AbstractParameterizer.java index 6aa22964..0fa9b240 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/AbstractParameterizer.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/AbstractParameterizer.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/InternalParameterizationErrors.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/InternalParameterizationErrors.java index 1cff200a..aa77c364 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/InternalParameterizationErrors.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/InternalParameterizationErrors.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/NoParameterValueException.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/NoParameterValueException.java index 53d992ff..e0266028 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/NoParameterValueException.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/NoParameterValueException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/OptionID.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionID.java index 60e51a98..60afb2b1 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionID.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionID.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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 @@ -42,10 +42,7 @@ public final class OptionID { private String description; /** - * Provides a new OptionID of the given name and description. - * <p/> - * All OptionIDs are unique w.r.t. their name. An OptionID provides - * additionally a description of the option. + * Constructor. * * @param name the name of the option * @param description the description of the option diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionUtil.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionUtil.java index ea28aa42..32d7a84d 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionUtil.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/OptionUtil.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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 @@ -31,10 +31,10 @@ import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; import de.lmu.ifi.dbs.elki.utilities.FormatUtil; import de.lmu.ifi.dbs.elki.utilities.documentation.DocumentationUtil; import de.lmu.ifi.dbs.elki.utilities.documentation.Reference; +import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackedParameter; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.SerializedParameterization; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.TrackParameters; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter; -import de.lmu.ifi.dbs.elki.utilities.pairs.Pair; /** * Utility functions related to Option handling. @@ -123,11 +123,11 @@ public final class OptionUtil { * @param indent Indentation string * @param options List of options */ - public static void formatForConsole(StringBuilder buf, int width, String indent, Collection<Pair<Object, Parameter<?>>> options) { - for(Pair<Object, Parameter<?>> pair : options) { - String currentOption = pair.getSecond().getName(); - String syntax = pair.getSecond().getSyntax(); - String longDescription = pair.getSecond().getFullDescription(); + public static void formatForConsole(StringBuilder buf, int width, String indent, Collection<TrackedParameter> options) { + for(TrackedParameter pair : options) { + String currentOption = pair.getParameter().getName(); + String syntax = pair.getParameter().getSyntax(); + String longDescription = pair.getParameter().getFullDescription(); buf.append(SerializedParameterization.OPTION_PREFIX); buf.append(currentOption); @@ -196,7 +196,7 @@ public final class OptionUtil { TrackParameters track = new TrackParameters(config); @SuppressWarnings("unused") Object p = ClassGenericsUtil.tryInstantiate(Object.class, pcls, track); - Collection<Pair<Object, Parameter<?>>> options = track.getAllParameters(); + Collection<TrackedParameter> options = track.getAllParameters(); if(options.size() > 0) { OptionUtil.formatForConsole(buf, width, indent, options); } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/ParameterException.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/ParameterException.java index 326335fd..0c9d5421 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/ParameterException.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/ParameterException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/Parameterizable.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizable.java deleted file mode 100644 index ead565b1..00000000 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizable.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.lmu.ifi.dbs.elki.utilities.optionhandling; - -/* - 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/>. - */ - -/** - * Interface to define the required methods for command line interaction. - * - * <b>Important note:</b> - * - * <p> - * Although <em>this cannot be specified in a Java interface</em>, any class - * implementing this interface <em>must</em> also have a constructor that takes - * a single - * {@link de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization} - * as option, which is used to set the class parameters. - * </p> - * - * <p> - * Alternatively, a constructor with no options is also allowed. - * </p> - * - * <p> - * This means, each class implementing Parameterizable - * <em>must have a constructor that either is</em> <blockquote> - * - * <pre> - * {@code - * public Class(Parameterizable config) { ... } - * } - * </pre> - * - * </blockquote> or <blockquote> - * - * <pre> - * {@code - * public Class() { ... } - * } - * </pre> - * - * </blockquote> - * </p> - * - * <p> - * Constructors <em>MUST</em> not do expensive operations or allocations, since - * they will also be called just to determine and validate parameters. - * </p> - * - * <p> - * For <em>documentation</em>, the classes should also be annotated with - * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Title} - * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Description} and - * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Reference} (where - * possible). - * </p> - * - * <p> - * Please check the <em>package documentation</em> for full information on this - * interface. - * </p> - * - * <p> - * The application - * {@link de.lmu.ifi.dbs.elki.application.internal.CheckParameterizables} can be - * used to check this class contracts. - * </p> - * - * @author Erich Schubert - * - * @apiviz.exclude - * @apiviz.excludeSubtypes - * @apiviz.has de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter - * oneway - n - * @apiviz.uses de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization - * .Parameterization oneway - */ -public interface Parameterizable { - // Empty marker interface - the \@Description / \@Title / \@Reference and - // constructor requirements cannot be specified in Java! -} diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizer.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizer.java index 7e3a848c..b7017206 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizer.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/Parameterizer.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/UnspecifiedParameterException.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnspecifiedParameterException.java index 31af6d87..8d22b113 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnspecifiedParameterException.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnspecifiedParameterException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/UnusedParameterException.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnusedParameterException.java index d5dbd4b2..6bd13429 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnusedParameterException.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/UnusedParameterException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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/WrongParameterValueException.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/WrongParameterValueException.java index eeb6a9e7..3f34efb7 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/WrongParameterValueException.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/WrongParameterValueException.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling; 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 @@ -54,7 +54,7 @@ public class WrongParameterValueException extends ParameterException { * @param cause the cause */ public WrongParameterValueException(Parameter<?> parameter, String read, Throwable cause) { - this("Wrong value of parameter \"" + parameter.getName() + "\".\n" + "Read: " + read + ".\n" + "Expected: " + parameter.getFullDescription() + "\n" + cause.getMessage(), cause); + this("Wrong value of parameter \"" + parameter.getName() + "\".\n" + "Read: " + read + ".\n" + "Expected: " + parameter.getFullDescription() + "\n" + formatCause(cause), cause); } /** @@ -66,7 +66,7 @@ public class WrongParameterValueException extends ParameterException { * @param cause the cause */ public WrongParameterValueException(Parameter<?> parameter, String read, String reason, Throwable cause) { - this("Wrong value of parameter " + parameter.getName() + ".\n" + "Read: " + read + ".\n" + "Expected: " + parameter.getFullDescription() + "\n" + reason + "\n" + cause.getMessage(), cause); + this("Wrong value of parameter " + parameter.getName() + ".\n" + "Read: " + read + ".\n" + "Expected: " + parameter.getFullDescription() + "\n" + reason + "\n" + formatCause(cause), cause); } /** @@ -98,4 +98,21 @@ public class WrongParameterValueException extends ParameterException { public WrongParameterValueException(String message, Throwable e) { super(message, e); } + + /** + * Format the error cause. + * + * @param cause Error cause. + * @return String representation + */ + private static String formatCause(Throwable cause) { + if(cause == null) { + return ""; + } + String message = cause.getMessage(); + if(message != null) { + return message; + } + return cause.toString(); + } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AbstractNumberConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AbstractNumberConstraint.java index fc4a673e..edd6166e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AbstractNumberConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AbstractNumberConstraint.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) 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/constraints/AllOrNoneMustBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/AllOrNoneMustBeSetGlobalConstraint.java index a87af1a8..dfa9ffae 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 @@ -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) 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/constraints/CommonConstraints.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.java index ea1caed9..6464ed13 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/CommonConstraints.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) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -29,6 +29,9 @@ import java.util.List; * Class storing a number of very common constraints. * * @author Erich Schubert + * + * @apiviz.landmark + * @apiviz.composedOf ParameterConstraint */ public final class CommonConstraints { /** 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 586b4257..56ecd0b6 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 @@ -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) 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/constraints/EqualStringConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/EqualStringConstraint.java index 1ab35cc1..3dda08b6 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 @@ -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) 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/constraints/GlobalListSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalListSizeConstraint.java index 7c35045e..997e7295 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 @@ -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) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -71,7 +71,7 @@ public class GlobalListSizeConstraint implements GlobalParameterConstraint { return; } - if(list.getListSize() != length.getValue().intValue()) { + if(list.getListSize() != length.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/GlobalParameterConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalParameterConstraint.java index 5e38b2b7..e249e0ef 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalParameterConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalParameterConstraint.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) 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/constraints/GlobalVectorListElementSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GlobalVectorListElementSizeConstraint.java index 01c99d42..9afd0a56 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 @@ -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) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -23,8 +23,7 @@ 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.math.linearalgebra.Vector; 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.IntParameter; @@ -74,8 +73,8 @@ public class GlobalVectorListElementSizeConstraint implements GlobalParameterCon return; } - for(List<Double> vec : vector.getValue()) { - if(vec.size() != size.getValue().intValue()) { + for(Vector vec : vector.getValue()) { + if(vec.getDimensionality() != size.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 33c73fb8..8ec817e9 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 @@ -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) 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/constraints/GreaterEqualConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/GreaterEqualConstraint.java index d05235c1..ba3d63e9 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 @@ -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) 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/constraints/IntervalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java deleted file mode 100644 index 00c2f5ad..00000000 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/IntervalConstraint.java +++ /dev/null @@ -1,217 +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) 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.utilities.optionhandling.ParameterException; -import de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException; - -/** - * Represents an interval parameter constraint testing if a given value lies - * within the specified interval. The value of the number parameter ( - * {@link de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.NumberParameter} - * ) tested 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. - * - * @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: - * {@link IntervalConstraint.IntervalBoundary#OPEN} denotes an open interval, - * i.e. less than (or greater than) comparison - * {@link IntervalConstraint.IntervalBoundary#CLOSE} denotes a closed - * interval, i.e. an equal to or less than (or equal to or greater than) - * comparison - * - * @apiviz.exclude - */ - public enum IntervalBoundary { - /** - * Open interval boundary - */ - OPEN, - /** - * Closed interval boundary - */ - CLOSE - } - - /** - * The low constraint value (left interval boundary). - */ - private final Number lowConstraintValue; - - /** - * The interval boundary for the low constraint value. - * - * @see IntervalBoundary - */ - private final IntervalBoundary lowBoundary; - - /** - * The high constraint value (right interval boundary). - */ - private final Number highConstraintValue; - - /** - * The interval boundary for the high constraint value. - * - * @see IntervalBoundary - */ - private final IntervalBoundary 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(Number lowConstraintValue, IntervalBoundary lowBoundary, Number highConstraintValue, IntervalBoundary highBoundary) { - if(lowConstraintValue.doubleValue() >= highConstraintValue.doubleValue()) { - throw new IllegalArgumentException("Left interval boundary is greater than " + "or equal to right interval boundary!"); - } - - this.lowConstraintValue = lowConstraintValue; - this.lowBoundary = lowBoundary; - this.highConstraintValue = 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(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. - * - */ - @Override - public void test(Number t) throws ParameterException { - // lower value - if(lowBoundary.equals(IntervalBoundary.CLOSE)) { - if(t.doubleValue() < lowConstraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be " + "equal to or greater than " + lowConstraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); - } - } - else if(lowBoundary.equals(IntervalBoundary.OPEN)) { - if(t.doubleValue() <= lowConstraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be " + "greater than " + lowConstraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); - } - } - - // higher value - if(highBoundary.equals(IntervalBoundary.CLOSE)) { - if(t.doubleValue() > highConstraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be " + "equal to or less than " + highConstraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); - } - } - else if(highBoundary.equals(IntervalBoundary.OPEN)) { - if(t.doubleValue() >= highConstraintValue.doubleValue()) { - throw new WrongParameterValueException("Parameter Constraint Error: \n" + "The parameter value specified has to be " + "less than " + highConstraintValue.toString() + ". (current value: " + t.doubleValue() + ")\n"); - } - } - } - - @Override - public String getDescription(String parameterName) { - String description = parameterName + " in "; - if(lowBoundary.equals(IntervalBoundary.CLOSE)) { - description += "["; - } - else if(lowBoundary.equals(IntervalBoundary.OPEN)) { - description += "("; - } - - description += lowConstraintValue.toString() + ", " + highConstraintValue; - - if(highBoundary.equals(IntervalBoundary.CLOSE)) { - description += "]"; - } - if(highBoundary.equals(IntervalBoundary.OPEN)) { - description += ")"; - } - return description; - } -}
\ No newline at end of file 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 5c4d0635..e4273272 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 @@ -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) 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/constraints/LessEqualConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualConstraint.java index d81c821b..ce84412a 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 @@ -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) 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/constraints/LessEqualGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessEqualGlobalConstraint.java index 9fa0ee99..aae6012e 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 @@ -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) 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/constraints/LessGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/LessGlobalConstraint.java index 989f6e29..cbc29edf 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 @@ -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) 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/constraints/ListEachConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.java index 918c59f5..a561b884 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListEachConstraint.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) 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/constraints/ListParameterNoDuplicateValueConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.java index 1ff23f80..533db703 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListParameterNoDuplicateValueConstraint.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) 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/constraints/ListSizeConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ListSizeConstraint.java index 95b5214b..b23ae76d 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 @@ -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) 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/constraints/NoDuplicateValueGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/NoDuplicateValueGlobalConstraint.java index 7036ecef..c6d9d93f 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 @@ -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) 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/constraints/OneMustBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OneMustBeSetGlobalConstraint.java index e7802685..fd708d47 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 @@ -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) 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/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/OnlyOneIsAllowedToBeSetGlobalConstraint.java index bdd55572..0a22096f 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) 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/constraints/ParameterConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterConstraint.java index 2847260a..fa600907 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterConstraint.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) 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/constraints/ParameterFlagGlobalConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/ParameterFlagGlobalConstraint.java index ab77240a..87db36dc 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 @@ -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) 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/constraints/StringLengthConstraint.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/StringLengthConstraint.java index ff42a21f..98dd588e 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/StringLengthConstraint.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/StringLengthConstraint.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) 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/constraints/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/package-info.java index e05ca2fa..371bd643 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/constraints/package-info.java @@ -5,7 +5,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 diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java index d2106865..8f2dc2e5 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/package-info.java @@ -246,14 +246,12 @@ * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Title} * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Description} and * {@link de.lmu.ifi.dbs.elki.utilities.documentation.Reference} (where possible).</p> - * - * @apiviz.excludeSubtypes de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable */ /* 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/parameterization/AbstractParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/AbstractParameterization.java index 75a5be86..6b804777 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/AbstractParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/AbstractParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/ChainedParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ChainedParameterization.java index 97cdb51f..9d8c171b 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ChainedParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ChainedParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/EmptyParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/EmptyParameterization.java index 02802593..b43fed45 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/EmptyParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/EmptyParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/ListParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ListParameterization.java index b870b57b..3cb309f5 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ListParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/ListParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/MergedParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/MergedParameterization.java index 9f765963..8e6e10c8 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/MergedParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/MergedParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/Parameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/Parameterization.java index 01c46583..32ab5bdb 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/Parameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/Parameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/SerializedParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/SerializedParameterization.java index b3e3f214..7eb3cf45 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/SerializedParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/SerializedParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/TrackParameters.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackParameters.java index 5a20bd9e..a9ccda98 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackParameters.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackParameters.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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 @@ -32,11 +32,9 @@ import java.util.Map; import de.lmu.ifi.dbs.elki.logging.LoggingUtil; import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil; import de.lmu.ifi.dbs.elki.utilities.optionhandling.InternalParameterizationErrors; -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.constraints.GlobalParameterConstraint; import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.Parameter; -import de.lmu.ifi.dbs.elki.utilities.pairs.Pair; /** * Utility wrapper to track parameters for a configuration session. @@ -54,7 +52,7 @@ public class TrackParameters implements Parameterization { /** * Tracking storage */ - List<Pair<Object, Parameter<?>>> options = new ArrayList<>(); + List<TrackedParameter> options = new ArrayList<>(); /** * Tree information: parent links @@ -70,7 +68,7 @@ public class TrackParameters implements Parameterization { /** * Current parent for nested parameterization */ - Object cur = null; + Object owner = null; /** * Constructor. @@ -83,18 +81,30 @@ public class TrackParameters implements Parameterization { } /** + * Constructor. + * + * @param inner Inner parameterization to wrap. + * @param owner Class/instance owning the parameter + */ + public TrackParameters(Parameterization inner, Object owner) { + super(); + this.inner = inner; + this.owner = owner; + } + + /** * Internal constructor, for nested tracking. * * @param inner Inner parameterization - * @param option Option + * @param owner Object owning the current parameters * @param options List of options * @param parents Parent map * @param children Child map */ - private TrackParameters(Parameterization inner, Object option, List<Pair<Object, Parameter<?>>> options, Map<Object, Object> parents, Map<Object, List<Object>> children) { + private TrackParameters(Parameterization inner, Object owner, List<TrackedParameter> options, Map<Object, Object> parents, Map<Object, List<Object>> children) { super(); - this.inner = inner.descend(option); - this.cur = option; + this.inner = inner.descend(owner); + this.owner = owner; this.options = options; this.parents = parents; this.children = children; @@ -113,7 +123,7 @@ public class TrackParameters implements Parameterization { @Override public boolean grab(Parameter<?> opt) { registerChild(opt); - options.add(new Pair<Object, Parameter<?>>(cur, opt)); + options.add(new TrackedParameter(owner, opt)); return inner.grab(opt); } @@ -130,7 +140,7 @@ public class TrackParameters implements Parameterization { @Override public boolean setValueForOption(Parameter<?> opt) throws ParameterException { registerChild(opt); - options.add(new Pair<Object, Parameter<?>>(cur, opt)); + options.add(new TrackedParameter(owner, opt)); return inner.setValueForOption(opt); } @@ -139,33 +149,19 @@ public class TrackParameters implements Parameterization { * * @return Parameters seen */ - public Collection<Pair<Object, Parameter<?>>> getAllParameters() { + public Collection<TrackedParameter> getAllParameters() { return options; } - /** - * Get the tracked parameters that were actually set. - * - * @return Parameters given - */ - public Collection<Pair<OptionID, Object>> getGivenParameters() { - ArrayList<Pair<OptionID, Object>> ret = new ArrayList<>(); - for(Pair<Object, Parameter<?>> pair : options) { - if(pair.second.isDefined() && pair.second.getGivenValue() != null) { - ret.add(new Pair<>(pair.second.getOptionID(), pair.second.getGivenValue())); - } - } - return ret; - } - @Override public boolean checkConstraint(GlobalParameterConstraint constraint) { return inner.checkConstraint(constraint); } /** - * {@inheritDoc} Track parameters using a shared options list with parent - * tracker. + * {@inheritDoc} + * + * Track parameters using a shared options list with parent tracker. */ @Override public Parameterization descend(Object option) { @@ -174,14 +170,14 @@ public class TrackParameters implements Parameterization { } private void registerChild(Object opt) { - if(opt == cur) { + if(opt == owner) { LoggingUtil.exception("Options shouldn't have themselves as parents!", new Throwable()); } - parents.put(opt, cur); - List<Object> c = children.get(cur); + parents.put(opt, owner); + List<Object> c = children.get(owner); if(c == null) { c = new ArrayList<>(); - children.put(cur, c); + children.put(owner, c); } if(!c.contains(opt)) { c.add(opt); @@ -204,7 +200,7 @@ public class TrackParameters implements Parameterization { return ClassGenericsUtil.tryInstantiate(r, c, this); } catch(Exception e) { - reportError(new InternalParameterizationErrors("Error instantiating internal class: "+c.getName(), e)); + reportError(new InternalParameterizationErrors("Error instantiating internal class: " + c.getName(), e)); return null; } } @@ -215,7 +211,7 @@ public class TrackParameters implements Parameterization { return ClassGenericsUtil.tryInstantiate(c, c, this); } catch(Exception e) { - reportError(new InternalParameterizationErrors("Error instantiating internal class: "+c.getName(), e)); + reportError(new InternalParameterizationErrors("Error instantiating internal class: " + c.getName(), e)); return null; } } diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackedParameter.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackedParameter.java new file mode 100644 index 00000000..01969302 --- /dev/null +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/TrackedParameter.java @@ -0,0 +1,71 @@ +package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; + +/* + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures + + Copyright (C) 2014 + 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.parameters.Parameter; + +/** + * Class containing an object, and the associated value. + * + * @author Erich Schubert + */ +public class TrackedParameter { + /** + * Option ID + */ + private Object owner; + + /** + * Parameter value + */ + private Parameter<?> parameter; + + /** + * Constructor. + * + * @param owner Object owning the parameter value + * @param parameter Parameter + */ + public TrackedParameter(Object owner, Parameter<?> parameter) { + this.owner = owner; + this.parameter = parameter; + } + + /** + * Get the owner object. + * + * @return Parameter owner + */ + public Object getOwner() { + return owner; + } + + /** + * Get the parameter observed. + * + * @return Parameter + */ + public Parameter<?> getParameter() { + return parameter; + } +}
\ No newline at end of file diff --git a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/UnParameterization.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/UnParameterization.java index 2a05a766..dfdbe7ac 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/UnParameterization.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/UnParameterization.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization; 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/parameterization/package-info.java b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/package-info.java index ce9c89b4..d330d343 100644 --- a/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameterization/package-info.java @@ -8,7 +8,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 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 |