use of de.lmu.ifi.dbs.elki.utilities.optionhandling.WrongParameterValueException in project elki by elki-project.
the class DoubleArrayListParameter method parseValue.
@SuppressWarnings("unchecked")
@Override
protected List<double[]> parseValue(Object obj) throws ParameterException {
try {
List<?> l = List.class.cast(obj);
// do extra validation:
for (Object o : l) {
if (!(o instanceof double[])) {
throw new WrongParameterValueException("Wrong parameter format for parameter \"" + getOptionID().getName() + "\". Given list contains objects of different type!");
}
}
// TODO: Should we copy the list and vectors?
return (List<double[]>) l;
} catch (ClassCastException e) {
// continue with other attempts.
}
if (obj instanceof String) {
String[] vectors = VECTOR_SPLIT.split((String) obj);
if (vectors.length == 0) {
throw new WrongParameterValueException("Wrong parameter format! Given list of vectors for parameter \"" + getOptionID().getName() + "\" is empty!");
}
ArrayList<double[]> vecs = new ArrayList<>();
double[] buf = new double[11];
int used = 0;
for (String vector : vectors) {
used = 0;
String[] coordinates = SPLIT.split(vector);
for (String coordinate : coordinates) {
try {
if (used == buf.length) {
buf = Arrays.copyOf(buf, buf.length << 1);
}
buf[used++] = ParseUtil.parseDouble(coordinate);
} catch (NumberFormatException e) {
throw new WrongParameterValueException("Wrong parameter format! Coordinates of vector \"" + vector + "\" are not valid!");
}
}
vecs.add(Arrays.copyOf(buf, used));
}
return vecs;
}
throw new WrongParameterValueException("Wrong parameter format! Parameter \"" + getOptionID().getName() + "\" requires a list of double values!");
}
Aggregations