Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created March 2, 2012 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DominicFinn/1959257 to your computer and use it in GitHub Desktop.
Save DominicFinn/1959257 to your computer and use it in GitHub Desktop.
Diffs
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