Created
March 2, 2012 15:46
-
-
Save DominicFinn/1959257 to your computer and use it in GitHub Desktop.
Diffs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Update(string updatedName, IEnumerable<Guid> updatedCountries) | |
{ | |
var countriesQueue = new Queue<Guid>(this.countries); | |
var updatedCountryList = new List<Guid>(updatedCountries); | |
var countriesToRemove = new List<Guid>(); | |
var countriesStillInGroup = new List<Guid>(); | |
List<Guid> countriestoAdd; | |
while (countriesQueue.Count > 0) | |
{ | |
var country = countriesQueue.Dequeue(); | |
//if the country is still in the updated list | |
if (updatedCountryList.Contains(country)) | |
{ | |
//Remove from update country list | |
updatedCountryList.Remove(country); | |
//Add it to still in list | |
countriesStillInGroup.Add(country); | |
} | |
else | |
{ | |
//doesn't contain it, add to remove list | |
countriesToRemove.Add(country); | |
} | |
} | |
//The stuff that's left in the update member list are new ones. | |
countriestoAdd = updatedCountryList; | |
var regionNameChanged = updatedName != this.name; | |
this.Apply(new RegionUpdated(updatedName, regionNameChanged, countriesStillInGroup, countriestoAdd, countriesToRemove)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment