use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangelevelToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
final StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
if (tok.countTokens() != 4) {
return new ParseResult.Fail(getTokenName() + " must have 4 | delimited arguments : " + value, context);
}
String classString = tok.nextToken();
CDOMSingleRef<PCClass> cl = context.getReferenceContext().getCDOMReference(PCClass.class, classString);
String mindlString = tok.nextToken();
int mindl;
try {
mindl = Integer.parseInt(mindlString);
} catch (NumberFormatException nfe) {
return new ParseResult.Fail(getTokenName() + " expected an integer: " + mindlString, context);
}
String maxdlString = tok.nextToken();
int maxdl;
try {
maxdl = Integer.parseInt(maxdlString);
} catch (NumberFormatException nfe) {
return new ParseResult.Fail(getTokenName() + " expected an integer: " + maxdlString, context);
}
String minremString = tok.nextToken();
int minrem;
try {
minrem = Integer.parseInt(minremString);
} catch (NumberFormatException nfe) {
return new ParseResult.Fail(getTokenName() + " expected an integer: " + minremString, context);
}
try {
LevelExchange le = new LevelExchange(cl, mindl, maxdl, minrem);
context.getObjectContext().put(pcc, ObjectKey.EXCHANGE_LEVEL, le);
return ParseResult.SUCCESS;
} catch (IllegalArgumentException e) {
ComplexParseResult pr = new ComplexParseResult();
pr.addErrorMessage("Error in " + getTokenName() + ' ' + e.getMessage());
pr.addErrorMessage(" Token contents: " + value);
return pr;
}
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseNegativeMinLevel.
@Test
public void testUnparseNegativeMinLevel() throws PersistenceLayerException {
try {
PCClass fighter = primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
LevelExchange le = new LevelExchange(CDOMDirectSingleRef.getRef(fighter), -4, 12, 2);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
assertBadUnparse();
} catch (IllegalArgumentException e) {
// Good here too :)
}
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseOne.
@Test
public void testUnparseOne() throws PersistenceLayerException {
PCClass fighter = primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
LevelExchange le = new LevelExchange(CDOMDirectSingleRef.getRef(fighter), 4, 12, 2);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
expectSingle(getToken().unparse(primaryContext, primaryProf), "Fighter|4|12|2");
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseNegRemainingLevel.
@Test
public void testUnparseNegRemainingLevel() throws PersistenceLayerException {
try {
PCClass fighter = primaryContext.getReferenceContext().constructCDOMObject(PCClass.class, "Fighter");
LevelExchange le = new LevelExchange(CDOMDirectSingleRef.getRef(fighter), 4, 3, -2);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
assertBadUnparse();
} catch (IllegalArgumentException e) {
// Good here too :)
}
}
use of pcgen.cdom.content.LevelExchange in project pcgen by PCGen.
the class ExchangeLevelTokenTest method testUnparseNullClass.
@Test
public void testUnparseNullClass() throws PersistenceLayerException {
try {
LevelExchange le = new LevelExchange(null, 4, 3, 2);
primaryProf.put(ObjectKey.EXCHANGE_LEVEL, le);
assertBadUnparse();
} catch (IllegalArgumentException e) {
// Good here too :)
}
}
Aggregations