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()]);
}
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()]);
}
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()]);
}
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;
}
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;
}
Aggregations