Search in sources :

Example 6 with VariableKey

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));
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) Test(org.junit.Test)

Example 7 with VariableKey

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));
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) Test(org.junit.Test)

Example 8 with VariableKey

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()]);
}
Also used : VariableKey(pcgen.cdom.enumeration.VariableKey) TreeSet(java.util.TreeSet)

Example 9 with VariableKey

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();
}
Also used : ConcretePrereqObject(pcgen.cdom.base.ConcretePrereqObject) StringKey(pcgen.cdom.enumeration.StringKey) URI(java.net.URI) FormulaKey(pcgen.cdom.enumeration.FormulaKey) CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) IntegerKey(pcgen.cdom.enumeration.IntegerKey) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 10 with VariableKey

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")));
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) CDOMObject(pcgen.cdom.base.CDOMObject) VariableKey(pcgen.cdom.enumeration.VariableKey) CDOMObject(pcgen.cdom.base.CDOMObject) PCTemplate(pcgen.core.PCTemplate) CharID(pcgen.cdom.enumeration.CharID) Test(org.junit.Test)

Aggregations

VariableKey (pcgen.cdom.enumeration.VariableKey)14 CDOMObject (pcgen.cdom.base.CDOMObject)11 CharID (pcgen.cdom.enumeration.CharID)9 Test (org.junit.Test)8 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)8 PCTemplate (pcgen.core.PCTemplate)8 URI (java.net.URI)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Formula (pcgen.base.formula.Formula)1 WrappedMapSet (pcgen.base.util.WrappedMapSet)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMListObject (pcgen.cdom.base.CDOMListObject)1 ConcretePrereqObject (pcgen.cdom.base.ConcretePrereqObject)1 FormulaKey (pcgen.cdom.enumeration.FormulaKey)1 IntegerKey (pcgen.cdom.enumeration.IntegerKey)1 StringKey (pcgen.cdom.enumeration.StringKey)1