Пример #1
0
            public void Step(Step step)
            {
                if (Children.Count != 0)
                {
                    foreach (Group other in Children)
                    {
                        other.Step(step);
                    }
                    return;
                }

                if (Items.Count <= 1)
                {
                    return;
                }

                if ((Items.Count == 2 && (step.IsFlat ?? true)) || (step.IsFlat ?? false))
                {
                    Items.Sort(step);
                    return;
                }

                string stepName = step.GetType().Name;

                Group group = new Group(stepName, new List <T>()
                {
                    Items[0]
                });

                Children.Add(group);

                for (int i = 1; i < Items.Count; i++)
                {
                    T item = Items[i];

                    if (step.Any(group.Items, item))
                    {
                        Group groupPrev = group;
                        group = null;

                        if (Children.Count > 1)
                        {
                            foreach (Group otherGroup in Children)
                            {
                                if (otherGroup == groupPrev)
                                {
                                    continue;
                                }
                                if (step.Any(otherGroup.Items, item) ||
                                    step.Any(otherGroup.NonMatching, item))
                                {
                                    continue;
                                }
                                group = otherGroup;
                                break;
                            }
                        }

                        if (group == null)
                        {
                            group = new Group(stepName);
                            Children.Add(group);
                            group.NonMatching.Add(groupPrev);
                            groupPrev.NonMatching.Add(group);
                        }
                    }

                    group.Items.Add(item);
                }

                if (Children.Count == 1)
                {
                    Children.Clear();
                    return;
                }

                Children.Sort(step.ForGroup);
            }