use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.
the class VariableFacetTest method testAddRemove1First.
@Test
public void testAddRemove1First() {
Object source = new Object();
CDOMObject t1 = new PCTemplate();
CDOMObject t2 = new PCTemplate();
VariableKey vk = VariableKey.getConstant("Var1");
t1.put(vk, FormulaFactory.getFormulaFor(2));
t2.put(vk, FormulaFactory.getFormulaFor(4));
DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_ADDED);
getFacet().dataAdded(dfce);
assertTrue(getFacet().contains(id, vk));
assertFalse(getFacet().contains(altid, vk));
assertFalse(getFacet().contains(id, VariableKey.getConstant("Var2")));
dfce = new DataFacetChangeEvent<>(id, t2, source, DataFacetChangeEvent.DATA_ADDED);
getFacet().dataAdded(dfce);
assertTrue(getFacet().contains(id, vk));
assertFalse(getFacet().contains(altid, vk));
assertFalse(getFacet().contains(id, VariableKey.getConstant("Var2")));
dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_REMOVED);
getFacet().dataRemoved(dfce);
assertTrue(getFacet().contains(id, vk));
dfce = new DataFacetChangeEvent<>(id, t2, source, DataFacetChangeEvent.DATA_REMOVED);
getFacet().dataRemoved(dfce);
assertFalse(getFacet().contains(id, vk));
}
use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.
the class VariableFacetTest method testUselessRemove.
@Test
public void testUselessRemove() {
Object source = new Object();
CDOMObject t1 = new PCTemplate();
VariableKey vk1 = VariableKey.getConstant("Var1");
DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_REMOVED);
getFacet().dataRemoved(dfce);
assertFalse(getFacet().contains(id, vk1));
}
use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.
the class DefineLst method unparse.
@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
Set<VariableKey> keys = context.getObjectContext().getVariableKeys(obj);
TreeSet<String> set = new TreeSet<>();
if (keys != null && !keys.isEmpty()) {
for (VariableKey key : keys) {
set.add(key.toString() + Constants.PIPE + context.getObjectContext().getVariable(obj, key));
}
}
if (set.isEmpty()) {
return null;
}
return set.toArray(new String[set.size()]);
}
use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.
the class AbstractObjectContext method commit.
void commit() {
ObjectCommitStrategy commit = getCommitStrategy();
for (URI uri : edits.preClearSet.getKeySet()) {
for (ConcretePrereqObject cpo : edits.preClearSet.getListFor(uri)) {
commit.clearPrerequisiteList(cpo);
}
}
for (URI uri : edits.globalClearSet.getKeySet()) {
for (CDOMObject cdo : edits.globalClearSet.getSecondaryKeySet(uri)) {
for (ListKey<?> lk : edits.globalClearSet.getListFor(uri, cdo)) {
commit.removeList(cdo, lk);
}
}
}
for (URI uri : edits.negativeMap.getKeySet()) {
for (ConcretePrereqObject cpo : edits.negativeMap.getSecondaryKeySet(uri)) {
if (cpo instanceof CDOMObject) {
CDOMObject cdo = (CDOMObject) cpo;
CDOMObject neg = edits.negativeMap.get(uri, cdo);
for (ObjectKey<?> ok : neg.getSafeListFor(ListKey.REMOVED_OBJECTKEY)) {
commit.remove(cdo, ok);
}
for (FactKey<?> ok : neg.getSafeListFor(ListKey.REMOVED_FACTKEY)) {
commit.remove(cdo, ok);
}
for (StringKey sk : neg.getSafeListFor(ListKey.REMOVED_STRINGKEY)) {
commit.remove(cdo, sk);
}
for (IntegerKey ik : neg.getSafeListFor(ListKey.REMOVED_INTEGERKEY)) {
commit.remove(cdo, ik);
}
for (FactSetKey<?> key : neg.getFactSetKeys()) {
removeFactSetKey(cdo, key, neg);
}
for (ListKey<?> key : neg.getListKeys()) {
removeListKey(cdo, key, neg);
}
for (MapKey<?, ?> key1 : neg.getMapKeys()) {
removeMapKey(cdo, key1, neg);
}
}
}
}
for (URI uri : edits.positiveMap.getKeySet()) {
for (ConcretePrereqObject cpo : edits.positiveMap.getSecondaryKeySet(uri)) {
CDOMObject pos = edits.positiveMap.get(uri, cpo);
for (Prerequisite p : pos.getPrerequisiteList()) {
commit.put(cpo, p);
}
if (cpo instanceof CDOMObject) {
CDOMObject cdo = (CDOMObject) cpo;
for (StringKey key : pos.getStringKeys()) {
commit.put(cdo, key, pos.get(key));
}
for (IntegerKey key : pos.getIntegerKeys()) {
commit.put(cdo, key, pos.get(key));
}
for (FormulaKey key : pos.getFormulaKeys()) {
commit.put(cdo, key, pos.get(key));
}
for (VariableKey key : pos.getVariableKeys()) {
commit.put(cdo, key, pos.get(key));
}
for (ObjectKey<?> key : pos.getObjectKeys()) {
putObjectKey(cdo, key, pos);
}
for (FactKey<?> key : pos.getFactKeys()) {
putFactKey(cdo, key, pos);
}
for (ListKey<?> key : pos.getListKeys()) {
putListKey(cdo, key, pos);
}
for (FactSetKey<?> key : pos.getFactSetKeys()) {
putFactSetKey(cdo, key, pos);
}
for (MapKey<?, ?> key1 : pos.getMapKeys()) {
putMapKey(cdo, key1, pos);
}
/*
* No need to deal with ListMods because that's done in
* listContext
*/
/*
* TODO Deal with cloned objects
*/
}
}
}
for (URI uri : edits.patternClearSet.getKeySet()) {
for (CDOMObject cdo : edits.patternClearSet.getSecondaryKeySet(uri)) {
for (ListKey<?> lk : edits.patternClearSet.getTertiaryKeySet(uri, cdo)) {
for (String s : edits.patternClearSet.getListFor(uri, cdo, lk)) {
commit.removePatternFromList(cdo, lk, s);
}
}
}
}
rollback();
}
use of pcgen.cdom.enumeration.VariableKey in project pcgen by PCGen.
the class VariableFacetTest method testAddRemove.
@Test
public void testAddRemove() {
Object source = new Object();
CDOMObject t1 = new PCTemplate();
VariableKey vk1 = VariableKey.getConstant("Var1");
VariableKey vk2 = VariableKey.getConstant("Var2");
t1.put(vk1, FormulaFactory.getFormulaFor(2));
t1.put(vk2, FormulaFactory.getFormulaFor(4));
DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_ADDED);
getFacet().dataAdded(dfce);
assertTrue(getFacet().contains(id, vk1));
assertTrue(getFacet().contains(id, vk2));
assertFalse(getFacet().contains(altid, vk1));
assertFalse(getFacet().contains(id, VariableKey.getConstant("Var3")));
dfce = new DataFacetChangeEvent<>(id, t1, source, DataFacetChangeEvent.DATA_REMOVED);
getFacet().dataRemoved(dfce);
assertFalse(getFacet().contains(id, vk1));
assertFalse(getFacet().contains(id, vk2));
assertFalse(getFacet().contains(altid, vk1));
assertFalse(getFacet().contains(id, VariableKey.getConstant("Var3")));
}
Aggregations