use of pcgen.cdom.choiceset.SimpleChoiceSet in project pcgen by PCGen.
the class RegionLst method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
String item = tok.nextToken();
Formula count = FormulaFactory.getFormulaFor(item);
if (!count.isValid()) {
return new ParseResult.Fail("Count in " + getTokenName() + " was not valid: " + count.toString(), context);
}
if (count.isStatic()) {
if (!tok.hasMoreTokens()) {
return new ParseResult.Fail(getTokenName() + " cannot have only a count: " + value, context);
}
item = tok.nextToken();
if (count.resolveStatic().intValue() <= 0) {
return new ParseResult.Fail("Count in " + getTokenName() + " must be > 0: " + value, context);
}
} else {
count = FormulaFactory.ONE;
}
List<Region> regions = new ArrayList<>();
while (true) {
regions.add(Region.getConstant(item));
if (!tok.hasMoreTokens()) {
break;
}
item = tok.nextToken();
}
SimpleChoiceSet<Region> rcs = new SimpleChoiceSet<>(regions);
ChoiceSet<Region> cs = new ChoiceSet<>(getTokenName(), rcs);
cs.setTitle("Region Selection");
TransitionChoice<Region> tc = new ConcreteTransitionChoice<>(cs, count);
context.getObjectContext().put(obj, ObjectKey.REGION_CHOICE, tc);
tc.setRequired(false);
tc.setChoiceActor(this);
return ParseResult.SUCCESS;
}
use of pcgen.cdom.choiceset.SimpleChoiceSet in project pcgen by PCGen.
the class StringToken method parseToken.
@Override
public ParseResult parseToken(LoadContext context, CDOMObject obj, String value) {
if (value == null || value.isEmpty()) {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " must have arguments", context);
}
if (value.indexOf(',') != -1) {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not contain , : " + value, context);
}
if (value.indexOf('[') != -1) {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not contain [] : " + value, context);
}
if (value.charAt(0) == '|') {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not start with | : " + value, context);
}
if (value.charAt(value.length() - 1) == '|') {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments may not end with | : " + value, context);
}
if (value.indexOf("||") != -1) {
return new ParseResult.Fail("CHOOSE:" + getTokenName() + " arguments uses double separator || : " + value, context);
}
StringTokenizer tok = new StringTokenizer(value, Constants.PIPE);
Set<String> set = new HashSet<>();
while (tok.hasMoreTokens()) {
String tokString = tok.nextToken();
set.add(tokString);
}
SimpleChoiceSet<String> scs = new SimpleChoiceSet<>(set, Constants.PIPE);
BasicChooseInformation<String> tc = new BasicChooseInformation<>(getTokenName(), scs);
tc.setTitle("Choose an Item");
tc.setChoiceActor(this);
context.getObjectContext().put(obj, ObjectKey.CHOOSE_INFO, tc);
return ParseResult.SUCCESS;
}
Aggregations