use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.
the class InfoLst method process.
@Override
public boolean process(LoadContext context, CDOMObject obj) {
boolean returnValue = true;
MapKey<CaseInsensitiveString, MessageFormat> infoKey = MapKey.INFO;
MapKey<CaseInsensitiveString, String[]> infoVarKey = MapKey.INFOVARS;
Set<CaseInsensitiveString> infoKeys = obj.getKeysFor(infoKey);
Set<CaseInsensitiveString> infoVarKeys = obj.getKeysFor(infoVarKey);
//Check if INFO needed INFOVARS
for (CaseInsensitiveString s : infoKeys) {
MessageFormat mf = obj.get(infoKey, s);
int required = MessageFormatUtilities.getRequriedArgumentCount(mf);
if (required > 0) {
String[] vars = obj.get(infoVarKey, s);
if (vars == null) {
Logging.errorPrint(obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " was loaded with INFO: " + s + " that requires " + required + " arguments, but no arguments" + " in INFOVARS were provided", context);
returnValue = false;
} else if (vars.length != required) {
Logging.errorPrint(obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " was loaded with INFO: " + s + " that requires " + required + " arguments, but " + vars.length + " arguments in INFOVARS were provided", context);
returnValue = false;
}
}
}
//Check if "Extra" INFOVARS were provided
for (CaseInsensitiveString s : infoVarKeys) {
if (!infoKeys.contains(s)) {
Logging.errorPrint(obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " was loaded with INFOVARS: " + s + " but no matching INFO was provided", context);
returnValue = false;
}
}
return returnValue;
}
use of pcgen.base.lang.CaseInsensitiveString in project pcgen by PCGen.
the class InfoVarsLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject cdo) {
MapChanges<CaseInsensitiveString, String[]> changes = context.getObjectContext().getMapChanges(cdo, MapKey.INFOVARS);
if (changes == null || changes.isEmpty()) {
return null;
}
Set<String> set = new TreeSet<>();
for (CaseInsensitiveString key : changes.getAdded().keySet()) {
String[] value = changes.getAdded().get(key);
set.add(new StringBuilder().append(key).append(Constants.PIPE).append(StringUtil.join(value, Constants.PIPE)).toString());
}
return set.toArray(new String[set.size()]);
}
Aggregations