final ParameterValueList values = this.values; // Protect against accidental changes.
// Quick search for an exact match.
final int size = values.size();
for (int i=0; i<size; i++) {
final GeneralParameterDescriptor descriptor = values.descriptor(i);
if (descriptor instanceof ParameterDescriptor<?>) {
if (name.equals(descriptor.getName().toString())) {
return (ParameterValue<?>) values.get(i);
}
}
}
// More costly search before to give up.
int fallback = -1, ambiguity = -1;
for (int i=0; i<size; i++) {
final GeneralParameterDescriptor descriptor = values.descriptor(i);
if (descriptor instanceof ParameterDescriptor<?>) {
if (isHeuristicMatchForName(descriptor, name)) {
if (fallback < 0) {
fallback = i;
} else {
ambiguity = i;
}
}
}
}
if (fallback >= 0) {
if (ambiguity < 0) {
return (ParameterValue<?>) values.get(fallback);
}
throw new ParameterNotFoundException(Errors.format(Errors.Keys.AmbiguousName_3,
values.descriptor(fallback).getName(), values.descriptor(ambiguity).getName(), name), name);
}
/*
* No existing parameter found. The parameter may be optional. Check if a descriptor exists.
* If such a descriptor is found, create the parameter, add it to the values list and returns it.
*/
final GeneralParameterDescriptor descriptor = values.descriptor.descriptor(name);
if (descriptor instanceof ParameterDescriptor<?> && descriptor.getMaximumOccurs() != 0) {
final ParameterValue<?> value = ((ParameterDescriptor<?>) descriptor).createValue();
values.addUnchecked(value);
return value;
}
throw new ParameterNotFoundException(Errors.format(Errors.Keys.ParameterNotFound_2,