use of pcgen.core.Language in project pcgen by PCGen.
the class RaceLangbonusTest method testSimple.
@Test
public void testSimple() throws PersistenceLayerException {
Race source = create(Race.class, "Source");
Language granted = create(Language.class, "Granted");
ParseResult result = token.parseToken(context, source, "Granted");
if (result != ParseResult.SUCCESS) {
result.printMessages();
fail("Test Setup Failed");
}
finishLoad();
assertEquals(0, startingLanguageFacet.getCount(id));
raceFacet.directSet(id, source, getAssoc());
assertTrue(startingLanguageFacet.contains(id, granted));
assertEquals(1, startingLanguageFacet.getCount(id));
raceFacet.remove(id);
assertEquals(0, startingLanguageFacet.getCount(id));
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LanguageFacetTest method getObject.
@Override
protected Language getObject() {
Language wp = new Language();
wp.setName("WP" + n++);
return wp;
}
use of pcgen.core.Language in project pcgen by PCGen.
the class AutoLanguageListFacetTest method getObject.
@Override
protected Language getObject() {
Language wp = new Language();
wp.setName("WP" + n++);
return wp;
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LangToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
String lang = value;
ParseResult pr = checkSeparatorsAndNonEmpty('|', lang);
if (!pr.passed()) {
return pr;
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(lang, Constants.PIPE);
boolean isPre = false;
// Do not initialize, null is significant!
Prerequisite prereq = null;
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (PreParserFactory.isPreReqString(token)) {
if (isPre) {
String errorText = "Invalid " + getTokenName() + ": " + value + " PRExxx must be at the END of the Token";
Logging.errorPrint(errorText);
return new ParseResult.Fail(errorText, context);
}
prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
}
int preStart = value.indexOf(token) - 1;
lang = value.substring(0, preStart);
isPre = true;
}
}
boolean firstToken = true;
tok = new StringTokenizer(lang, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(token)) {
if (!firstToken) {
return new ParseResult.Fail("Non-sensical situation was " + "encountered while parsing " + getTokenName() + ": When used, .CLEAR must be the first argument", context);
}
context.getObjectContext().removeList(obj, ListKey.AUTO_LANGUAGE);
} else if (Constants.LST_PERCENT_LIST.equals(token)) {
ChooseSelectionActor<Language> cra;
if (prereq == null) {
cra = this;
} else {
ConditionalSelectionActor<Language> cca = new ConditionalSelectionActor<>(this);
cca.addPrerequisite(prereq);
cra = cca;
}
foundOther = true;
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
} else if (Constants.LST_ALL.equals(token)) {
foundAny = true;
context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(context.getReferenceContext().getCDOMAllReference(LANGUAGE_CLASS), prereq));
} else {
foundOther = true;
CDOMReference<Language> ref = TokenUtilities.getTypeOrPrimitive(context, LANGUAGE_CLASS, token);
if (ref == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getTokenName(), context);
}
context.getObjectContext().addToList(obj, ListKey.AUTO_LANGUAGE, new QualifiedObject<>(ref, prereq));
}
firstToken = false;
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.Language in project pcgen by PCGen.
the class LanguageToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
ParsingSeparator sep = new ParsingSeparator(value, '|');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String activeValue = sep.next();
Formula count;
if (!sep.hasNext()) {
count = FormulaFactory.ONE;
} else {
count = FormulaFactory.getFormulaFor(activeValue);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic() && count.resolveStatic().doubleValue() <= 0) {
return new ParseResult.Fail("Count in " + getFullName() + " must be > 0", context);
}
activeValue = sep.next();
}
if (sep.hasNext()) {
return new ParseResult.Fail(getFullName() + " had too many pipe separated items: " + value, context);
}
ParseResult pr = checkSeparatorsAndNonEmpty(',', activeValue);
if (!pr.passed()) {
return pr;
}
List<CDOMReference<Language>> refs = new ArrayList<>();
StringTokenizer tok = new StringTokenizer(activeValue, Constants.COMMA);
while (tok.hasMoreTokens()) {
String tokText = tok.nextToken();
CDOMReference<Language> lang = TokenUtilities.getReference(context, LANGUAGE_CLASS, tokText);
if (lang == null) {
return new ParseResult.Fail(" Error was encountered while parsing " + getFullName() + ": " + value + " had an invalid reference: " + tokText, context);
}
refs.add(lang);
}
ReferenceChoiceSet<Language> rcs = new ReferenceChoiceSet<>(refs);
if (!rcs.getGroupingState().isValid()) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
ChoiceSet<Language> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Language Choice");
PersistentTransitionChoice<Language> tc = new ConcretePersistentTransitionChoice<>(cs, count);
context.getObjectContext().addToList(obj, ListKey.ADD, tc);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
Aggregations