use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class DomainTokenTest method testUnparseSinglePre.
@Test
public void testUnparseSinglePre() throws PersistenceLayerException {
Domain wp1 = construct(primaryContext, "TestWP1");
CDOMDirectSingleRef<Domain> ref = CDOMDirectSingleRef.getRef(wp1);
PreParserFactory prereqParser = PreParserFactory.getInstance();
Prerequisite prereq = prereqParser.parse("PRERACE:1,Dwarf");
assertNotNull(prereq);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(ref, prereq);
primaryProf.addToListFor(ListKey.DOMAIN, qo);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue() + "|PRERACE:1,Dwarf");
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class LangToken method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
Changes<QualifiedObject<CDOMReference<Language>>> changes = context.getObjectContext().getListChanges(obj, ListKey.AUTO_LANGUAGE);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(obj, ListKey.NEW_CHOOSE_ACTOR);
Collection<QualifiedObject<CDOMReference<Language>>> added = changes.getAdded();
StringBuilder sb = new StringBuilder();
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
boolean foundAny = false;
boolean foundOther = false;
if (changes.includesGlobalClear()) {
sb.append(Constants.LST_DOT_CLEAR);
}
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> cra : listAdded) {
if (cra.getSource().equals(getTokenName())) {
try {
if (sb.length() > 0) {
sb.append('|');
}
sb.append(cra.getLstFormat());
foundOther = true;
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (added != null) {
boolean needPipe = sb.length() > 0;
Prerequisite prereq = null;
for (QualifiedObject<CDOMReference<Language>> spp : added) {
CDOMReference<Language> lang = spp.getRawObject();
List<Prerequisite> prereqs = spp.getPrerequisiteList();
String ab = lang.getLSTformat(false);
boolean isUnconditionalAll = Constants.LST_ALL.equals(ab);
foundAny |= isUnconditionalAll;
foundOther |= !isUnconditionalAll;
if (needPipe) {
sb.append('|');
}
needPipe = true;
if (prereqs != null && !prereqs.isEmpty()) {
if (prereqs.size() > 1) {
context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had more than one Prerequisite for " + getFullName());
return null;
}
Prerequisite p = prereqs.get(0);
if (prereq != null && !p.equals(prereq)) {
context.addWriteMessage("Error: " + obj.getClass().getSimpleName() + " had differing Prerequisites for " + getFullName());
return null;
}
prereq = p;
}
sb.append(ab);
}
if (prereq != null) {
StringWriter swriter = new StringWriter();
try {
prereqWriter.write(swriter, prereq);
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
sb.append('|').append(swriter.toString());
}
}
if (foundAny && foundOther) {
context.addWriteMessage("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + sb);
return null;
}
if (sb.length() == 0) {
// okay
return null;
}
return new String[] { sb.toString() };
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class VisionFacetTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
CDOMObject cdo1 = new PCTemplate();
cdo1.setName("Template1");
CDOMObject cdo2 = new Race();
cdo2.setName("Race1");
Vision vision1 = new Vision(VisionType.getVisionType("Normal"), FormulaFactory.getFormulaFor(30));
Vision vision2 = new Vision(VisionType.getVisionType("Darkvision"), FormulaFactory.getFormulaFor(20));
CDOMDirectSingleRef<Vision> ref1 = new CDOMDirectSingleRef<>(vision1);
SimpleAssociatedObject apo1 = new SimpleAssociatedObject();
cdo1.putToList(Vision.VISIONLIST, ref1, apo1);
CDOMDirectSingleRef<Vision> ref2 = new CDOMDirectSingleRef<>(vision2);
SimpleAssociatedObject apo2 = new SimpleAssociatedObject();
cdo2.putToList(Vision.VISIONLIST, ref2, apo2);
QualifiedObject<Vision> st1 = new QualifiedObject<>(vision1);
QualifiedObject<Vision> st2 = new QualifiedObject<>(vision2);
source = new CDOMObject[] { cdo1, cdo2 };
target = new QualifiedObject[] { st1, st2 };
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class DomainTokenTest method testUnparseSinglePre.
@Test
public void testUnparseSinglePre() throws PersistenceLayerException {
Domain wp1 = construct(primaryContext, "TestWP1");
CDOMDirectSingleRef<Domain> ref = CDOMDirectSingleRef.getRef(wp1);
PreParserFactory prereqParser = PreParserFactory.getInstance();
Prerequisite prereq = prereqParser.parse("PRERACE:1,Dwarf");
assertNotNull(prereq);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(ref, prereq);
primaryProf.addToListFor(ListKey.DOMAIN, qo);
String[] unparsed = getToken().unparse(primaryContext, primaryProf);
expectSingle(unparsed, getLegalValue() + "|PRERACE:1,Dwarf");
}
use of pcgen.core.QualifiedObject in project pcgen by PCGen.
the class ClassLevelDomainBracketToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClassLevel level, String value) {
Logging.deprecationPrint(getMessage(level, value));
StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
boolean first = true;
while (pipeTok.hasMoreTokens()) {
String tok = pipeTok.nextToken();
if (Constants.LST_DOT_CLEAR.equals(tok)) {
if (!first) {
return new ParseResult.Fail(" Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
}
context.getObjectContext().removeList(level, ListKey.DOMAIN);
continue;
}
// Note: May contain PRExxx
String domainKey;
Prerequisite prereq = null;
int openBracketLoc = tok.indexOf('[');
if (openBracketLoc == -1) {
if (tok.indexOf(']') != -1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must have '[' if it contains a PREREQ tag", context);
}
domainKey = tok;
} else {
if (tok.lastIndexOf(']') != tok.length() - 1) {
return new ParseResult.Fail("Invalid " + getTokenName() + " must end with ']' if it contains a PREREQ tag", context);
}
domainKey = tok.substring(0, openBracketLoc);
String prereqString = tok.substring(openBracketLoc + 1, tok.length() - 1);
if (prereqString.isEmpty()) {
return new ParseResult.Fail(getTokenName() + " cannot have empty prerequisite : " + value, context);
}
prereq = getPrerequisite(prereqString);
if (prereq == null) {
return new ParseResult.Fail(getTokenName() + " had invalid prerequisite : " + prereqString, context);
}
}
CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, domainKey);
QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
if (prereq != null) {
qo.addPrerequisite(prereq);
}
context.getObjectContext().addToList(level, ListKey.DOMAIN, qo);
first = false;
}
return ParseResult.SUCCESS;
}
Aggregations