/** * Makes sure that an argument is non-null. This is a convenience method for subclass methods. * * @param name Argument name. * @param object User argument. * @throws InvalidParameterValueException if {@code object} is null. */ protected static void ensureNonNull(final String name, final Object object) throws InvalidParameterValueException { if (object == null) { throw new InvalidParameterValueException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name), name, object); } }
err.print(Errors.format(ErrorKeys.IN_$1, exception.getParameterName())); err.print(' '); err.println(exception.getLocalizedMessage());
} catch (ClassCastException exception) { InvalidParameterValueException e = new InvalidParameterValueException( Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, key, value), key, value); e.initCause(exception); throw e;
fail("setValue(> max)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Bounded param")); assertEquals("Bounded param", exception.getParameterName()); fail("setValue(< min)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Bounded param")); assertEquals("Bounded param", exception.getParameterName()); fail("setValue(double)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Integer")); assertEquals("Bounded param", exception.getParameterName()); fail("setValue(double,Unit)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Bounded param")); assertEquals("Bounded param", exception.getParameterName());
} catch (InvalidParameterValueException exception) { assertEquals("Test", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Test", exception.getParameterName());
new String[] {e.getParameterName()}, param.offset).initCause(e); } catch (InvalidParameterValueException e) { throw (ParseException) new ParseException(e.getLocalizedMessage(), param.offset).initCause(e);
} catch (InvalidParameterValueException exception) { assertEquals("Bounded param", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Bounded param", exception.getParameterName()); fail("setValue(String)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Bounded param")); assertEquals("Bounded param", exception.getParameterName());
} catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName());
new String[] {e.getParameterName()}, param.offset).initCause(e); } catch (InvalidParameterValueException e) { throw (ParseException) new ParseException(e.getLocalizedMessage(), param.offset).initCause(e);
/** * Makes sure that an argument is non-null. This is a convenience method for subclass * constructors. * * @param name Argument name. * @param object User argument. * @throws InvalidParameterValueException if {@code object} is null. */ protected static void ensureNonNull(final String name, final Object object) throws InvalidParameterValueException { if (object == null) { throw new InvalidParameterValueException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name), name, object); } }
} catch (ClassCastException exception) { InvalidParameterValueException e = new InvalidParameterValueException( Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, key, value), key, value); e.initCause(exception); throw e;
fail("setValue(AxisDirection.UP)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Direction")); assertTrue(message, message.contains("Geocentric X")); assertEquals("Direction", exception.getParameterName()); fail("setValue(VerticalDatumType)"); } catch (InvalidParameterValueException exception) { final String message = exception.getMessage(); assertTrue(message, message.contains("Direction")); assertTrue(message, message.contains("VerticalDatumType")); assertTrue(message, message.contains("AxisDirection")); assertEquals("Direction", exception.getParameterName());
} catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Range", exception.getParameterName());
/** * Makes sure that an argument is non-null. This is a convenience method for subclass * constructors. * * @param name Argument name. * @param object User argument. * @throws InvalidParameterValueException if {@code object} is null. */ protected static void ensureNonNull(final String name, final Object object) throws InvalidParameterValueException { if (object == null) { throw new InvalidParameterValueException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name), name, object); } }
/** * Sets the parameter value as a floating point and its associated unit. * * <p>The default implementation wraps the given number in an object of the type specified by the * {@linkplain #getDescriptor() descriptor}, then delegates to {@link #setValue(Object, Unit)}.</p> * * @param newValue the parameter value. * @param unit the unit for the specified value. * @throws InvalidParameterValueException if the floating point type is inappropriate for this parameter, * or if the value is illegal for some other reason (for example a value out of range). * * @see #setValue(double) * @see #doubleValue(Unit) */ @Override public void setValue(final double newValue, final Unit<?> unit) throws InvalidParameterValueException { try { setValue(wrap(newValue, descriptor.getValueClass()), unit); } catch (InvalidParameterValueException e) { throw e; // Need to be thrown explicitely because it is a subclass of IllegalArgumentException. } catch (IllegalArgumentException e) { throw (InvalidParameterValueException) new InvalidParameterValueException( e.getLocalizedMessage(), Verifier.getDisplayName(descriptor), newValue).initCause(e); } }
} catch (InvalidParameterValueException exception) { assertEquals("Test", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Test", exception.getParameterName()); } catch (InvalidParameterValueException exception) { assertEquals("Test", exception.getParameterName());
/** * Makes sure an array element is non-null. This is a convenience method for subclass * constructors. * * @param name Argument name. * @param array User argument. * @param index Index of the element to check. * @throws InvalidParameterValueException if {@code array[i]} is null. */ protected static void ensureNonNull(final String name, final Object[] array, final int index) throws InvalidParameterValueException { if (array[index] == null) { throw new InvalidParameterValueException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name + '[' + index + ']'), name, array); } }
/** * Sets the parameter value as a floating point and its associated unit. * * <p>The default implementation wraps the given number in an object of the type specified by the * {@linkplain #getDescriptor() descriptor}, then delegates to {@link #setValue(Object, Unit)}.</p> * * @param newValue the parameter value. * @param unit the unit for the specified value. * @throws InvalidParameterValueException if the floating point type is inappropriate for this parameter, * or if the value is illegal for some other reason (for example a value out of range). * * @see #setValue(double) * @see #doubleValue(Unit) */ @Override public void setValue(final double newValue, final Unit<?> unit) throws InvalidParameterValueException { try { setValue(wrap(newValue, descriptor.getValueClass()), unit); } catch (InvalidParameterValueException e) { throw e; // Need to be thrown explicitly because it is a subclass of IllegalArgumentException. } catch (IllegalArgumentException e) { throw (InvalidParameterValueException) new InvalidParameterValueException( e.getLocalizedMessage(), Verifier.getDisplayName(descriptor), newValue).initCause(e); } }
fail("setValue(< min)"); } catch (InvalidParameterValueException exception) { assertEquals("Length measure", exception.getParameterName()); fail("setValue(> max)"); } catch (InvalidParameterValueException exception) { assertEquals("Length measure", exception.getParameterName()); fail("setValue(Sring)"); } catch (InvalidParameterValueException exception) { assertEquals("Length measure", exception.getParameterName());
/** * Makes sure an argument is non-null. This is method duplicate {@link * AbstractIdentifiedObject#ensureNonNull(String, Object)} except for the more accurate stack * trace. It is duplicated there in order to avoid a dependency to {@link * AbstractIdentifiedObject}. * * @param name Argument name. * @param object User argument. * @throws InvalidParameterValueException if {@code object} is null. */ private static void ensureNonNull(final String name, final Object object) throws IllegalArgumentException { if (object == null) { throw new InvalidParameterValueException( Errors.format(ErrorKeys.NULL_ARGUMENT_$1, name), name, object); } }