use of org.opengis.util.InternationalString in project sis by apache.
the class DefaultInternationalString method add.
/**
* Adds the given character sequence. If the given sequence is an other {@link InternationalString} instance,
* then only the string for the given locale is added. This method is for {@link Types} internal usage only.
*
* @param locale the locale for the {@code string} value.
* @param string the character sequence to add.
* @throws IllegalArgumentException if a different string value was already set for the given locale.
*/
final void add(final Locale locale, final CharSequence string) throws IllegalArgumentException {
final boolean i18n = (string instanceof InternationalString);
add(locale, i18n ? ((InternationalString) string).toString(locale) : string.toString());
if (i18n && !(string instanceof SimpleInternationalString)) {
/*
* If the string may have more than one locale, log a warning telling that some locales
* may have been ignored. We declare Types.toInternationalString(…) as the source since
* it is the public facade invoking this method. We declare the source class using only
* its name rather than Types.class in order to avoid unnecessary real dependency.
*/
final LogRecord record = Messages.getResources(null).getLogRecord(Level.WARNING, Messages.Keys.LocalesDiscarded);
record.setSourceClassName("org.apache.sis.util.iso.Types");
record.setSourceMethodName("toInternationalString");
record.setLoggerName(Modules.UTILITIES);
Logging.getLogger(Modules.UTILITIES).log(record);
}
}
use of org.opengis.util.InternationalString in project sis by apache.
the class DefaultInternationalString method isSubsetOf.
/**
* Returns {@code true} if all localized texts stored in this international string are
* contained in the specified object. More specifically:
*
* <ul>
* <li>If {@code candidate} is an instance of {@link InternationalString}, then this method
* returns {@code true} if, for all <var>{@linkplain Locale locale}</var>-<var>{@linkplain
* String string}</var> pairs contained in {@code this}, <code>candidate.{@linkplain
* InternationalString#toString(Locale) toString}(locale)</code> returns a string
* {@linkplain String#equals equals} to {@code string}.</li>
*
* <li>If {@code candidate} is an instance of {@link CharSequence}, then this method
* returns {@code true} if {@link #toString(Locale)} returns a string {@linkplain
* String#equals equals} to <code>candidate.{@linkplain CharSequence#toString()
* toString()}</code> for all locales.</li>
*
* <li>If {@code candidate} is an instance of {@link Map}, then this methods returns
* {@code true} if all <var>{@linkplain Locale locale}</var>-<var>{@linkplain String
* string}</var> pairs are contained into {@code candidate}.</li>
*
* <li>Otherwise, this method returns {@code false}.</li>
* </ul>
*
* @param candidate the object which may contains this international string.
* @return {@code true} if the given object contains all localized strings found in this international string.
*/
public synchronized boolean isSubsetOf(final Object candidate) {
if (candidate instanceof InternationalString) {
final InternationalString string = (InternationalString) candidate;
for (final Map.Entry<Locale, String> entry : localeMap.entrySet()) {
final Locale locale = entry.getKey();
final String text = entry.getValue();
if (!text.equals(string.toString(locale))) {
return false;
}
}
} else if (candidate instanceof CharSequence) {
final String string = candidate.toString();
for (final String text : localeMap.values()) {
if (!text.equals(string)) {
return false;
}
}
} else if (candidate instanceof Map<?, ?>) {
final Map<?, ?> map = (Map<?, ?>) candidate;
return map.entrySet().containsAll(localeMap.entrySet());
} else {
return false;
}
return true;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class GeoapiAssert method assertAnyTitleEquals.
/**
* Asserts that the title or an alternate title of the given citation is equal to the given string.
* This method is typically used for testing if a citation stands for the OGC, OGP or EPSG authority
* for instance. Such abbreviations are often declared as {@linkplain Citation#getAlternateTitles()
* alternate titles} rather than the main {@linkplain Citation#getTitle() title}, but this method
* tests both for safety.
*
* @param message Header of the exception message in case of failure, or {@code null} if none.
* @param expected The expected title or alternate title.
* @param actual The citation to test.
*/
public static void assertAnyTitleEquals(final String message, final String expected, final Citation actual) {
if (isNull(message, expected, actual)) {
return;
}
InternationalString title = actual.getTitle();
if (title != null && expected.equals(title.toString())) {
return;
}
for (final InternationalString t : actual.getAlternateTitles()) {
if (expected.equals(t.toString())) {
return;
}
}
fail(concat(message, '"' + expected + "\" not found in title or alternate titles."));
}
use of org.opengis.util.InternationalString in project sis by apache.
the class TableColumn method getHeader.
/**
* Returns the text to display as column header.
*
* @return the text to display as column header.
*/
public synchronized InternationalString getHeader() {
CharSequence t = header;
if (t == null || t instanceof InternationalString) {
return (InternationalString) t;
}
final InternationalString i18n = new SimpleInternationalString(t.toString());
header = i18n;
return i18n;
}
use of org.opengis.util.InternationalString in project sis by apache.
the class TreeTables method replaceCharSequences.
/**
* Implementation of the public {@link #replaceCharSequences(TreeTable, Locale)} method.
*
* @param node the node in which to replace values by their string representations.
* @param columns the columns where to perform the replacements.
* @param locale the locale to use when replacing {@link InternationalString} instances. Can be {@code null}.
* @param pool an initially empty pool of string representations, to be filled by this method.
* @return number of replacements done.
*/
private static int replaceCharSequences(final TreeTable.Node node, final TableColumn<? super String>[] columns, final Locale locale, final Map<String, String> pool) {
int changes = 0;
for (final TreeTable.Node child : node.getChildren()) {
changes += replaceCharSequences(child, columns, locale, pool);
}
for (final TableColumn<? super String> column : columns) {
final Object value = node.getValue(column);
if (value != null) {
String text;
if (value instanceof InternationalString) {
text = ((InternationalString) value).toString(locale);
} else {
text = value.toString();
}
final String old = pool.put(text, text);
if (old != null) {
pool.put(old, old);
text = old;
}
if (text != value) {
node.setValue(column, text);
changes++;
}
}
}
return changes;
}
Aggregations