Search in sources :

Example 6 with HashMapToList

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

the class QualifyToken method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<Qualifier> changes = context.getObjectContext().getListChanges(obj, ListKey.QUALIFY);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Collection<Qualifier> quals = changes.getAdded();
    HashMapToList<String, CDOMSingleRef<?>> map = new HashMapToList<>();
    for (Qualifier qual : quals) {
        Class<? extends Loadable> cl = qual.getQualifiedClass();
        String s = StringPClassUtil.getStringFor(cl);
        CDOMSingleRef<?> ref = qual.getQualifiedReference();
        String key = s;
        if (ref instanceof CategorizedCDOMReference) {
            Category<?> cat = ((CategorizedCDOMReference<?>) ref).getCDOMCategory();
            key += '=' + cat.getKeyName();
        }
        map.addToListFor(key, ref);
    }
    Set<CDOMSingleRef<?>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
    Set<String> returnSet = new TreeSet<>();
    for (String key : map.getKeySet()) {
        set.clear();
        set.addAll(map.getListFor(key));
        StringBuilder sb = new StringBuilder();
        sb.append(key).append(Constants.PIPE).append(ReferenceUtilities.joinLstFormat(set, Constants.PIPE));
        returnSet.add(sb.toString());
    }
    return returnSet.toArray(new String[returnSet.size()]);
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference) HashMapToList(pcgen.base.util.HashMapToList) TreeSet(java.util.TreeSet) Qualifier(pcgen.cdom.reference.Qualifier)

Example 7 with HashMapToList

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

the class ForwardRefToken method unparse.

@Override
public String[] unparse(LoadContext context, Campaign obj) {
    Changes<Qualifier> changes = context.getObjectContext().getListChanges(obj, ListKey.FORWARDREF);
    if (changes == null || changes.isEmpty()) {
        return null;
    }
    Collection<Qualifier> quals = changes.getAdded();
    HashMapToList<String, CDOMSingleRef<?>> map = new HashMapToList<>();
    for (Qualifier qual : quals) {
        Class<? extends Loadable> cl = qual.getQualifiedClass();
        String s = StringPClassUtil.getStringFor(cl);
        CDOMSingleRef<?> ref = qual.getQualifiedReference();
        String key = s;
        if (ref instanceof CategorizedCDOMReference) {
            String cat = ((CategorizedCDOMReference<?>) ref).getLSTCategory();
            if (Constants.FEAT_CATEGORY.equals(cat)) {
                key = Constants.FEAT_CATEGORY;
            } else {
                key += '=' + cat;
            }
        }
        map.addToListFor(key, ref);
    }
    Set<CDOMSingleRef<?>> set = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
    Set<String> returnSet = new TreeSet<>();
    for (String key : map.getKeySet()) {
        set.clear();
        set.addAll(map.getListFor(key));
        StringBuilder sb = new StringBuilder();
        sb.append(key).append(Constants.PIPE).append(ReferenceUtilities.joinLstFormat(set, Constants.COMMA));
        returnSet.add(sb.toString());
    }
    return returnSet.toArray(new String[returnSet.size()]);
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CategorizedCDOMReference(pcgen.cdom.reference.CategorizedCDOMReference) HashMapToList(pcgen.base.util.HashMapToList) TreeSet(java.util.TreeSet) Qualifier(pcgen.cdom.reference.Qualifier)

Example 8 with HashMapToList

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

the class DomainsToken method unparse.

@Override
public String[] unparse(LoadContext context, Deity deity) {
    CDOMReference<DomainList> dl = Deity.DOMAINLIST;
    AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), deity, dl);
    List<String> list = new ArrayList<>();
    Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
    if (changes.includesGlobalClear()) {
        if (removedItems != null && !removedItems.isEmpty()) {
            context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
            return null;
        }
        list.add(Constants.LST_DOT_CLEAR);
    } else if (removedItems != null && !removedItems.isEmpty()) {
        list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, ",.CLEAR.", true));
    }
    MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl != null && !mtl.isEmpty()) {
        MapToList<Set<Prerequisite>, CDOMReference<Domain>> m = new HashMapToList<>();
        for (CDOMReference<Domain> ab : mtl.getKeySet()) {
            for (AssociatedPrereqObject assoc : mtl.getListFor(ab)) {
                m.addToListFor(new HashSet<>(assoc.getPrerequisiteList()), ab);
            }
        }
        Set<String> set = new TreeSet<>();
        for (Set<Prerequisite> prereqs : m.getKeySet()) {
            Set<CDOMReference<Domain>> domainSet = new TreeSet<>(ReferenceUtilities.REFERENCE_SORTER);
            domainSet.addAll(m.getListFor(prereqs));
            StringBuilder sb = new StringBuilder(ReferenceUtilities.joinLstFormat(domainSet, Constants.COMMA, true));
            if (prereqs != null && !prereqs.isEmpty()) {
                sb.append(Constants.PIPE);
                sb.append(getPrerequisiteString(context, prereqs));
            }
            set.add(sb.toString());
        }
        list.addAll(set);
    }
    if (list.isEmpty()) {
        return null;
    }
    return list.toArray(new String[list.size()]);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) DomainList(pcgen.cdom.list.DomainList) HashMapToList(pcgen.base.util.HashMapToList) TreeSet(java.util.TreeSet) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 9 with HashMapToList

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

the class FeatAllListToken method getAbilityList.

/**
	 * @see pcgen.io.exporttoken.AbilityListToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
	 */
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.VIRTUAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Example 10 with HashMapToList

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

the class FeatAllToken method getAbilityList.

/**
	 * @see pcgen.io.exporttoken.AbilityToken#getAbilityList(pcgen.core.PlayerCharacter, pcgen.core.AbilityCategory)
	 */
@Override
protected MapToList<Ability, CNAbility> getAbilityList(PlayerCharacter pc, final AbilityCategory aCategory) {
    final MapToList<Ability, CNAbility> listOfAbilities = new HashMapToList<>();
    Collection<AbilityCategory> allCats = SettingsHandler.getGame().getAllAbilityCategories();
    for (AbilityCategory aCat : allCats) {
        if (aCat.getParentCategory().equals(aCategory)) {
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.NORMAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.AUTOMATIC)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
            for (CNAbility cna : pc.getPoolAbilities(aCat, Nature.VIRTUAL)) {
                listOfAbilities.addToListFor(cna.getAbility(), cna);
            }
        }
    }
    return listOfAbilities;
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) HashMapToList(pcgen.base.util.HashMapToList) AbilityCategory(pcgen.core.AbilityCategory)

Aggregations

HashMapToList (pcgen.base.util.HashMapToList)24 CNAbility (pcgen.cdom.content.CNAbility)15 Ability (pcgen.core.Ability)14 AbilityCategory (pcgen.core.AbilityCategory)14 ArrayList (java.util.ArrayList)5 TreeSet (java.util.TreeSet)5 CDOMReference (pcgen.cdom.base.CDOMReference)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)3 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 CategorizedCDOMReference (pcgen.cdom.reference.CategorizedCDOMReference)2 Qualifier (pcgen.cdom.reference.Qualifier)2 QualifiedObject (pcgen.core.QualifiedObject)2 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1