Search in sources :

Example 1 with TripleKeyMap

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

the class SpellsLst method processAdds.

private Collection<? extends String> processAdds(LoadContext context, MapToList<CDOMReference<Spell>, AssociatedPrereqObject> mtl) {
    TripleKeyMap<Set<Prerequisite>, Map<AssociationKey<?>, Object>, CDOMReference<Spell>, String> m = new TripleKeyMap<>();
    for (CDOMReference<Spell> lw : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(lw)) {
            Map<AssociationKey<?>, Object> am = new HashMap<>();
            String dc = null;
            for (AssociationKey<?> ak : assoc.getAssociationKeys()) {
                // else
                if (AssociationKey.DC_FORMULA.equals(ak)) {
                    dc = assoc.getAssociation(AssociationKey.DC_FORMULA);
                } else {
                    am.put(ak, assoc.getAssociation(ak));
                }
            }
            m.put(new HashSet<>(assoc.getPrerequisiteList()), am, lw, dc);
        }
    }
    Set<String> set = new TreeSet<>();
    for (Set<Prerequisite> prereqs : m.getKeySet()) {
        for (Map<AssociationKey<?>, Object> am : m.getSecondaryKeySet(prereqs)) {
            StringBuilder sb = new StringBuilder();
            sb.append(am.get(AssociationKey.SPELLBOOK));
            Formula times = AssociationKey.TIMES_PER_UNIT.cast(am.get(AssociationKey.TIMES_PER_UNIT));
            sb.append(Constants.PIPE).append("TIMES=").append(times);
            String timeunit = AssociationKey.TIME_UNIT.cast(am.get(AssociationKey.TIME_UNIT));
            if (timeunit != null) {
                sb.append(Constants.PIPE).append("TIMEUNIT=").append(timeunit);
            }
            String casterLvl = AssociationKey.CASTER_LEVEL.cast(am.get(AssociationKey.CASTER_LEVEL));
            if (casterLvl != null) {
                sb.append(Constants.PIPE).append("CASTERLEVEL=").append(casterLvl);
            }
            Set<String> spellSet = new TreeSet<>();
            for (CDOMReference<Spell> spell : m.getTertiaryKeySet(prereqs, am)) {
                String spellString = spell.getLSTformat(false);
                String dc = m.get(prereqs, am, spell);
                if (dc != null) {
                    spellString += Constants.COMMA + dc;
                }
                spellSet.add(spellString);
            }
            sb.append(Constants.PIPE);
            sb.append(StringUtil.join(spellSet, Constants.PIPE));
            if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
            }
            set.add(sb.toString());
        }
    }
    return set;
}
Also used : AssociationKey(pcgen.cdom.enumeration.AssociationKey) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Spell(pcgen.core.spell.Spell) Formula(pcgen.base.formula.Formula) TripleKeyMap(pcgen.base.util.TripleKeyMap) TreeSet(java.util.TreeSet) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DoubleKeyMap(pcgen.base.util.DoubleKeyMap) TripleKeyMap(pcgen.base.util.TripleKeyMap) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Formula (pcgen.base.formula.Formula)1 DoubleKeyMap (pcgen.base.util.DoubleKeyMap)1 TripleKeyMap (pcgen.base.util.TripleKeyMap)1 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CDOMReference (pcgen.cdom.base.CDOMReference)1 AssociationKey (pcgen.cdom.enumeration.AssociationKey)1 Prerequisite (pcgen.core.prereq.Prerequisite)1 Spell (pcgen.core.spell.Spell)1