using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo; namespace TINK.Model.Bikes { public class BikeCollection : IBikeDictionary { /// Holds the bike dictionary object. private Dictionary BikeDictionary { get; } /// Constructs an empty bike info dictionary object. public BikeCollection() { BikeDictionary = new Dictionary(); } /// Constructs a bike collection object. /// public BikeCollection(Dictionary bikeDictionary) { BikeDictionary = bikeDictionary ?? throw new ArgumentNullException(nameof(bikeDictionary), "Can not construct BikeCollection object."); } /// Gets a bike by its id. /// Id of the bike to get. /// public BikeInfo GetById(string id) { return BikeDictionary.FirstOrDefault(x => x.Key == id).Value; } /// Gets the count of bikes. public int Count => BikeDictionary.Count; /// Gets if a bike with given id exists. /// Id of bike. /// True if bike is contained, false otherwise. public bool ContainsKey(string id) => BikeDictionary.Keys.Contains(id); /// Gets the enumerator. /// Enumerator object. public IEnumerator GetEnumerator() => BikeDictionary.Values.GetEnumerator(); /// Gets the enumerator. /// Enumerator object. IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } }