/** * Constructs a descriptor with the same values than the specified one. This copy constructor * may be used in order to wraps an arbitrary implementation into a Geotools one. * * @since 2.2 */ protected AbstractParameterDescriptor(final GeneralParameterDescriptor descriptor) { super(descriptor); minimumOccurs = descriptor.getMinimumOccurs(); }
/** * Forward the call to the {@linkplain MatrixParameterDescriptors matrix parameter descriptors} * specified at construction time. */ public int getMinimumOccurs() { return descriptor.getMinimumOccurs(); }
/** * Constructs a parameter group from the specified descriptor. All {@linkplain #values parameter * values} will be initialized to their default value. * * @param descriptor The descriptor for this group. */ public ParameterGroup(final ParameterDescriptorGroup descriptor) { super(descriptor); final List<GeneralParameterDescriptor> parameters = descriptor.descriptors(); values = new ArrayList<GeneralParameterValue>(parameters.size()); for (final GeneralParameterDescriptor element : parameters) { for (int count = element.getMinimumOccurs(); --count >= 0; ) { final GeneralParameterValue value = element.createValue(); ensureNonNull("createValue", value); values.add(value); } } }
final GeneralParameterDescriptor descriptor = entry.getKey(); final int count = entry.getValue()[0]; final int min = descriptor.getMinimumOccurs(); final int max = descriptor.getMaximumOccurs(); if (!(count >= min && count <= max)) {
/** * Remove the value at the specified index. * * @param type The descriptor of the value to remove. * @param index The index of the value to remove. */ private GeneralParameterValue remove(final GeneralParameterDescriptor type, final int index) { modCount++; int count = 0; final String name = type.getName().getCode(); for (final GeneralParameterValue value : values) { if (AbstractIdentifiedObject.nameMatches(value.getDescriptor(), name)) { count++; } } final int min = type.getMinimumOccurs(); if (count <= min) { final int max = type.getMaximumOccurs(); throw new InvalidParameterCardinalityException( Errors.format( ErrorKeys.ILLEGAL_OCCURS_FOR_PARAMETER_$4, name, count - 1, min, max), name); } final GeneralParameterValue value = values.remove(index); assert value != null && type.equals(value.getDescriptor()) : value; return value; } }
/** * Creates a new builder initialized to properties of the given object. * * @param descriptor the descriptor from which to inherit properties, or {@code null}. * * @since 0.6 */ public ParameterBuilder(final GeneralParameterDescriptor descriptor) { super(descriptor); if (descriptor != null) { required = descriptor.getMinimumOccurs() != 0; } }
/** * Creates a new builder initialized to properties of the given object. * * @param descriptor the descriptor from which to inherit properties, or {@code null}. * * @since 0.6 */ public ParameterBuilder(final GeneralParameterDescriptor descriptor) { super(descriptor); if (descriptor != null) { required = descriptor.getMinimumOccurs() != 0; } }
/** * Adds all mandatory parameters to this list. This method can been invoked only after * construction or after a call to {@link #clear()}. */ private void initialize(final List<GeneralParameterDescriptor> elements) { for (final GeneralParameterDescriptor child : elements) { for (int count=child.getMinimumOccurs(); --count>=0;) { addUnchecked(new UninitializedParameter(child)); } } }
/** * Adds all mandatory parameters to this list. This method can been invoked only after * construction or after a call to {@link #clear()}. */ private void initialize(final List<GeneralParameterDescriptor> elements) { for (final GeneralParameterDescriptor child : elements) { for (int count=child.getMinimumOccurs(); --count>=0;) { addUnchecked(new UninitializedParameter(child)); } } }
/** * Constructs a parameter group from the specified descriptor. * All {@linkplain #values parameter values} will be initialized * to their default value. * * @param descriptor The descriptor for this group. */ public ParameterGroup(final ParameterDescriptorGroup descriptor) { super(descriptor); final List<GeneralParameterDescriptor> parameters = descriptor.descriptors(); values = new ArrayList<>(parameters.size()); for (final GeneralParameterDescriptor element : parameters) { for (int count=element.getMinimumOccurs(); --count>=0;) { final GeneralParameterValue value = element.createValue(); ensureNonNull("createValue", value); values.add(value); } } }
/** * Constructs a new parameter descriptor with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one or a * user-defined one (as a subclass), usually in order to leverage some implementation-specific API. * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * * @param descriptor the object to shallow copy. */ protected AbstractParameterDescriptor(final GeneralParameterDescriptor descriptor) { super(descriptor); minimumOccurs = crop(descriptor.getMinimumOccurs()); maximumOccurs = crop(descriptor.getMaximumOccurs()); }
/** * Constructs a new parameter descriptor with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one or a * user-defined one (as a subclass), usually in order to leverage some implementation-specific API. * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * * @param descriptor the object to shallow copy. */ protected AbstractParameterDescriptor(final GeneralParameterDescriptor descriptor) { super(descriptor); minimumOccurs = crop(descriptor.getMinimumOccurs()); maximumOccurs = crop(descriptor.getMaximumOccurs()); }
/** * Compares the specified object with this parameter for equality. * * @return {@inheritDoc} */ @Override public boolean equals(final Object object, final ComparisonMode mode) { if (super.equals(object, mode)) { switch (mode) { case STRICT: { final AbstractParameterDescriptor that = (AbstractParameterDescriptor) object; return minimumOccurs == that.minimumOccurs && maximumOccurs == that.maximumOccurs; } default: { final GeneralParameterDescriptor that = (GeneralParameterDescriptor) object; return getMinimumOccurs() == that.getMinimumOccurs() && getMaximumOccurs() == that.getMaximumOccurs(); } } } return false; }
/** * Verifies if removing the given value is allowed by the cardinality constraints. If removing the parameter * would result in less occurrences than {@link DefaultParameterDescriptor#getMinimumOccurs()}, * then this method throws an {@link InvalidParameterCardinalityException}. */ private void ensureCanRemove(final GeneralParameterDescriptor desc) { final int min = desc.getMinimumOccurs(); if (min != 0) { // Optimization for a common case. final Identifier name = desc.getName(); int count = 0; for (int i=0; i<size; i++) { if (name.equals(values[i].getDescriptor().getName())) { if (++count > min) { return; } } } throw new InvalidParameterCardinalityException(Errors.format( Errors.Keys.TooFewOccurrences_2, min, name), name.getCode()); } }
/** * Compares the specified object with this parameter for equality. * * @return {@inheritDoc} */ @Override public boolean equals(final Object object, final ComparisonMode mode) { if (super.equals(object, mode)) { switch (mode) { case STRICT: { final AbstractParameterDescriptor that = (AbstractParameterDescriptor) object; return minimumOccurs == that.minimumOccurs && maximumOccurs == that.maximumOccurs; } default: { final GeneralParameterDescriptor that = (GeneralParameterDescriptor) object; return getMinimumOccurs() == that.getMinimumOccurs() && getMaximumOccurs() == that.getMaximumOccurs(); } } } return false; }
/** * Verifies if removing the given value is allowed by the cardinality constraints. If removing the parameter * would result in less occurrences than {@link DefaultParameterDescriptor#getMinimumOccurs()}, * then this method throws an {@link InvalidParameterCardinalityException}. */ private void ensureCanRemove(final GeneralParameterDescriptor desc) { final int min = desc.getMinimumOccurs(); if (min != 0) { // Optimization for a common case. final Identifier name = desc.getName(); int count = 0; for (int i=0; i<size; i++) { if (name.equals(values[i].getDescriptor().getName())) { if (++count > min) { return; } } } throw new InvalidParameterCardinalityException(Errors.format( Errors.Keys.TooFewOccurrences_2, min, name), name.getCode()); } }
/** * Removes the value at the specified index. * * @param type The descriptor of the value to remove. * @param index The index of the value to remove. */ private GeneralParameterValue remove(final GeneralParameterDescriptor type, final int index) { modCount++; int count = 0; final String name = type.getName().getCode(); for (final GeneralParameterValue value : values) { if (IdentifiedObjects.isHeuristicMatchForName(value.getDescriptor(), name)) { count++; } } final int min = type.getMinimumOccurs(); if (count <= min) { final int max = type.getMaximumOccurs(); throw new InvalidParameterCardinalityException(Errors.format( Errors.Keys.IllegalOccursForParameter_4, name, count-1, min, max), name); } final GeneralParameterValue value = values.remove(index); assert value!=null && type.equals(value.getDescriptor()) : value; return value; } }
/** * Verifies that the given parameter descriptor has the expected EPSG code, name and OGC alias. * * @param code the expected EPSG code. * @param name the expected EPSG name. * @param alias the expected OGC alias. * @param required {@code true} if the parameter should be mandatory, or {@code false} if optional. * @param descriptor the parameter descriptor to verify. */ private static void verifyDescriptor(final int code, final String name, final String alias, final boolean required, final GeneralParameterDescriptor descriptor) { assertEpsgNameAndIdentifierEqual(name, code, descriptor); assertAliasTipEquals(alias, descriptor); assertEquals("maximumOccurs", 1, descriptor.getMaximumOccurs()); assertEquals("minimumOccurs", required ? 1 : 0, descriptor.getMinimumOccurs()); }
/** * Asserts that the primary name of the given parameter is the given name in the EPSG namespace. * Then asserts that the first alias (ignoring other EPSG alias) of the given parameter is the * given name in the OGC namespace. */ private static void assertParamEquals(final String epsgName, final String ogcName, final boolean isMandatory, final GeneralParameterDescriptor actual) { if (epsgName != null) { assertEpsgIdentifierEquals(epsgName, actual.getName()); } else { assertOgcIdentifierEquals(ogcName, actual.getName()); } assertEquals("minimumOccurs", isMandatory ? 1 : 0, actual.getMinimumOccurs()); if (epsgName != null) { for (final GenericName alias : actual.getAlias()) { if (alias instanceof ReferenceIdentifier && ((ReferenceIdentifier) alias).getAuthority() != Citations.EPSG) { assertOgcIdentifierEquals(ogcName, (ReferenceIdentifier) alias); return; } } fail("OGC alias not found."); } }
/** * Verifies the properties of the given member of a {@link DefaultParameterDescriptorGroup}. */ private static void verifyParameter(final GeneralParameterDescriptor complete, final GeneralParameterDescriptor merged, final boolean same, final String remarks) { assertEquals("same", same, merged == complete); assertSame ("name", complete.getName(), merged.getName()); assertEquals("minimumOccurs", 0, merged.getMinimumOccurs()); assertEquals("maximumOccurs", 1, merged.getMaximumOccurs()); assertEquals("valueClass", Integer.class, ((ParameterDescriptor<?>) merged).getValueClass()); assertEquals("remarks", remarks, (remarks == null) ? null : merged.getRemarks().toString()); } }