Java Code Examples for org.opengis.parameter.GeneralParameterDescriptor#getName()
The following examples show how to use
org.opengis.parameter.GeneralParameterDescriptor#getName() .
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: Verifier.java From sis with Apache License 2.0 | 5 votes |
/** * Convenience method returning the name of the specified descriptor. * This method is used mostly for output to be read by human, not for processing. * Consequently, we may consider to returns a localized name in a future version. * * <p>This method is null-safe even if none of the references checked here should be null. * We make this method safe because it is indirectly invoked by methods like {@code toString()} * which are not expected to fail even if the object is invalid.</p> * * <p><b>This method should NOT be invoked for programmatic usage</b> (e.g. setting a parameter * value) because the string returned in case of invalid descriptor is arbitrary.</p> */ static String getDisplayName(final GeneralParameterDescriptor descriptor) { if (descriptor != null) { final Identifier name = descriptor.getName(); if (name != null) { final String code = name.getCode(); if (code != null) { return code; } } } return Vocabulary.format(Vocabulary.Keys.Unnamed); }
Example 3
Source File: ParameterValueList.java From sis with Apache License 2.0 | 5 votes |
/** * Adds a {@link ParameterValue} or an other {@link ParameterValueGroup} to this list. * If an existing parameter is already included for the same name and adding the new * parameter would increase the number past what is allowable by {@code maximumOccurs}, * then an {@link InvalidParameterCardinalityException} will be thrown. * * @param parameter new parameter to be added to this group. * @return always {@code true} since this object changes as a result of this call. * @throws IllegalArgumentException if the specified parameter is not allowable by the groups descriptor. * @throws InvalidParameterCardinalityException if adding this parameter would result in more parameters * than allowed by {@code maximumOccurs}. */ @Override public boolean add(final GeneralParameterValue parameter) { ArgumentChecks.ensureNonNull("parameter", parameter); final GeneralParameterDescriptor desc = parameter.getDescriptor(); ensureDescriptorExists(desc); /* * If we had an uninitialized parameter (a parameter created by the DefaultParameterValueGroup constructor * and never been queried or set by the user), then the given parameter will replace the uninitialized. * The intent is to allow users to set its own parameters by a call to group.values().addAll(myParam). * Otherwise the given parameter will be added, in which case we need to check the cardinality. */ final Identifier name = desc.getName(); int count = 0; for (int i=0; i<size; i++) { final GeneralParameterValue value = values[i]; if (name.equals(value.getDescriptor().getName())) { if (value instanceof UninitializedParameter) { values[i] = parameter; return true; } count++; } } final int max = desc.getMaximumOccurs(); if (count >= max) { throw new InvalidParameterCardinalityException(Errors.format( Errors.Keys.TooManyOccurrences_2, max, name), name.getCode()); } addUnchecked(parameter); modCount++; return true; }
Example 4
Source File: ParameterValueList.java From sis with Apache License 2.0 | 5 votes |
/** * Verifies if adding a parameter with the given descriptor is allowed by the cardinality constraints. If adding * the parameter would result in more occurrences than {@link DefaultParameterDescriptor#getMaximumOccurs()}, * then this method throws an {@link InvalidParameterCardinalityException}. */ private void ensureCanAdd(final GeneralParameterDescriptor desc) { final Identifier name = desc.getName(); int count = 0; for (int i=0; i<size; i++) { if (name.equals(values[i].getDescriptor().getName())) { count++; } } final int max = desc.getMaximumOccurs(); if (count >= max) { throw new InvalidParameterCardinalityException(Errors.format( Errors.Keys.TooManyOccurrences_2, max, name), name.getCode()); } }
Example 5
Source File: ProvidersTest.java From sis with Apache License 2.0 | 4 votes |
/** * Ensures that every parameter instance is unique. Actually this test is not strong requirement. * This is only for sharing existing resources by avoiding unnecessary objects duplication. * * @throws ReflectiveOperationException if the instantiation of a service provider failed. */ @Test public void ensureParameterUniqueness() throws ReflectiveOperationException { final Map<GeneralParameterDescriptor, String> groupNames = new IdentityHashMap<>(); final Map<GeneralParameterDescriptor, GeneralParameterDescriptor> parameters = new HashMap<>(); final Map<Object, Object> namesAndIdentifiers = new HashMap<>(); for (final Class<?> c : methods()) { final OperationMethod method = (OperationMethod) c.getConstructor((Class[]) null).newInstance((Object[]) null); final ParameterDescriptorGroup group = method.getParameters(); final String operationName = group.getName().getCode(); for (final GeneralParameterDescriptor param : group.descriptors()) { assertFalse("Parameter declared twice in the same group.", operationName.equals(groupNames.put(param, operationName))); /* * Ensure uniqueness of the parameter descriptor as a whole. */ final Identifier name = param.getName(); Object existing = parameters.put(param, param); if (existing != null && existing != param) { fail("Parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined in “" + groupNames.get(existing) + "”." + " The same instance could be shared."); } /* * Ensure uniqueness of each name and identifier. */ existing = namesAndIdentifiers.put(name, name); if (existing != null && existing != name) { fail("The name of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared."); } for (final GenericName alias : param.getAlias()) { existing = namesAndIdentifiers.put(alias, alias); if (existing != null && existing != alias) { fail("Alias “" + alias + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared."); } } for (final Identifier id : param.getIdentifiers()) { existing = namesAndIdentifiers.put(id, id); if (existing != null && existing != id) { fail("Identifier “" + id + "” of parameter “" + name.getCode() + "” defined in “" + operationName + '”' + " was already defined elsewhere. The same instance could be shared."); } } } } }
Example 6
Source File: WKTUtilities.java From sis with Apache License 2.0 | 3 votes |
/** * Returns {@code true} if the given parameter is defined in the EPSG code space. We handle EPSG * parameters in a special way because Apache SIS uses the EPSG geodetic dataset as the primary * source of coordinate operation definitions. * * <p>We intentionally don't define {@code isEPSG(OperationMethod)} method because the operation * method may be the inverse of an EPSG method (for example "Inverse of Mercator (variant A)") * which would not be recognized. Instead, {@code isEPSG(method.getParameters())} should work.</p> * * @param descriptor the parameter or group of parameters to inspect. * @param ifUndefined the value to return if the code space is undefined. * @return whether the given parameter is an EPSG parameter. */ public static boolean isEPSG(final GeneralParameterDescriptor descriptor, final boolean ifUndefined) { if (descriptor != null) { final ReferenceIdentifier id = descriptor.getName(); if (id != null) { final String cs = id.getCodeSpace(); if (cs != null) { return Constants.EPSG.equalsIgnoreCase(cs); } } } return ifUndefined; }
Example 7
Source File: CC_GeneralOperationParameter.java From sis with Apache License 2.0 | 2 votes |
/** * Verifies that the given descriptor is non-null and contains at least a name. * This method is used after unmarshalling. */ static boolean isValid(final GeneralParameterDescriptor descriptor) { return descriptor != null && descriptor.getName() != null; }