Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.PluginInfrastructure/3.3/PluginDescriptionIterator.cs @ 5593

Last change on this file since 5593 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24
25namespace HeuristicLab.PluginInfrastructure.Manager {
26  internal static class PluginDescriptionIterator {
27    internal static IEnumerable<PluginDescription> IterateDependenciesBottomUp(IEnumerable<PluginDescription> pluginDescriptions) {
28      // list to make sure we yield each description only once
29      HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
30      foreach (var desc in pluginDescriptions) {
31        foreach (var dependency in IterateDependenciesBottomUp(desc.Dependencies)) {
32          if (!yieldedDescriptions.Contains(dependency)) {
33            yieldedDescriptions.Add(dependency);
34            yield return dependency;
35          }
36        }
37        if (!yieldedDescriptions.Contains(desc)) {
38          yieldedDescriptions.Add(desc);
39          yield return desc;
40        }
41      }
42    }
43
44    internal static IEnumerable<PluginDescription> IterateDependentsTopDown(IEnumerable<PluginDescription> pluginDescriptions, IEnumerable<PluginDescription> allPlugins) {
45      HashSet<PluginDescription> yieldedDescriptions = new HashSet<PluginDescription>();
46      foreach (var desc in pluginDescriptions) {
47        foreach (var dependent in IterateDependentsTopDown(GetDependentPlugins(desc, allPlugins), allPlugins)) {
48          if (!yieldedDescriptions.Contains(dependent)) {
49            yieldedDescriptions.Add(dependent);
50            yield return dependent;
51          }
52        }
53        if (!yieldedDescriptions.Contains(desc)) {
54          yieldedDescriptions.Add(desc);
55          yield return desc;
56        }
57      }
58    }
59
60    private static IEnumerable<PluginDescription> GetDependentPlugins(PluginDescription desc, IEnumerable<PluginDescription> allPlugins) {
61      return from plugin in allPlugins
62             where plugin.Dependencies.Contains(desc)
63             select plugin;
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.