using System; using System.Collections.Generic; namespace Lab5.TouristInformationCenter { /// /// Class used to store multiple locations in one place /// class Register { private LocationsContainer AllLocations; public Register() { AllLocations = new LocationsContainer(); } public Register(LocationsContainer locations) { AllLocations = new LocationsContainer(locations); } /// /// Add one location to the register. /// /// Target location public void Add(Location location) { AllLocations.Add(location); } /// /// The amount of stored locations in the register. /// /// Location count public int Count() { return AllLocations.Count; } /// /// Access location from register by index /// /// Target index /// Location public Location GetByIndex(int index) { return AllLocations.Get(index); } public int CountLocationsThatHaveGuides() { int count = 0; for (int i = 0; i < AllLocations.Count; i++) { Museum museum = AllLocations.Get(i) as Museum; if (museum != null && museum.HasGuide) { count++; } } return count; } /// /// Get all of the different types of cities. /// /// A list of city names public List GetAllCities() { List cities = new List(); for (int i = 0; i < AllLocations.Count; i++) { Location location = AllLocations.Get(i); if (!cities.Contains(location.City)) { cities.Add(location.City); } } return cities; } public List GetAllTypes() { List types = new List(); for (int i = 0; i < AllLocations.Count; i++) { Museum museum = AllLocations.Get(i) as Museum; if (museum != null && !types.Contains(museum.Type)) { types.Add(museum.Type); } } return types; } public List FindCommonTypesBetweenCities() { List allCities = GetAllCities(); Dictionary types = new Dictionary(); foreach (string type in GetAllTypes()) { types.Add(type, 0); foreach (string city in allCities) { for (int i = 0; i < AllLocations.Count; i++) { Museum museum = AllLocations.Get(i) as Museum; if (museum != null && museum.Type == type && museum.City == city) { types[type]++; break; } } } } List result = new List(); foreach (var item in types) { if (item.Value == allCities.Count) { result.Add(item.Key); } } return result; } public bool HasGuideAtWeekendByType(string type) { for (int i = 0; i < AllLocations.Count; i++) { Museum museum = AllLocations.Get(i) as Museum; if (museum != null && museum.Type == type && museum.HasGuide && (museum.Workdays.Contains(Weekday.Saturday) || museum.Workdays.Contains(Weekday.Sunday))) { return true; } } return false; } public List FindCommonTypesWithGuidesAtWeekends() { List types = new List(); foreach (string type in FindCommonTypesBetweenCities()) { if (HasGuideAtWeekendByType(type)) { types.Add(type); } } return types; } public LocationsContainer FindLocationsByAuthor(string author) { LocationsContainer locations = new LocationsContainer(); for (int i = 0; i < AllLocations.Count; i++) { Statue statue = AllLocations.Get(i) as Statue; if (statue != null && statue.Author == author) { locations.Add(statue); } } return locations; } public LocationsContainer FindLocationsAfterYear(int year) { LocationsContainer locations = new LocationsContainer(); for (int i = 0; i < AllLocations.Count; i++) { Location location = AllLocations.Get(i); if (location.Year > year) { locations.Add(location); } } return locations; } } }