use of org.opengis.metadata.Identifier in project sis by apache.
the class ParameterTableRow method writeIdentifiers.
/**
* Writes the identifiers. At most one of {@code colors != null} and {@code colorsForRows}
* can be {@code true}.
*
* <p><b>This method can be invoked only once per {@code ParameterTableRow} instance</b>,
* as its implementation destroys the internal list of identifiers.</p>
*
* @param out where to write.
* @param writeCodespaces {@code true} for writing codespaces, or {@code false} for omitting them.
* @param colors non-null if syntax coloring should be applied for table title.
* @param colorsForRows {@code true} if syntax coloring should be applied for table rows.
* @param lineSeparator the system-dependent line separator.
* @throws IOException if an exception occurred while writing.
*/
final void writeIdentifiers(final Appendable out, final boolean writeCodespaces, final Colors colors, final boolean colorsForRows, final String lineSeparator) throws IOException {
if (codespaceWidth != 0) {
// Add a colon and space between codespace and code in e.g. "OGC: Mercator".
codespaceWidth += 2;
}
boolean isNewLine = false;
for (final Map.Entry<String, Set<Object>> entry : identifiers.entrySet()) {
final String codespace = entry.getKey();
final Set<Object> identifiers = entry.getValue();
Iterator<Object> it = identifiers.iterator();
while (it.hasNext()) {
if (isNewLine) {
out.append(lineSeparator);
}
isNewLine = true;
/*
* Write the codespace. More than one name may exist for the same codespace,
* in which case the code space will be repeated on a new line each time.
*/
writeColor(out, colors, ElementKind.NAME);
if (writeCodespaces) {
int pad = codespaceWidth;
if (codespace != null) {
writeColor(out, FAINT, colorsForRows);
out.append(codespace).append(DEFAULT_SEPARATOR);
writeColor(out, NORMAL, colorsForRows);
pad -= (codespace.length() + 1);
}
out.append(spaces(pad));
}
/*
* Write the name or alias after the codespace. We remove what we wrote,
* because we may iterate over the 'identifiers' set more than once.
*/
writeColor(out, BOLD, colors != null);
out.append(toString(it.next()));
writeColor(out, RESET, colors != null);
it.remove();
/*
* Write the footnote number if there is a remark associated to this parameter.
* We write the remark only for the first name or identifier.
*/
if (remarks != 0) {
writeFootnoteNumber(out, remarks);
remarks = 0;
}
/*
* Write all identifiers between parenthesis after the firt name only.
* Aliases (to be written in a new iteration) will not have identifier.
*/
boolean hasAliases = false;
boolean hasIdentifiers = false;
while (it.hasNext()) {
final Object id = it.next();
if (id instanceof Identifier) {
out.append(hasIdentifiers ? ", " : " (");
writeColor(out, colors, ElementKind.IDENTIFIER);
out.append(toString(id));
writeColor(out, FOREGROUND_DEFAULT, colors != null);
hasIdentifiers = true;
it.remove();
} else {
hasAliases = true;
}
}
if (hasIdentifiers) {
out.append(')');
}
if (hasAliases) {
it = identifiers.iterator();
}
}
}
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class ParameterValueList method ensureDescriptorExists.
/**
* 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);
}
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class ParameterValueList method ensureCanRemove.
/**
* 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());
}
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class Parameters method getName.
/**
* Returns the name or alias of the given parameter for the authority code space expected by this group.
* If no name or alias for this group's authority can be found, then the primary name will be returned.
*
* @param source the parameter for which the name is wanted.
* @return the name of the given parameter. May be {@code null} if there is no name at all,
* but such nameless descriptors are not legal.
*/
private String getName(final GeneralParameterDescriptor source) {
final ParameterDescriptorGroup descriptor = getDescriptor();
if (descriptor != null) {
// Paranoiac check (should never be null)
final Identifier group = descriptor.getName();
if (group != null) {
// Paranoiac check (should never be null)
final Citation authority = group.getAuthority();
final String name = IdentifiedObjects.getName(source, authority);
if (name != null || authority == null) {
return name;
}
}
}
return IdentifiedObjects.getName(source, null);
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class GeoKeysTest method verifyParameterNames.
/**
* Verifies that parameter names registered in the {@link org.apache.sis.internal.referencing.provider} package
* match the name of fields listed in {@link GeoKeys}.
*/
@Test
@DependsOnMethod("testName")
public void verifyParameterNames() {
final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
for (final OperationMethod method : factory.getAvailableMethods(SingleOperation.class)) {
for (final GeneralParameterDescriptor param : method.getParameters().descriptors()) {
final Identifier identifier = IdentifiedObjects.getIdentifier(param, Citations.GEOTIFF);
final Set<String> names = IdentifiedObjects.getNames(param, Citations.GEOTIFF);
/*
* If there is no GeoTIFF identifiers, we should have no GeoTIFF name neither.
*/
assertEquals(param.getName().getCode(), identifier == null, names.isEmpty());
if (identifier != null) {
final int code = Short.parseShort(identifier.getCode());
for (final String name : names) {
assertEquals(name, code(name), code);
}
}
}
}
}
Aggregations