use of pcgen.cdom.reference.FilteredReference in project pcgen by PCGen.
the class ClassesToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Skill skill, String value) {
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean added = false;
List<CDOMReference<ClassSkillList>> allow = new ArrayList<>();
while (pipeTok.hasMoreTokens()) {
String className = pipeTok.nextToken();
if (Constants.LST_ALL.equals(className)) {
if (added) {
return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ALL after a specific reference: " + value, context);
}
break;
}
if (className.startsWith("!")) {
return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ! without (or before) ALL: " + value, context);
}
allow.add(context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, className));
added = true;
}
if (pipeTok.hasMoreTokens()) {
// allow is not used (empty or an error)
FilteredReference<ClassSkillList> filtered = new FilteredReference<>(SKILLLIST_CLASS, context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS));
while (pipeTok.hasMoreTokens()) {
String className = pipeTok.nextToken();
if (className.startsWith("!")) {
String clString = className.substring(1);
if (Constants.LST_ALL.equals(clString) || Constants.LST_ANY.equals(clString)) {
return new ParseResult.Fail("Invalid " + getTokenName() + " cannot use !ALL", context);
}
CDOMSingleRef<ClassSkillList> ref = context.getReferenceContext().getCDOMReference(SKILLLIST_CLASS, clString);
filtered.addProhibitedItem(ref);
} else {
return new ParseResult.Fail("Non-sensical Skill " + getTokenName() + ": Contains ALL and a specific reference: " + value, context);
}
}
context.getListContext().addToMasterList(getTokenName(), skill, filtered, skill);
} else if (allow.isEmpty()) {
// unqualified ALL
context.getListContext().addToMasterList(getTokenName(), skill, context.getReferenceContext().getCDOMAllReference(SKILLLIST_CLASS), skill);
} else {
// use allow
for (CDOMReference<ClassSkillList> ref : allow) {
context.getListContext().addToMasterList(getTokenName(), skill, ref, skill);
}
}
return ParseResult.SUCCESS;
}
Aggregations