use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class OptionToken method unparse.
@Override
public String[] unparse(LoadContext context, BaseKit kit) {
Collection<OptionBound> bounds = kit.getBounds();
if (bounds == null) {
return null;
}
List<String> list = new ArrayList<>();
for (OptionBound bound : bounds) {
Formula min = bound.getOptionMin();
Formula max = bound.getOptionMax();
if (min == null || max == null) {
// Error if only one is null
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(min);
if (!min.equals(max)) {
sb.append(',').append(max);
}
list.add(sb.toString());
}
return new String[] { StringUtil.join(list, Constants.PIPE) };
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class CountToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitDeity kitDeity, String value) {
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
kitDeity.setCount(formula);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class EquipBuyToken method unparse.
@Override
public String[] unparse(LoadContext context, Kit kit) {
QualifiedObject<Formula> qo = kit.get(ObjectKey.EQUIP_BUY);
if (qo == null) {
return null;
}
Formula f = qo.getRawObject();
List<Prerequisite> prereqs = qo.getPrerequisiteList();
String ab = f.toString();
if (prereqs != null && !prereqs.isEmpty()) {
ab = ab + Constants.PIPE + getPrerequisiteString(context, prereqs);
}
return new String[] { ab };
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class QtyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitGear kitGear, String value) {
Formula formula = FormulaFactory.getFormulaFor(value);
if (!formula.isValid()) {
return new ParseResult.Fail("Formula in " + getTokenName() + " was not valid: " + formula.toString(), context);
}
kitGear.setQuantity(formula);
return ParseResult.SUCCESS;
}
use of pcgen.base.formula.Formula in project pcgen by PCGen.
the class ValuesToken method processRange.
private boolean processRange(KitTable kitTable, KitGear optionInfo, String range) {
if (isEmpty(range) || hasIllegalSeparator(',', range)) {
return false;
}
ParsingSeparator sep = new ParsingSeparator(range, ',');
sep.addGroupingPair('[', ']');
sep.addGroupingPair('(', ')');
String minString = sep.next();
String maxString;
if (sep.hasNext()) {
maxString = sep.next();
} else {
maxString = range;
}
if (sep.hasNext()) {
return false;
}
Formula min = FormulaFactory.getFormulaFor(minString);
if (!min.isValid()) {
Logging.errorPrint("Min Formula in " + getTokenName() + " was not valid: " + min.toString());
return false;
}
Formula max = FormulaFactory.getFormulaFor(maxString);
if (!max.isValid()) {
Logging.errorPrint("Max Formula in " + getTokenName() + " was not valid: " + max.toString());
return false;
}
kitTable.addGear(optionInfo, min, max);
return true;
}
Aggregations