Java Code Examples for org.opengis.parameter.GeneralParameterDescriptor#getMinimumOccurs()
The following examples show how to use
org.opengis.parameter.GeneralParameterDescriptor#getMinimumOccurs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterValueList.java From sis with Apache License 2.0 | 6 votes |
/** * 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()); } }
Example 2
Source File: ParameterValueList.java From sis with Apache License 2.0 | 5 votes |
/** * 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)); } } }
Example 3
Source File: CC_GeneralOperationParameter.java From sis with Apache License 2.0 | 4 votes |
/** * Returns a descriptor with the same properties than the {@code provided} one, but completed with information * not found in GML. Those missing information are given by the {@code complete} descriptor, which may come from * two sources: * * <ul> * <li>The descriptor for a {@code <gml:ParameterValue>} element. Those descriptors are more complete than the * ones provided by {@code <gml:OperationParameter>} elements alone because the parameter value allows SIS * to infer the {@code valueClass}.</li> * <li>A pre-defined parameter descriptor from the {@link org.apache.sis.internal.referencing.provider} package.</li> * </ul> * * @param provided the descriptor unmarshalled from the GML document. * @param complete the descriptor to use for completing missing information. * @return the descriptor to use. May be one of the arguments given to this method, or a new instance. * * @see <a href="http://issues.apache.org/jira/browse/SIS-290">SIS-290</a> */ static GeneralParameterDescriptor merge(final GeneralParameterDescriptor provided, final GeneralParameterDescriptor complete) { if (provided == complete) { return complete; } final boolean isGroup; if (provided instanceof ParameterDescriptor<?> && complete instanceof ParameterDescriptor<?>) { isGroup = false; // This is by far the most usual case. } else if (provided instanceof ParameterDescriptorGroup && complete instanceof ParameterDescriptorGroup) { isGroup = true; } else { /* * Mismatched or unknown type. It should not happen with descriptors parsed by JAXB and with * pre-defined descriptors provided by SIS. But it could happen with a pre-defined descriptor * found in a user-provided OperationMethod with malformed parameters. * Return the descriptor found in the GML document as-is. */ return provided; } final int minimumOccurs = provided.getMinimumOccurs(); final int maximumOccurs = provided.getMaximumOccurs(); final Map<String,?> expected = IdentifiedObjects.getProperties(complete); final Map<String,?> actual = IdentifiedObjects.getProperties(provided, IGNORE_DURING_MERGE); final boolean canSubstitute = complete.getMinimumOccurs() == minimumOccurs && complete.getMaximumOccurs() == maximumOccurs && expected.entrySet().containsAll(actual.entrySet()) && containsAll(complete.getAlias(), provided.getAlias()) && containsAll(complete.getIdentifiers(), provided.getIdentifiers()); if (canSubstitute && !isGroup) { /* * The pre-defined or ParameterValue descriptor contains at least all the information found * in the descriptor parsed from the GML document. We can use the existing instance directly, * assuming that the additional properties are acceptable. * * We make an exception to the above rule if the existing instance put a possibly too strong * restriction on the parameter values. See 'isRestricted(…)' for more information. */ if (!isRestricted((ParameterDescriptor<?>) complete)) { return complete; } } /* * Collect the properties specified in the GML document and complete with the properties provided * by the 'complete' descriptor. If the descriptor is a group, then this 'replacement' method will * be invoked recursively for each parameter in the group. */ final Map<String,Object> merged = new HashMap<>(expected); merged.putAll(actual); // May overwrite pre-defined properties. mergeArrays(GeneralParameterDescriptor.ALIAS_KEY, GenericName.class, provided.getAlias(), merged, complete.getName()); mergeArrays(GeneralParameterDescriptor.IDENTIFIERS_KEY, ReferenceIdentifier.class, provided.getIdentifiers(), merged, null); if (isGroup) { final List<GeneralParameterDescriptor> descriptors = ((ParameterDescriptorGroup) provided).descriptors(); return merge(DefaultParameterValueGroup.class, merged, merged, minimumOccurs, maximumOccurs, descriptors.toArray(new GeneralParameterDescriptor[descriptors.size()]), (ParameterDescriptorGroup) complete, canSubstitute); } else { return create(merged, (ParameterDescriptor<?>) provided, (ParameterDescriptor<?>) complete); } }
Example 4
Source File: ParameterBuilder.java From sis with Apache License 2.0 | 3 votes |
/** * 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; } }