diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/utilities/optionhandling/parameters/DoubleListParameter.java | 28 |
1 files changed, 17 insertions, 11 deletions
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. |