55 lines
No EOL
2 KiB
C#
55 lines
No EOL
2 KiB
C#
using BuildingDirectory.Model;
|
|
|
|
namespace BuildingDirectory;
|
|
|
|
/// <summary>
|
|
/// Represents a simple building information system
|
|
/// </summary>
|
|
public sealed class BuildingInformation
|
|
{
|
|
private readonly MyDictionary<Floor, MyDictionary<string, Company>> _companiesPerFloor;
|
|
|
|
/// <summary>
|
|
/// Creates a new instance with the supplied building information
|
|
/// </summary>
|
|
/// <param name="companiesPerFloor"></param>
|
|
public BuildingInformation(MyDictionary<Floor, MyDictionary<string, Company>> companiesPerFloor)
|
|
{
|
|
_companiesPerFloor = companiesPerFloor;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns all floors in the building
|
|
/// </summary>
|
|
/// <returns>A list of available floors</returns>
|
|
public List<Floor> GetFloorSelection() => _companiesPerFloor.GetKeys();
|
|
|
|
/// <summary>
|
|
/// Returns all companies residing on a specific floor.
|
|
/// If floor is not available null is returned.
|
|
/// </summary>
|
|
/// <param name="floor">The floor to check</param>
|
|
/// <returns>A list of names of companies residing on the provided floor</returns>
|
|
public List<string>? GetCompaniesOnFloor(Floor floor)
|
|
{
|
|
_companiesPerFloor.TryGetValue(floor, out MyDictionary<string, Company>? companies);
|
|
return companies?.GetKeys();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the company identified by floor and company name.
|
|
/// If the specified company is not found null is returned.
|
|
/// </summary>
|
|
/// <param name="floor">Floor to look at</param>
|
|
/// <param name="companyName">Name of the requested company</param>
|
|
/// <returns>Company information if found; null otherwise</returns>
|
|
public Company? GetCompany(Floor floor, string companyName)
|
|
{
|
|
//Needed to declare here, else you get an initialization error
|
|
Company? company = null;
|
|
|
|
_companiesPerFloor.TryGetValue(floor, out MyDictionary<string, Company>? companies);
|
|
companies?.TryGetValue(companyName, out company);
|
|
return company;
|
|
}
|
|
} |