Search in sources :

Example 1 with TreeMapToList

use of pcgen.base.util.TreeMapToList in project pcgen by PCGen.

the class ConsolidatedListCommitStrategy method getChangesInMasterList.

@Override
public <T extends CDOMObject> AssociatedChanges<T> getChangesInMasterList(String tokenName, CDOMObject owner, CDOMReference<? extends CDOMList<T>> swl) {
    Set<CDOMObject> added = masterList.getSecondaryKeySet(swl);
    MapToList<T, AssociatedPrereqObject> owned = new TreeMapToList<>(CDOMObjectUtilities.CDOM_SORTER);
    for (CDOMObject lw : added) {
        List<AssociatedPrereqObject> list = masterList.getListFor(swl, lw);
        for (AssociatedPrereqObject assoc : list) {
            if (owner.equals(assoc.getAssociation(AssociationKey.OWNER))) {
                owned.addToListFor((T) lw, assoc);
                break;
            }
        }
    }
    return new AssociatedCollectionChanges<>(owned, null, false);
}
Also used : TreeMapToList(pcgen.base.util.TreeMapToList) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 2 with TreeMapToList

use of pcgen.base.util.TreeMapToList in project pcgen by PCGen.

the class KnownspellsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    Changes<KnownSpellIdentifier> changes = context.getObjectContext().getListChanges(pcc, ListKey.KNOWN_SPELLS);
    List<String> list = new ArrayList<>();
    if (changes.includesGlobalClear()) {
        list.add(Constants.LST_DOT_CLEAR_ALL);
    }
    Collection<KnownSpellIdentifier> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR.");
        return null;
    }
    Collection<KnownSpellIdentifier> added = changes.getAdded();
    if (added != null && !added.isEmpty()) {
        TreeMapToList<CDOMReference<?>, Integer> map = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
        for (KnownSpellIdentifier ksi : added) {
            CDOMReference<Spell> ref = ksi.getSpellReference();
            Integer i = ksi.getSpellLevel();
            map.addToListFor(ref, i);
        }
        for (CDOMReference<?> ref : map.getKeySet()) {
            for (Integer lvl : map.getListFor(ref)) {
                StringBuilder sb = new StringBuilder();
                boolean needComma = false;
                String refString = ref.getLSTformat(false);
                if (!Constants.LST_ALL.equals(refString)) {
                    sb.append(refString);
                    needComma = true;
                }
                if (lvl != null) {
                    if (needComma) {
                        sb.append(',');
                    }
                    sb.append("LEVEL=").append(lvl);
                }
                list.add(sb.toString());
            }
        }
    }
    if (list.isEmpty()) {
        return null;
    }
    return new String[] { StringUtil.join(list, Constants.PIPE) };
}
Also used : KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) TreeMapToList(pcgen.base.util.TreeMapToList) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 3 with TreeMapToList

use of pcgen.base.util.TreeMapToList in project pcgen by PCGen.

the class ListChanges method getAddedAssociations.

@Override
public MapToList<CDOMReference<T>, AssociatedPrereqObject> getAddedAssociations() {
    Collection<CDOMReference<T>> mods = positive.getListMods(list);
    if (mods == null) {
        return null;
    }
    MapToList<CDOMReference<T>, AssociatedPrereqObject> owned = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
    for (CDOMReference<T> lw : mods) {
        Collection<AssociatedPrereqObject> assocs = positive.getListAssociations(list, lw);
        for (AssociatedPrereqObject assoc : assocs) {
            if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
                owned.addToListFor(lw, assoc);
            }
        }
    }
    if (owned.isEmpty()) {
        return null;
    }
    return owned;
}
Also used : TreeMapToList(pcgen.base.util.TreeMapToList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 4 with TreeMapToList

use of pcgen.base.util.TreeMapToList in project pcgen by PCGen.

the class ListChanges method getRemovedAssociations.

@Override
public MapToList<CDOMReference<T>, AssociatedPrereqObject> getRemovedAssociations() {
    MapToList<CDOMReference<T>, AssociatedPrereqObject> owned = new TreeMapToList<>(ReferenceUtilities.REFERENCE_SORTER);
    if (negative == null) {
        return owned;
    }
    Collection<CDOMReference<T>> mods = negative.getListMods(list);
    if (mods == null) {
        return owned;
    }
    for (CDOMReference<T> lw : mods) {
        Collection<AssociatedPrereqObject> assocs = negative.getListAssociations(list, lw);
        for (AssociatedPrereqObject assoc : assocs) {
            if (tokenName.equals(assoc.getAssociation(AssociationKey.TOKEN))) {
                owned.addToListFor(lw, assoc);
            }
        }
    }
    if (owned.isEmpty()) {
        return null;
    }
    return owned;
}
Also used : TreeMapToList(pcgen.base.util.TreeMapToList) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Aggregations

TreeMapToList (pcgen.base.util.TreeMapToList)4 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 ArrayList (java.util.ArrayList)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)1 Spell (pcgen.core.spell.Spell)1