use of org.opengis.util.InternationalString in project sis by apache.
the class Citations method titleMatches.
/**
* Returns {@code true} if the two citations have at least one title in common,
* ignoring case and non-alphanumeric characters.
* See {@link org.apache.sis.metadata.iso.citation.Citations#titleMatches(Citation, Citation)}
* for the public documentation of this method.
*
* @param c1 the first citation to compare, or {@code null}.
* @param c2 the second citation to compare, or {@code null}.
* @return {@code true} if both arguments are non-null, and at least one title or alternate title matches.
*/
public static boolean titleMatches(final Citation c1, final Citation c2) {
if (c1 != null && c2 != null) {
if (c1 == c2) {
// Optimisation for a common case.
return true;
}
InternationalString candidate = c2.getTitle();
Iterator<? extends InternationalString> iterator = null;
do {
if (candidate != null) {
final String unlocalized = candidate.toString(Locale.ROOT);
if (titleMatches(c1, unlocalized)) {
return true;
}
final String localized = candidate.toString();
if (// Slight optimization for a common case.
!Objects.equals(localized, unlocalized) && titleMatches(c1, localized)) {
return true;
}
}
if (iterator == null) {
iterator = iterator(c2.getAlternateTitles());
if (iterator == null)
break;
}
if (!iterator.hasNext())
break;
candidate = iterator.next();
} while (true);
}
return false;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class Citations method titleMatches.
/**
* Returns {@code true} if the given citation has at least one title equals to the given string,
* ignoring case and non-alphanumeric characters.
* See {@link org.apache.sis.metadata.iso.citation.Citations#titleMatches(Citation, String)}
* for the public documentation of this method.
*
* @param citation the citation to check for, or {@code null}.
* @param title the title or alternate title to compare, or {@code null}.
* @return {@code true} if both arguments are non-null, and the title or an alternate
* title matches the given string.
*/
public static boolean titleMatches(final Citation citation, final CharSequence title) {
if (citation != null && title != null) {
InternationalString candidate = citation.getTitle();
Iterator<? extends InternationalString> iterator = null;
do {
if (candidate != null) {
final String unlocalized = candidate.toString(Locale.ROOT);
if (equalsFiltered(unlocalized, title)) {
return true;
}
final String localized = candidate.toString();
if (// Slight optimization for a common case.
!Objects.equals(localized, unlocalized) && equalsFiltered(localized, title)) {
return true;
}
}
if (iterator == null) {
iterator = iterator(citation.getAlternateTitles());
if (iterator == null)
break;
}
if (!iterator.hasNext())
break;
candidate = iterator.next();
} while (true);
}
return false;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class MetadataBuilder method addKeywords.
/**
* Adds keywords if at least one non-empty element exists in the {@code keywords} array.
* Other arguments have no impact on whether keywords are added or not because only the
* {@code MD_Keywords.keyword} property is mandatory.
* Storage locations are:
*
* <ul>
* <li>{@code metadata/identificationInfo/descriptiveKeywords}</li>
* <li>{@code metadata/identificationInfo/thesaurusName/title}</li>
* <li>{@code metadata/identificationInfo/type}</li>
* </ul>
*
* @param keywords word(s) used to describe the subject, or {@code null} for no-operation.
* @param type subject matter used to group similar keywords, or {@code null} if none.
* @param thesaurusName name of the formally registered thesaurus, or {@code null} if none.
*/
public final void addKeywords(final Iterable<? extends CharSequence> keywords, final KeywordType type, final CharSequence thesaurusName) {
if (keywords != null) {
DefaultKeywords group = null;
Collection<InternationalString> list = null;
for (final CharSequence kw : keywords) {
final InternationalString i18n = trim(kw);
if (i18n != null) {
if (list == null) {
group = new DefaultKeywords();
group.setType(type);
group.setThesaurusName(sharedCitation(trim(thesaurusName)));
list = group.getKeywords();
}
list.add(i18n);
}
}
if (group != null) {
addIfNotPresent(identification().getDescriptiveKeywords(), group);
}
}
}
use of org.opengis.util.InternationalString in project sis by apache.
the class MetadataBuilder method addProcessDescription.
/**
* Adds additional details about the process step.
* If a description already exists, the new one will be added on a new line.
* Storage location is:
*
* <ul>
* <li>{@code metadata/resourceLineage/processStep/description}</li>
* </ul>
*
* @param description additional details about the process step, or {@code null} for no-operation.
*/
public final void addProcessDescription(final CharSequence description) {
final InternationalString i18n = trim(description);
if (i18n != null) {
final DefaultProcessStep ps = processStep();
ps.setDescription(append(ps.getDescription(), i18n));
}
}
use of org.opengis.util.InternationalString in project sis by apache.
the class MetadataBuilder method addTitle.
/**
* Adds a title or alternate title of the resource.
* Storage location is:
*
* <ul>
* <li>{@code metadata/identificationInfo/citation/title} if not yet used</li>
* <li>{@code metadata/identificationInfo/citation/alternateTitle} otherwise</li>
* </ul>
*
* @param title the resource title or alternate title, or {@code null} for no-operation.
*
* @see #addAbstract(CharSequence)
*/
public final void addTitle(final CharSequence title) {
final InternationalString i18n = trim(title);
if (i18n != null) {
final DefaultCitation citation = citation();
final InternationalString current = citation.getTitle();
if (current == null) {
citation.setTitle(i18n);
} else if (!equals(current, i18n)) {
addIfNotPresent(citation.getAlternateTitles(), i18n);
}
}
}
Aggregations