/** Set the specified parameter to the specified value, if not null. */ private static void setParameterValue( final ParameterValueGroup parameters, String name, Object value) throws InvalidParameterNameException { if (value != null) try { parameters.parameter(name).setValue(value); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException( Errors.format(ErrorKeys.UNKNOW_PARAMETER_NAME_$1, name), name); exception.initCause(cause); throw exception; } } }
final String name = d.getName().getCode().trim().toLowerCase(); if (replacements.put(name, d) != null) { throw new InvalidParameterNameException( Errors.format(ErrorKeys.DUPLICATED_VALUES_$1, name), name);
} catch (InvalidParameterNameException e) { assertEquals("4", e.getParameterName()); assertNotNull(e.getMessage());
value = "(group)"; throw new InvalidParameterNameException( Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, name, value), name);
/** * Tests that attempts to add an invalid parameter cause an {@link InvalidParameterNameException} to be thrown. */ @Test @DependsOnMethod("testValuesAdd") public void testValuesAddWrongParameter() { final DefaultParameterValueGroup group = createGroup(10); final List<GeneralParameterValue> values = group.values(); final ParameterValue<Integer> nonExistent = new DefaultParameterDescriptor<>( singletonMap(NAME_KEY, "Optional 5"), 0, 1, Integer.class, null, null, null).createValue(); try { values.add(nonExistent); fail("“Optional 5” is not a parameter for this group."); } catch (InvalidParameterNameException e) { assertEquals("Optional 5", e.getParameterName()); final String message = e.getMessage(); assertTrue(message, message.contains("Optional 5")); assertTrue(message, message.contains("Test group")); } }
new InvalidParameterNameException( Errors.format(ErrorKeys.UNEXPECTED_PARAMETER_$1, name), name); if (cause != null) { exception.initCause(cause);
final ParameterDescriptor d = (ParameterDescriptor) values[i].getDescriptor(); if (AbstractIdentifiedObject.nameMatches(d, name)) { throw new InvalidParameterNameException( Errors.format( ErrorKeys.PARAMETER_NAME_CLASH_$4,
continue; } else { throw new InvalidParameterNameException( Errors.format(ErrorKeys.UNEXPECTED_PARAMETER_$1, name), name); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException( Errors.format(ErrorKeys.UNEXPECTED_PARAMETER_$1, name), name); exception.initCause(cause); throw exception;
if (i != j) { if (nameMatches(parameters[j], name)) { throw new InvalidParameterNameException( Errors.format( ErrorKeys.PARAMETER_NAME_CLASH_$4,
/** * Set the specified parameter to the specified value, if not null. */ private static void setParameterValue(final ParameterValueGroup parameters, String name, Object value) throws InvalidParameterNameException { if (value != null) try { parameters.parameter(name).setValue(value); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException( Errors.format(ErrorKeys.UNKNOW_PARAMETER_NAME_$1, name), name); exception.initCause(cause); throw exception; } } }
/** * Verifies the given descriptor exists in the {@link DefaultParameterDescriptorGroup#descriptors()} list. */ final void ensureDescriptorExists(final GeneralParameterDescriptor desc) { final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors(); if (!descriptors.contains(desc)) { /* * For a more accurate error message, check if the operation failed because the * parameter name was not found, or the parameter descriptor does not matches. */ final Identifier name = desc.getName(); final String code = name.getCode(); for (final GeneralParameterDescriptor descriptor : descriptors) { if (IdentifiedObjects.isHeuristicMatchForName(descriptor, code)) { throw new IllegalArgumentException(Resources.format( Resources.Keys.MismatchedParameterDescriptor_1, name)); } } throw new InvalidParameterNameException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), code); } }
/** * Set the specified parameter to the specified value, if not null. */ private static void setParameterValue(final ParameterValueGroup parameters, String name, Object value) throws InvalidParameterNameException { if (value != null) try { parameters.parameter(name).setValue(value); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException( Errors.format(ErrorKeys.UNKNOW_PARAMETER_NAME_$1, name), name); exception.initCause(cause); throw exception; } } }
/** * Verifies the given descriptor exists in the {@link DefaultParameterDescriptorGroup#descriptors()} list. */ final void ensureDescriptorExists(final GeneralParameterDescriptor desc) { final List<GeneralParameterDescriptor> descriptors = descriptor.descriptors(); if (!descriptors.contains(desc)) { /* * For a more accurate error message, check if the operation failed because the * parameter name was not found, or the parameter descriptor does not matches. */ final Identifier name = desc.getName(); final String code = name.getCode(); for (final GeneralParameterDescriptor descriptor : descriptors) { if (IdentifiedObjects.isHeuristicMatchForName(descriptor, code)) { throw new IllegalArgumentException(Resources.format( Resources.Keys.MismatchedParameterDescriptor_1, name)); } } throw new InvalidParameterNameException(Resources.format(Resources.Keys.ParameterNotFound_2, Verifier.getDisplayName(descriptor), name), code); } }
target = destination.parameter(name); } catch (ParameterNotFoundException cause) { throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format( Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);
/** * Ensures that the given name array does not contain duplicate values. * * @param properties the properties given to the constructor, or {@code null} if unknown. */ private static void verifyNames(final Map<String,?> properties, final GeneralParameterDescriptor[] parameters) { for (int i=0; i<parameters.length; i++) { final GeneralParameterDescriptor parameter = parameters[i]; ArgumentChecks.ensureNonNullElement("parameters", i, parameter); final String name = parameter.getName().getCode(); for (int j=0; j<i; j++) { if (IdentifiedObjects.isHeuristicMatchForName(parameters[j], name)) { throw new InvalidParameterNameException(Resources.forProperties(properties).getString( Resources.Keys.DuplicatedParameterName_4, Verifier.getDisplayName(parameters[j]), j, name, i), name); } } } }
target = destination.parameter(name); } catch (ParameterNotFoundException cause) { throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format( Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);
value = "(group)"; throw new InvalidParameterNameException(Errors.format( Errors.Keys.IllegalArgument_2, name, value), name);
throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format( Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);
/** * Ensures that the given name array does not contain duplicate values. * * @param properties the properties given to the constructor, or {@code null} if unknown. */ private static void verifyNames(final Map<String,?> properties, final GeneralParameterDescriptor[] parameters) { for (int i=0; i<parameters.length; i++) { final GeneralParameterDescriptor parameter = parameters[i]; ArgumentChecks.ensureNonNullElement("parameters", i, parameter); final String name = parameter.getName().getCode(); for (int j=0; j<i; j++) { if (IdentifiedObjects.isHeuristicMatchForName(parameters[j], name)) { throw new InvalidParameterNameException(Resources.forProperties(properties).getString( Resources.Keys.DuplicatedParameterName_4, Verifier.getDisplayName(parameters[j]), j, name, i), name); } } } }
throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format( Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);