sharee.bike-App/TINKLib/Model/Bikes/BikeCollection.cs

55 lines
2 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BikeInfo = TINK.Model.Bike.BC.BikeInfo;
namespace TINK.Model.Bike
{
public class BikeCollection : IBikeDictionary<BikeInfo>
{
/// <summary> Holds the bike dictionary object.</summary>
2021-06-26 20:57:55 +02:00
private Dictionary<string, BikeInfo> BikeDictionary { get; }
2021-05-13 20:03:07 +02:00
/// <summary>Constructs an empty bike info dictionary object.</summary>
public BikeCollection()
{
2021-06-26 20:57:55 +02:00
BikeDictionary = new Dictionary<string, BikeInfo>();
2021-05-13 20:03:07 +02:00
}
/// <summary> Constructs a bike collection object.</summary>
/// <param name="bikeDictionary"></param>
2021-06-26 20:57:55 +02:00
public BikeCollection(Dictionary<string, BikeInfo> bikeDictionary)
2021-05-13 20:03:07 +02:00
{
BikeDictionary = bikeDictionary ??
throw new ArgumentNullException(nameof(bikeDictionary), "Can not construct BikeCollection object.");
}
/// <summary> Gets a bike by its id.</summary>
2021-06-26 20:57:55 +02:00
/// <param name="id">Id of the bike to get.</param>
2021-05-13 20:03:07 +02:00
/// <returns></returns>
2021-06-26 20:57:55 +02:00
public BikeInfo GetById(string id)
2021-05-13 20:03:07 +02:00
{
2021-06-26 20:57:55 +02:00
return BikeDictionary.FirstOrDefault(x => x.Key == id).Value;
2021-05-13 20:03:07 +02:00
}
/// <summary> Gets the count of bikes. </summary>
public int Count => BikeDictionary.Count;
/// <summary> Gets if a bike with given id exists.</summary>
2021-06-26 20:57:55 +02:00
/// <param name="id">Id of bike.</param>
2021-05-13 20:03:07 +02:00
/// <returns>True if bike is contained, false otherwise.</returns>
2021-06-26 20:57:55 +02:00
public bool ContainsKey(string id) => BikeDictionary.Keys.Contains(id);
2021-05-13 20:03:07 +02:00
/// <summary> Gets the enumerator. </summary>
/// <returns>Enumerator object.</returns>
public IEnumerator<BikeInfo> GetEnumerator() => BikeDictionary.Values.GetEnumerator();
/// <summary> Gets the enumerator. </summary>
/// <returns>Enumerator object.</returns>
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}