Object code = null;
Object codeSpace = null;
Object version = null;
Object authority = null;
Object remarks = null;
DefaultInternationalString localized = null;
/*
* Iterate through each map entry. This have two purposes:
*
* 1) Ignore case (a call to properties.get("foo") can't do that)
* 2) Find localized remarks.
*
* This algorithm is sub-optimal if the map contains a lot of entries of no interest to
* this identifier. Hopefully, most users will fill a map with only useful entries.
*/
for (final Map.Entry<String,?> entry : properties.entrySet()) {
String key = entry.getKey().trim().toLowerCase();
Object value = entry.getValue();
/*switch (key)*/ { // This is a "string in switch" on the JDK7 branch.
if (key.equals(CODE_KEY)) {
code = value;
continue;
}
else if (key.equals(CODESPACE_KEY)) {
codeSpace = value;
continue;
}
else if (key.equals(VERSION_KEY)) {
version = value;
continue;
}
else if (key.equals(AUTHORITY_KEY)) {
if (value instanceof String) {
value = Citations.fromName((String) value);
}
authority = value;
continue;
}
else if (key.equals(REMARKS_KEY)) {
if (value instanceof String) {
value = new SimpleInternationalString((String) value);
}
remarks = value;
continue;
}
}
/*
* Search for additional locales (e.g. "remarks_fr").
*/
final Locale locale = Locales.parseSuffix(REMARKS_KEY, key);
if (locale != null) {
if (localized == null) {
localized = new DefaultInternationalString();
}
localized.add(locale, (String) value);
}
}
/*
* Get the localized remarks, if it was not yet set. If a user specified remarks
* both as InternationalString and as String for some locales (which is a weird
* usage...), then current implementation discards the later with a warning.
*/
if (localized != null) {
if (remarks == null) {
remarks = localized;
} else if (remarks instanceof SimpleInternationalString) {
localized.add(Locale.ROOT, remarks.toString());
remarks = localized;
} else {
Logging.log(ImmutableIdentifier.class, "<init>",
Messages.getResources(null).getLogRecord(Level.WARNING, Messages.Keys.LocalesDiscarded));
}