use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreAbilityParserTest method testInvalidCharacter.
/**
* Test that an error is produced if separators are incorrect
* @throws Exception
*/
@Test
public void testInvalidCharacter() throws Exception {
try {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,KEY_a|Key_b", false, false);
fail("Should have thrown a PersistenceLayerException.");
} catch (PersistenceLayerException e) {
// Ignore, this is the expected result.
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreAbilityParserTest method testInvalidSeparators.
/**
* Test that an error is produced if separators are incorrect
* @throws Exception
*/
@Test
public void testInvalidSeparators() throws Exception {
try {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,,KEY_a", false, false);
fail("Should have thrown a PersistenceLayerException.");
} catch (PersistenceLayerException e) {
// Ignore, this is the expected result.
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class AdddomainsToken method unparse.
@Override
public String[] unparse(LoadContext context, PCClassLevel level) {
AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), level, PCClass.ALLOWED_DOMAINS);
Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
context.addWriteMessage(getTokenName() + " does not support .CLEAR");
return null;
}
MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
if (mtl == null || mtl.isEmpty()) {
return null;
}
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
Set<String> set = new TreeSet<>();
for (CDOMReference<Domain> domain : mtl.getKeySet()) {
for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
List<Prerequisite> prereqs = assoc.getPrerequisiteList();
Prerequisite prereq;
if (prereqs == null || prereqs.isEmpty()) {
prereq = null;
} else if (prereqs.size() == 1) {
prereq = prereqs.get(0);
} else {
context.addWriteMessage("Added Domain from " + getTokenName() + " had more than one " + "Prerequisite: " + prereqs.size());
return null;
}
if (prereq != null) {
sb.append('[');
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append(swriter.toString());
sb.append(']');
}
set.add(sb.toString());
}
}
return new String[] { StringUtil.join(set, Constants.DOT) };
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreWeaponProfWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
writer.write('!');
}
writer.write("PREWEAPONPROF:" + (prereq.isOverrideQualify() ? "Q:" : ""));
writer.write(prereq.getOperand());
writer.write(',');
writer.write(prereq.getKey());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
use of pcgen.persistence.PersistenceLayerException in project pcgen by PCGen.
the class PreWieldWriter method write.
/**
* @see pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface#write(java.io.Writer, pcgen.core.prereq.Prerequisite)
*/
@Override
public void write(Writer writer, Prerequisite prereq) throws PersistenceLayerException {
checkValidOperator(prereq, operatorsHandled());
try {
if (prereq.getOperator().equals(PrerequisiteOperator.LT)) {
writer.write('!');
}
writer.write("PREWIELD:" + (prereq.isOverrideQualify() ? "Q:" : "") + "1,");
writer.write(prereq.getKey());
} catch (IOException e) {
throw new PersistenceLayerException(e.getMessage());
}
}
Aggregations