From 262c5aadba0fb372e59c822877f470fd10989ea5 Mon Sep 17 00:00:00 2001 From: Ionite Date: Tue, 30 May 2023 13:47:07 -0400 Subject: [PATCH] Refactor PackageFactory, internally use Dictionary --- StabilityMatrix/Helper/PackageFactory.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/StabilityMatrix/Helper/PackageFactory.cs b/StabilityMatrix/Helper/PackageFactory.cs index f5535ffc..1c32a9de 100644 --- a/StabilityMatrix/Helper/PackageFactory.cs +++ b/StabilityMatrix/Helper/PackageFactory.cs @@ -7,20 +7,23 @@ namespace StabilityMatrix.Helper; public class PackageFactory : IPackageFactory { - private readonly IEnumerable basePackages; + /// + /// Mapping of package.Name to package + /// + private readonly Dictionary basePackages; public PackageFactory(IEnumerable basePackages) { - this.basePackages = basePackages; + this.basePackages = basePackages.ToDictionary(x => x.Name); } public IEnumerable GetAllAvailablePackages() { - return basePackages; + return basePackages.Values; } public BasePackage? FindPackageByName(string packageName) { - return basePackages.FirstOrDefault(x => x.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); + return basePackages.GetValueOrDefault(packageName); } }