use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreParserFactory method parse.
public static List<Prerequisite> parse(final List<String> preStrings) {
final List<Prerequisite> ret = new ArrayList<>(preStrings.size());
for (String prestr : preStrings) {
try {
final PreParserFactory factory = PreParserFactory.getInstance();
final Prerequisite prereq = factory.parse(prestr);
ret.add(prereq);
} catch (PersistenceLayerException ple) {
//The message is now produced at a lower level, and thus has to be localised there.
Logging.errorPrint(ple.getMessage(), ple);
//Logging.errorPrintLocalised(PropertyFactory.getString("PrereqHandler.Unable_to_parse"), object); //$NON-NLS-1$
}
}
return ret;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class AbstractPrerequisiteParser method parse.
/**
* Parses the PreRequisite.
*
* @param kind the kind of the prerequisite (less the "PRE" prefix).
* @param formula The body of the prerequisite.
* @param invertResult Whether the prerequisite should invert the result.
* @param overrideQualify
* if set true, this prerequisite will be enforced in spite
* of any "QUALIFY" tag that may be present.
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
// Check to make sure that this class can parse this token
boolean foundTag = false;
for (int i = 0; i < kindsHandled().length; i++) {
String arrayElement = kindsHandled()[i];
if (arrayElement.equalsIgnoreCase(kind)) {
foundTag = true;
break;
}
}
if (!foundTag) {
throw new PersistenceLayerException(this.getClass().getName() + " can not parse a Prerequisite tag of '" + kind + ":" + formula + "'");
}
// If we can parse this token then set the kind and invert flag.
Prerequisite prereq = new Prerequisite();
prereq.setKind(kind);
prereq.setOverrideQualify(overrideQualify);
return prereq;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class AbstractPrerequisiteSimpleParser method parse.
/**
* Parse PreReq
*
* @param kind
* @param formula
* @param invertResult
* @param overrideQualify
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
prereq.setKey(formula);
prereq.setOperator(PrerequisiteOperator.EQ);
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
return prereq;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PreMultParser method parse.
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
prereq.setKind(null);
prereq.setCharacterRequired(false);
int commaIndex = formula.indexOf(",");
if (commaIndex > 0) {
String minFormula = formula.substring(0, commaIndex);
formula = formula.substring(commaIndex + 1);
prereq.setOperator(PrerequisiteOperator.GTEQ);
prereq.setOperand(minFormula);
}
// [PREARMORPROF:1,TYPE.Medium],[PREFEAT:1,Armor Proficiency (Medium)]
PreParserFactory parser = PreParserFactory.getInstance();
for (String s : splitOnTopLevelToken(formula, '[', ']')) {
prereq.addPrerequisite(parser.parse(s));
}
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
return prereq;
}
use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.
the class PrerequisiteMultWriter method write.
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
Prerequisite subreq;
//
if (isSpecialCase(prereq)) {
handleSpecialCase(writer, prereq);
return;
}
if (isNegatedPreability(prereq)) {
handleNegatedPreAbility(writer, prereq);
return;
}
if (prereq.getPrerequisiteCount() != 0) {
subreq = prereq.getPrerequisites().get(0);
final PrerequisiteWriterInterface test = PrerequisiteWriterFactory.getInstance().getWriter(subreq.getKind());
if ((test != null) && (test instanceof AbstractPrerequisiteWriter) && ((AbstractPrerequisiteWriter) test).specialCase(writer, prereq)) {
return;
}
}
if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
writer.write('!');
}
writer.write("PREMULT:");
writer.write(prereq.getOperand());
writer.write(',');
int i = 0;
for (Prerequisite pre : prereq.getPrerequisites()) {
if (i > 0) {
writer.write(',');
}
writer.write('[');
PrerequisiteWriterFactory factory = PrerequisiteWriterFactory.getInstance();
PrerequisiteWriterInterface w = factory.getWriter(pre.getKind());
if (w != null) {
w.write(writer, pre);
} else {
writer.write("unrecognized kind:" + pre.getKind());
}
writer.write(']');
i++;
}
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
Aggregations