/// <summary> /// Gets the pattern components collections. /// </summary> /// <param name="scMatches">The symbol component matches.</param> /// <returns>The component matches grouped by design pattern.</returns> private List <PatternComponentCollection> GetPatternComponentsCollections(Dictionary <Component, List <ComponentMatch> > scMatches) { var collections = new List <PatternComponentCollection>(); foreach (var scMatch in scMatches) { var pattern = scMatch.Key.DesignPattern; var collection = collections.SingleOrDefault(c => c.DesignPattern == pattern); if (collection == null) { collection = new PatternComponentCollection(pattern); collections.Add(collection); } if (!collection.Components.ContainsKey(scMatch.Key)) { collection.Components.Add(scMatch.Key, new List <ComponentMatch>()); } // Defensive: avoid possible matches that did not correctly add to the list. var cleanedValue = scMatch.Value.Where(c => c != null); collection.Components[scMatch.Key].AddRange(cleanedValue); } return(collections); }
/// <summary> /// Gets a pattern result if it is valid, based on the design pattern configuration /// </summary> /// <param name="collection">The collection.</param> /// <returns>The valid design pattern</returns> private FoundDesignPattern GetPatternResult(PatternComponentCollection collection) { (var pattern, var componentMatches) = collection; // If a pattern does not contain the specified amount of components as matches, no result. if (pattern.Components.Count != componentMatches.Keys.Count) { return(null); } // if a pattern only has a single component, all matches belong to the same match. if (pattern.Components.Count == 1 && componentMatches.Keys.Count == 1) { return(this.MapSingleComponentPattern(pattern, componentMatches)); } return(this.MapMultipleComponentPattern(pattern, componentMatches)); }