Browse Source

Refactor PackageFactory, internally use Dictionary

pull/5/head
Ionite 1 year ago
parent
commit
262c5aadba
No known key found for this signature in database
  1. 11
      StabilityMatrix/Helper/PackageFactory.cs

11
StabilityMatrix/Helper/PackageFactory.cs

@ -7,20 +7,23 @@ namespace StabilityMatrix.Helper;
public class PackageFactory : IPackageFactory public class PackageFactory : IPackageFactory
{ {
private readonly IEnumerable<BasePackage> basePackages; /// <summary>
/// Mapping of package.Name to package
/// </summary>
private readonly Dictionary<string, BasePackage> basePackages;
public PackageFactory(IEnumerable<BasePackage> basePackages) public PackageFactory(IEnumerable<BasePackage> basePackages)
{ {
this.basePackages = basePackages; this.basePackages = basePackages.ToDictionary(x => x.Name);
} }
public IEnumerable<BasePackage> GetAllAvailablePackages() public IEnumerable<BasePackage> GetAllAvailablePackages()
{ {
return basePackages; return basePackages.Values;
} }
public BasePackage? FindPackageByName(string packageName) public BasePackage? FindPackageByName(string packageName)
{ {
return basePackages.FirstOrDefault(x => x.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase)); return basePackages.GetValueOrDefault(packageName);
} }
} }

Loading…
Cancel
Save