Search in sources :

Example 11 with CaseInsensitiveString

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;
}
Also used : MessageFormat(java.text.MessageFormat) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Example 12 with CaseInsensitiveString

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()]);
}
Also used : TreeSet(java.util.TreeSet) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString) CaseInsensitiveString(pcgen.base.lang.CaseInsensitiveString)

Aggregations

CaseInsensitiveString (pcgen.base.lang.CaseInsensitiveString)12 MessageFormat (java.text.MessageFormat)4 TreeSet (java.util.TreeSet)2 CDOMObject (pcgen.cdom.base.CDOMObject)2 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 LegalScope (pcgen.base.formula.base.LegalScope)1 ObjectWrapperFacet (pcgen.cdom.facet.ObjectWrapperFacet)1 ResultFacet (pcgen.cdom.facet.analysis.ResultFacet)1 VariableContext (pcgen.rules.context.VariableContext)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1