When using the boolean = removeAll(Collection), does it assume that each value in the collection actually exists in the set in question?
I'm using:
Iterator<FactionAPI> allFactions = Global.getSector().getAllFactions().iterator();
Map<String, String> vanillaFactions = vanillaIDsDatabase.getFactionIDs();
while (allFactions.hasNext()) {
if (vanillaFactions.containsKey(allFactions.next().getId())) {
if (!allFactions.next().getKnownFighters().removeAll(vanillaIDsDatabase.getOverriddenFighterWingIDs().values())) {
LOG.error("Could not remove all overridden vanilla fighter wings from " + allFactions.next().getId());
}
if (!allFactions.next().getPriorityFighters().removeAll(vanillaIDsDatabase.getOverriddenFighterWingIDs().values())) {
LOG.error("Could not remove all overridden priority vanilla fighter wings from " + allFactions.next().getId());
}
}
}
This:
- Checks to make sure the faction is a vanilla one.
- Uses the values() method of a map containing the fighter wing ids for each vanilla fighter to remove them all from known fighters and priority fighters.
- Logs if this wasn't successful. Not sure if it logs if one isn't removed or only if all aren't removed.
Log:
Spoiler
42157 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden vanilla hullmods from remnant
42157 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden vanilla hullmods from hegemony
42157 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden priority vanilla fighter wings from poor
42157 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden priority vanilla fighter wings from independent
42157 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden vanilla fighter wings from persean
42158 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden priority vanilla fighter wings from knights_of_ludd
42158 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden vanilla fighter wings from adamantine_consortium
42158 [Thread-4] ERROR data.scripts.overrides.VanillaOverridesManager - Could not remove all overridden priority vanilla fighter wings from tritachyon
Annnd looking at this... why the
heck is it trying to do that for admantine_consortium?? That's not even in the ids map and should have failed the containsKey() check!
Arrgh that... doesn't make any sense! *EDIT*
Wait a minute, trying to think back to college but I think I understand what's going on now. I need to assign the Iterator.next() to a FactionAPI instead and use that when I need to check multiple things.
It's not failing the containsKey() it's just going to the next FactionAPI every time I call the next() method! *Feels dumb*
Anyway the initial question remains. Would it be better to iterate through the values, check for them to exist in the set and them remove them one by one? Or should passing in the collection do the job? Thanks!
Map contents:
Spoiler
public class VanillaIDsDatabase {
private static final Map<String, String> FACTION_IDS = new HashMap<>();
private static final Map<String, String> HULLMOD_IDS = new HashMap<>();
private static final Map<String, String> FIGHTER_SHIP_IDS = new HashMap<>();
private static final Map<String, String> FIGHTER_WING_IDS = new HashMap<>();
public void initMaps() {
// Vanilla faction ids.
FACTION_IDS.put("hegemony", "hegemony");
FACTION_IDS.put("luddic_church", "luddic_church");
FACTION_IDS.put("luddic_path", "luddic_path");
FACTION_IDS.put("sindrian_diktat", "sindrian_diktat");
FACTION_IDS.put("derelict", "derelict");
FACTION_IDS.put("independent", "independent");
FACTION_IDS.put("knights_of_ludd", "knights_of_ludd");
FACTION_IDS.put("lions_guard", "lions_guard");
FACTION_IDS.put("persean_league", "persean_league");
FACTION_IDS.put("pirates", "pirates");
FACTION_IDS.put("remnant", "remnant");
FACTION_IDS.put("scavengers", "scavengers");
FACTION_IDS.put("tritachyon", "tritachyon");
// Currently overridden vanilla hullmod ids.
HULLMOD_IDS.put("advancedoptics", "advancedoptics");
HULLMOD_IDS.put("turretgyros", "turretgyros");
HULLMOD_IDS.put("magazines", "magazines");
HULLMOD_IDS.put("missleracks", "missleracks");
HULLMOD_IDS.put("extendedshieldemitter", "extendedshieldemitter");
HULLMOD_IDS.put("frontemitter", "frontemitter");
HULLMOD_IDS.put("fluxcoil", "fluxcoil");
HULLMOD_IDS.put("fluxdistributor", "fluxdistributor");
HULLMOD_IDS.put("converted_hangar", "converted_hangar");
HULLMOD_IDS.put("operations_center", "operations_center");
HULLMOD_IDS.put("frontshield", "frontshield");
HULLMOD_IDS.put("heavyarmor", "heavyarmor");
HULLMOD_IDS.put("targetingunit", "targetingunit");
HULLMOD_IDS.put("adaptiveshields", "adaptiveshields");
HULLMOD_IDS.put("safetyoverrides", "safetyoverrides");
HULLMOD_IDS.put("stabilizedshieldemitter", "stabilizedshieldemitter");
HULLMOD_IDS.put("dedicated_targeting_core", "dedicated_targeting_core");
HULLMOD_IDS.put("augmentedengines", "augmentedengines");
HULLMOD_IDS.put("expanded_deck_crew", "expanded_deck_crew");
HULLMOD_IDS.put("unstable_injector", "unstable_injector");
HULLMOD_IDS.put("armoredweapons", "armoredweapons");
HULLMOD_IDS.put("autorepair", "autorepair");
// Add vanilla fighter ship definition ids.
FIGHTER_SHIP_IDS.put("talon", "talon");
FIGHTER_SHIP_IDS.put("dagger", "dagger");
FIGHTER_SHIP_IDS.put("wasp", "wasp");
FIGHTER_SHIP_IDS.put("xyphos", "xyphos");
FIGHTER_SHIP_IDS.put("broadsword", "broadsword");
FIGHTER_SHIP_IDS.put("piranha", "piranha");
FIGHTER_SHIP_IDS.put("trident", "trident");
FIGHTER_SHIP_IDS.put("longbow", "longbow");
FIGHTER_SHIP_IDS.put("mining_drone", "mining_drone");
FIGHTER_SHIP_IDS.put("gladius", "gladius");
FIGHTER_SHIP_IDS.put("warthog", "warthog");
FIGHTER_SHIP_IDS.put("thunder", "thunder");
FIGHTER_SHIP_IDS.put("claw", "claw");
FIGHTER_SHIP_IDS.put("hoplon", "hoplon");
FIGHTER_SHIP_IDS.put("spark", "spark");
FIGHTER_SHIP_IDS.put("lux", "lux");
FIGHTER_SHIP_IDS.put("flash", "flash");
FIGHTER_SHIP_IDS.put("perdition", "perdition");
FIGHTER_SHIP_IDS.put("cobra", "cobra");
// Add vanilla fighter wing ids.
FIGHTER_WING_IDS.put("talon_wing", "talon_wing");
FIGHTER_WING_IDS.put("xyphos_wing", "xyphos_wing");
FIGHTER_WING_IDS.put("gladius_wing", "gladius_wing");
FIGHTER_WING_IDS.put("warthog_wing", "warthog_wing");
FIGHTER_WING_IDS.put("thunder_wing", "thunder_wing");
FIGHTER_WING_IDS.put("claw_wing", "claw_wing");
FIGHTER_WING_IDS.put("wasp_wing", "wasp_wing");
FIGHTER_WING_IDS.put("dagger_wing", "dagger_wing");
FIGHTER_WING_IDS.put("piranha_wing", "piranha_wing");
FIGHTER_WING_IDS.put("trident_wing", "trident_wing");
FIGHTER_WING_IDS.put("perdition_wing", "perdition_wing");
FIGHTER_WING_IDS.put("cobra_wing", "cobra_wing");
FIGHTER_WING_IDS.put("longbow_wing", "longbow_wing");
FIGHTER_WING_IDS.put("mining_drone_wing,", "mining_drone_wing,");
FIGHTER_WING_IDS.put("flash_wing", "flash_wing");
FIGHTER_WING_IDS.put("spark_wing", "spark_wing");
FIGHTER_WING_IDS.put("lux_wing", "lux_wing");
}
public Map<String, String> getFactionIDs() {
return FACTION_IDS;
}
public Map<String, String> getOverriddenHullmodIDs() {
return HULLMOD_IDS;
}
public Map<String, String> getOverriddenFighterShipIDs() {
return FIGHTER_SHIP_IDS;
}
public Map<String, String> getOverriddenFighterWingIDs() {
return FIGHTER_WING_IDS;
}
}
*EDIT 2*
Ahh, nvm - missed this part of the interface documentation: * @return <tt>true</tt> if this set changed as a result of the call
I only read the description at first and that part didn't seem clear. Should of kept reading.
Hmm, now I'm wondering why the call is returning false so often. The set should have changed. Sigh, back to the drawing board.