use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavoredClassTokenTest method testCategorizationFail.
@Test
public void testCategorizationFail() throws PersistenceLayerException {
construct(primaryContext, "TestWP1");
assertTrue(parse("TestWP1.Two"));
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Two");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
assertConstructionError();
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavclassToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Race race, String value) {
context.getObjectContext().remove(race, ObjectKey.ANY_FAVORED_CLASS);
context.getObjectContext().removeList(race, ListKey.FAVORED_CLASS);
context.getObjectContext().removeFromList(race, ListKey.NEW_CHOOSE_ACTOR, this);
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
foundAny = true;
context.getObjectContext().put(race, ObjectKey.ANY_FAVORED_CLASS, true);
} else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
foundOther = true;
context.getObjectContext().addToList(race, ListKey.NEW_CHOOSE_ACTOR, this);
} else {
CDOMReference<? extends PCClass> ref;
foundOther = true;
int dotLoc = token.indexOf('.');
if (dotLoc == -1) {
// Primitive
ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
} else {
ParseResult pr = checkForIllegalSeparator('.', value);
if (!pr.passed()) {
return pr;
}
// SubClass
String parent = token.substring(0, dotLoc);
String subclass = token.substring(dotLoc + 1);
SubClassCategory scc = SubClassCategory.getConstant(parent);
ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
}
context.getObjectContext().addToList(race, ListKey.FAVORED_CLASS, ref);
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class ClassToken method decodeChoice.
@Override
public PCClass decodeChoice(LoadContext context, String s) {
int dotLoc = s.indexOf('.');
if (dotLoc == -1) {
// Primitive
return context.getReferenceContext().silentlyGetConstructedCDOMObject(PCCLASS_CLASS, s);
}
// SubClass
String parent = s.substring(0, dotLoc);
String subclass = s.substring(dotLoc + 1);
SubClassCategory scc = SubClassCategory.getConstant(parent);
return context.getReferenceContext().silentlyGetConstructedCDOMObject(SUBCLASS_CLASS, scc, subclass);
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavoredclassToken method parseFavoredClass.
public ParseResult parseFavoredClass(LoadContext context, CDOMObject cdo, String value) {
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (Constants.HIGHEST_LEVEL_CLASS.equalsIgnoreCase(token)) {
foundAny = true;
context.getObjectContext().put(cdo, ObjectKey.ANY_FAVORED_CLASS, true);
} else if (Constants.LST_PERCENT_LIST.equalsIgnoreCase(token)) {
context.getObjectContext().addToList(cdo, ListKey.NEW_CHOOSE_ACTOR, this);
} else {
CDOMReference<? extends PCClass> ref;
foundOther = true;
int dotLoc = token.indexOf('.');
if (dotLoc == -1) {
// Primitive
ref = context.getReferenceContext().getCDOMReference(PCCLASS_CLASS, token);
} else {
ParseResult pr = checkForIllegalSeparator('.', token);
if (!pr.passed()) {
return pr;
}
// SubClass
String parent = token.substring(0, dotLoc);
String subclass = token.substring(dotLoc + 1);
SubClassCategory scc = SubClassCategory.getConstant(parent);
ref = context.getReferenceContext().getCDOMReference(SUBCLASS_CLASS, scc, subclass);
}
context.getObjectContext().addToList(cdo, ListKey.FAVORED_CLASS, ref);
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getTokenName() + ": Contains " + Constants.HIGHEST_LEVEL_CLASS + " and a specific reference: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.cdom.enumeration.SubClassCategory in project pcgen by PCGen.
the class FavoredClassIntegrationTest method testRoundRobinSimpleCategorized.
@Test
public void testRoundRobinSimpleCategorized() throws PersistenceLayerException {
verifyCleanStart();
construct(primaryContext, "TestWP1");
construct(primaryContext, "TestWP2");
construct(secondaryContext, "TestWP1");
construct(secondaryContext, "TestWP2");
SubClass obj = primaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
SubClassCategory cat = SubClassCategory.getConstant("TestWP2");
primaryContext.getReferenceContext().reassociateCategory(cat, obj);
obj = secondaryContext.getReferenceContext().constructCDOMObject(SubClass.class, "Sub");
secondaryContext.getReferenceContext().reassociateCategory(cat, obj);
TestContext tc = new TestContext();
commit(testCampaign, tc, "TestWP1");
commit(modCampaign, tc, "TestWP2.Sub");
completeRoundRobin(tc);
}
Aggregations