public override object DeepCopy() { Magazine other = (Magazine)MemberwiseClone(); other.PersonsList = new List <Person>(); other.ArticleList = new List <Article>(); foreach (Person person in PersonsList) { other.PersonsList.Add((Person)person.DeepCopy()); } foreach (Article article in ArticleList) { other.ArticleList.Add((Article)article.DeepCopy()); } return(other); }
/* * public MagazineCollection() : this(new List<Magazine>()) * { * } * * public MagazineCollection(List<Magazine> magazines) * { * Magazines = magazines; * } */ public void AddDefaults() { Magazines = new List <Magazine>(); Magazine fullMagazine = new Magazine(new Edition("name33", DateTime.Now, 123), "name1", Frequency.Montly, DateTime.Now, 10, new List <Person> { new Person(), new Person() }, new List <Article> { new Article(new Person(), "1", 50), new Article(new Person(), "2", 80) }); Magazines.Add(fullMagazine); Magazines.Add(new Magazine()); Magazines.Add(fullMagazine); }
public TestCollections(int count) { Editions = new List <Edition>(); Text = new List <string>(); EdMagDictionary = new Dictionary <Edition, Magazine>(); StMagDictionary = new Dictionary <string, Magazine>(); for (int i = 0; i < count; i++) { Magazine magazine = GetMegazine(i); Edition edition = magazine.EditionBase; Editions.Add(edition); Text.Add(edition.ToString()); EdMagDictionary.Add(edition, magazine); StMagDictionary.Add(edition.ToString(), magazine); } }
public static Magazine GetMegazine(int index) { Magazine magazine = new Magazine( new Edition( "editionName " + index, DateTime.Today.AddDays(index), index), "magazineName " + index, Frequency.Montly, DateTime.Today.AddDays(index + 1), index, new List <Person> { new Person("personName " + index + 1, "personLast " + index + 1, DateTime.Today.AddDays(index + 2)), new Person("personName " + index + 2, "personLast " + index + 2, DateTime.Today.AddDays(index + 3)), new Person("personName " + index + 3, "personLast " + index + 3, DateTime.Today.AddDays(index + 4)) }, new List <Article> { new Article(new Person("personName " + index + 1, "personLast " + index + 1, DateTime.Today.AddDays(index + 5)), "articleName " + index, index), new Article(new Person("personName " + index + 2, "personLast " + index + 2, DateTime.Today.AddDays(index + 6)), "articleName " + index + 2, index), new Article(new Person("personName " + index + 3, "personLast " + index + 3, DateTime.Today.AddDays(index + 7)), "articleName " + index + 3, index) }); return(magazine); }
static void Main(string[] args) { Magazine magazine = new Magazine("Daily Buglees", Frequency.Monthly, new DateTime(2010, 12, 12), 250000); magazine.AddArticles(new Article(new Person("Nick", "Back", new DateTime(1990, 10, 20)), "Corona-Time", 2.2)); magazine.AddEditors(new Person("Kek", "lol", new DateTime(1988, 8, 7))); MagazineCollection collection = new MagazineCollection(); collection.AddDefaults(); collection.AddMagazines(magazine); Console.WriteLine(collection.ToString()); Console.WriteLine("Sorted by mane: "); collection.SortByName(); Console.WriteLine(collection.ToString()); Console.WriteLine("Sorted by releaseDate:"); collection.SortByDate(); Console.WriteLine(collection.ToString()); Console.WriteLine("Sorted by copiesCount:"); collection.SortByDate(); Console.WriteLine(collection.ToString()); Console.WriteLine($"Max avg rate: {collection.MaxAvgRate}"); Console.WriteLine("Magazines with monthly frequency: "); Console.WriteLine(String.Join(",", collection.MonthlyMagazines.Select(magazineGroup => magazineGroup.ToString()).ToArray())); Console.WriteLine(collection.RatingGroup(2)); TestCollection testCollection = new TestCollection(2000); testCollection.MeasureTime(); }
protected bool Equals(Magazine other) { return(string.Equals(_magazineName, other._magazineName) && _timing == other._timing && _magazineDate.Equals(other._magazineDate) && _magazineCirculation == other._magazineCirculation && _articleList.SequenceEqual(other._articleList) && _personsList.SequenceEqual(other._personsList)); }