* Put the first identifier in the first column. If no identifier has a codespace in the list
* supplied by the user, then we will use the first identifier (any codespace) as a fallback.
*/
final Set<ReferenceIdentifier> identifiers = object.getIdentifiers();
if (identifiers != null) { // Paranoiac check.
ReferenceIdentifier identifier = null;
for (final ReferenceIdentifier candidate : identifiers) {
if (candidate != null) { // Paranoiac check.
if (isPreferredCodespace(candidate.getCodeSpace())) {
identifier = candidate;
break; // Format now.
}
if (identifier == null) {
identifier = candidate; // To be used as a fallback if we find nothing better.
}
}
}
if (identifier != null) {
row[0] = IdentifiedObjects.toString(identifier);
hasIdentifiers = true;
}
}
/*
* If the name's codespace is in the list of codespaces asked by the user, add that name
* in the current row and clear the 'name' locale variable. Otherwise, keep the 'name'
* locale variable in case we found no alias to format.
*/
ReferenceIdentifier name = object.getName();
if (name != null) { // Paranoiac check.
final String codespace = name.getCodeSpace();
if (isPreferredCodespace(codespace)) {
row = putIfAbsent(resources, row, columnIndices, codespace, name.getCode());
name = null;
}
}
/*
* Put all aliases having a codespace in the list asked by the user.
*/
final Collection<GenericName> aliases = object.getAlias();
if (aliases != null) { // Paranoiac check.
for (final GenericName alias : aliases) {
if (alias != null) { // Paranoiac check.
final String codespace = NameToIdentifier.getCodespaceOrAuthority(alias, displayLocale);
if (isPreferredCodespace(codespace)) {
row = putIfAbsent(resources, row, columnIndices, codespace,
alias.tip().toInternationalString().toString(displayLocale));
name = null;
}
}
}
}
/*
* If no name and no alias have a codespace in the list of codespaces asked by the user,
* force the addition of primary name regardless its codespace.
*/
if (name != null) {
row = putIfAbsent(resources, row, columnIndices, name.getCodeSpace(), name.getCode());
}
rows.add(row);
}
/*
* Writes the table. The header will contain one column for each codespace in the order declared