}
boolean containsPositiveWeight = false;
for (int i = begin; i < begin + length; i++) {
if (Double.isNaN(weights[i])) {
throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, i);
}
if (Double.isInfinite(weights[i])) {
throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, weights[i], i);
}
if (weights[i] < 0) {
throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, i, weights[i]);
}
if (!containsPositiveWeight && weights[i] > 0.0) {
containsPositiveWeight = true;
}
}
if (!containsPositiveWeight) {
throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO);
}
return test(values, begin, length, allowEmpty);
}