2021-05-13 20:03:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
using BikeInfo = ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfo;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
|
namespace ShareeBike.Model.Bikes
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public class BikeCollection : IBikeDictionary<BikeInfo>
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Holds the bike dictionary object.</summary>
|
|
|
|
|
private Dictionary<string, BikeInfo> BikeDictionary { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>Constructs an empty bike info dictionary object.</summary>
|
|
|
|
|
public BikeCollection()
|
|
|
|
|
{
|
|
|
|
|
BikeDictionary = new Dictionary<string, BikeInfo>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Constructs a bike collection object.</summary>
|
|
|
|
|
/// <param name="bikeDictionary"></param>
|
|
|
|
|
public BikeCollection(Dictionary<string, BikeInfo> bikeDictionary)
|
|
|
|
|
{
|
|
|
|
|
BikeDictionary = bikeDictionary ??
|
|
|
|
|
throw new ArgumentNullException(nameof(bikeDictionary), "Can not construct BikeCollection object.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets a bike by its id.</summary>
|
|
|
|
|
/// <param name="id">Id of the bike to get.</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public BikeInfo GetById(string id)
|
|
|
|
|
{
|
|
|
|
|
return BikeDictionary.FirstOrDefault(x => x.Key == id).Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets the count of bikes. </summary>
|
|
|
|
|
public int Count => BikeDictionary.Count;
|
|
|
|
|
|
|
|
|
|
/// <summary> Gets if a bike with given id exists.</summary>
|
|
|
|
|
/// <param name="id">Id of bike.</param>
|
|
|
|
|
/// <returns>True if bike is contained, false otherwise.</returns>
|
|
|
|
|
public bool ContainsKey(string id) => BikeDictionary.Keys.Contains(id);
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|