MCPcopy Create free account
hub / github.com/PCGen/pcgen / parseNonEmptyToken

Method parseNonEmptyToken

code/src/java/plugin/lsttokens/race/CrToken.java:47–70  ·  view source on GitHub ↗
(LoadContext context, Race race, String value)

Source from the content-addressed store, hash-verified

45 }
46
47 @Override
48 public ParseResult parseNonEmptyToken(LoadContext context, Race race, String value)
49 {
50 try
51 {
52 int intRating = Integer.parseInt(value.startsWith("1/") ? value.substring(2) : value);
53 if (intRating < 0)
54 {
55 return new ParseResult.Fail(getTokenName() + " Challenge Rating cannot be negative");
56 }
57 }
58 catch (NumberFormatException e)
59 {
60 return new ParseResult.Fail(getTokenName() + "Challenge Rating must be a positive integer i or 1/i");
61 }
62 Formula formula = FormulaFactory.getFormulaFor(value);
63 if (!formula.isValid())
64 {
65 return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString());
66 }
67 ChallengeRating cr = new ChallengeRating(formula);
68 context.getObjectContext().put(race, ObjectKey.CHALLENGE_RATING, cr);
69 return ParseResult.SUCCESS;
70 }
71
72 /**
73 * Unparse the CR token

Callers

nothing calls this directly

Calls 7

getTokenNameMethod · 0.95
getFormulaForMethod · 0.95
isValidMethod · 0.95
parseIntMethod · 0.80
toStringMethod · 0.65
putMethod · 0.65
getObjectContextMethod · 0.65

Tested by

no test coverage detected