Ejemplo n.º 1
0
        public static TAccumulator Inject <TAccumulator, T>(this IComposite <T> composite,
                                                            TAccumulator accumulatorStartValue, Func <TAccumulator, T, TAccumulator> lambda,
                                                            TreeTraversalStrategy str)
        {
            var func = str.Traversal <T>();

            return(func(composite).Inject(accumulatorStartValue, lambda));
        }
Ejemplo n.º 2
0
 public IEnumerable <BTNode> Traverse()
 {
     @lock.EnterReadLock();
     try
     {
         return(TreeTraversalStrategy.Traverse(this));
     }
     finally
     {
         @lock.ExitReadLock();
     }
 }
        public static Func <IComposite <T>, IEnumerable <T> > Traversal <T>(this TreeTraversalStrategy str)
        {
            switch (str)
            {
            case TreeTraversalStrategy.PostOrderDepthFirst:
                return(CompositeExtensions.PostOrdered);

            case TreeTraversalStrategy.PreOrderDepthFirst:
                return(CompositeExtensions.PreOrdered);

            case TreeTraversalStrategy.BreadthFirst:
                return(CompositeExtensions.BreadthFirst);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public BTNode Find(string nodeName)
 {
     @lock.EnterReadLock();
     try
     {
         return(TreeTraversalStrategy.Traverse(this).
                Where(treeNode => treeNode.Name == nodeName).
                Single());
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
     finally
     {
         @lock.ExitReadLock();
     }
 }
Ejemplo n.º 5
0
 public static IEnumerable <T> Exclude <T>(this IComposite <T> composite, T element, TreeTraversalStrategy str)
 {
     return(composite.Where(t => !Equals(t, element), str));
 }
Ejemplo n.º 6
0
        public static IEnumerable <T> Where <T>(this IComposite <T> composite, Func <T, bool> predicate, TreeTraversalStrategy str)
        {
            var func = str.Traversal <T>();

            return(func(composite).Where(predicate));
        }
Ejemplo n.º 7
0
        public static IEnumerable <T> Select <T>(this IComposite <T> composite, Func <T, T> selector, TreeTraversalStrategy str)
        {
            var func = str.Traversal <T>();

            return(func(composite).Select(selector));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// applies an action to each content element of a composite, in the order given by a tree traversal strategy
        /// </summary>
        /// <typeparam name="T">the type of content element contained in the composite</typeparam>
        /// <param name="composite">the composite to iterate over</param>
        /// <param name="action">the action to apply</param>
        /// <param name="str">the tree traversal strategy to use</param>
        public static void Each <T>(this IComposite <T> composite, Action <T> action, TreeTraversalStrategy str)
        {
            var func = str.Traversal <T>();

            func(composite).Each(action);
        }