当前位置: 首页>>代码示例>>C#>>正文


C# Queue.All方法代码示例

本文整理汇总了C#中Queue.All方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.All方法的具体用法?C# Queue.All怎么用?C# Queue.All使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.All方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QueueExtensions_All_ReturnsTrueIfQueueIsEmpty

        public void QueueExtensions_All_ReturnsTrueIfQueueIsEmpty()
        {
            var queue = new Queue<Int32>();

            var result = queue.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:8,代码来源:QueueExtensionsTest.cs

示例2: QueueExtensions_All_ReturnsTrueIfAllItemsMatchPredicate

        public void QueueExtensions_All_ReturnsTrueIfAllItemsMatchPredicate()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(2);
            queue.Enqueue(4);
            queue.Enqueue(6);

            var result = queue.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:11,代码来源:QueueExtensionsTest.cs

示例3: QueueExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate

        public void QueueExtensions_All_ReturnsFalseIfOneItemDoesNotMatchPredicate()
        {
            var queue = new Queue<Int32>();
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(4);
            queue.Enqueue(6);

            var result = queue.All(x => x % 2 == 0);

            TheResultingValue(result).ShouldBe(false);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:12,代码来源:QueueExtensionsTest.cs

示例4: ReadUntilToken

        private string ReadUntilToken(string token)
        {
            Queue<char> q = new Queue<char>(token.Length);
            char[] b = new char[1];
            StringBuilder sb = new StringBuilder();
            bool readZero = false;

            while (true)
            {
                if (q.Count < token.Length && !readZero)
                {
                    if (reader.Read(b, 0, 1) != 0)
                        q.Enqueue(b[0]);
                    else readZero = true;
                }
                else
                {
                    int i = 0;
                    if (q.All(delegate(char c) { return token[i++] == c; }) || (readZero && q.Count == 0))
                        return sb.ToString();
                    else
                        sb.Append(q.Dequeue());
                }
            }
        }
开发者ID:TheProjecter,项目名称:flatiron,代码行数:25,代码来源:CommandReader.cs

示例5: ParseChunk

        public static IList<ParsedChunk> ParseChunk(string input)
        {
            #region init

            // init
            var toReturn = new List<ParsedChunk>();
            var openTags = new Stack<BbTag>();
            var tags = new Queue<BbTag>();
            var processedQueue = new Queue<BbTag>();

            var finder = new BbFinder(input);

            // find all tags
            while (!finder.HasReachedEnd)
            {
                var next = finder.Next();
                if (next != null)
                    tags.Enqueue(next);
            }

            // return original input if we've no valid bbcode tags
            if (tags.All(x => x.Type == BbCodeType.None))
                return new[] {AsChunk(input)};

            #endregion

            #region handle unbalanced tags

            var unbalancedTags =
                (from t in tags
                    where t.Type != BbCodeType.None
                    group t by t.Type
                    into g
                    select new {Type = g.Key, Tags = g})
                    .Where(x => x.Tags.Count()%2 == 1);

            foreach (var tagGroup in unbalancedTags.ToList())
                tagGroup.Tags.First().Type = BbCodeType.None;

            #endregion

            while (tags.Count > 0)
            {
                // get the next tag to process
                var tag = tags.Dequeue();
                var addToQueue = true;

                #region add as child of last tag

                // check if we're in the context of another open tag
                if (openTags.Count > 0)
                {
                    var lastOpen = openTags.Peek();

                    // check if we're the closing for the last open tag
                    if (lastOpen.Type == tag.Type
                        && tag.IsClosing)
                    {
                        lastOpen.ClosingTag = tag;
                        openTags.Pop();

                        #region handle noparse

                        if (lastOpen.Type == BbCodeType.NoParse)
                        {
                            lastOpen.Children = lastOpen.Children ?? new List<BbTag>();
                            lastOpen.Children.Add(new BbTag
                                {
                                    Type = BbCodeType.None,
                                    End = tag.Start,
                                    Start = lastOpen.End
                                });
                        }

                        #endregion
                    }
                    else
                    {
                        if (lastOpen.Type != BbCodeType.NoParse)
                        {
                            // if not, we have to be a child of it
                            lastOpen.Children = lastOpen.Children ?? new List<BbTag>();

                            lastOpen.Children.Add(tag);
                        }

                        addToQueue = false;
                    }
                }

                #endregion

                // we don't need to continue processing closing tags
                if (tag.IsClosing) continue;

                // tell the system we're in the context of this tag now
                if (tag.Type != BbCodeType.None) // text content can't have children
                    openTags.Push(tag);

                // if we're added as a child to another tag, don't process independently of parent
//.........这里部分代码省略.........
开发者ID:Khayde,项目名称:slimCat,代码行数:101,代码来源:Converters.cs

示例6: PrintTree

        public static void PrintTree(Queue<INode> queue, int level, int maxLevel)
        {
            if (queue.Count == 0 || queue.All(item => item == null))
            {
                return;
            }

            int floor = maxLevel - level;
            int edgeLines = (int) Math.Pow(2, (Math.Max(floor - 1, 0)));
            int firstSpaces = (int) Math.Pow(2, floor) - 1;
            int betweenSpaces = (int) Math.Pow(2, (floor + 1)) - 1;

            PrintWhiteSpace(firstSpaces);

            List<INode> nodes = new List<INode>(queue.Count);
            while (queue.Count > 0)
            {
                nodes.Add(queue.Dequeue());
            }

            foreach (INode node in nodes)
            {
                if (node != null)
                {
                    if (node.IsLeaf())
                    {
                        Console.Write(node.Leaf().Id);
                    }
                    else
                    {
                        Console.Write(".");
                    }

                    queue.Enqueue(node.Left());
                    queue.Enqueue(node.Right());
                }
                else
                {
                    queue.Enqueue(null);
                    queue.Enqueue(null);
                    PrintWhiteSpace(1);
                }
                PrintWhiteSpace(betweenSpaces);
            }

            Console.WriteLine();

            for (int ii = 1; ii <= edgeLines; ii++)
            {
                for (int jj = 0; jj < nodes.Count; jj++)
                {
                    PrintWhiteSpace(firstSpaces - ii);
                    if (nodes[jj] == null)
                    {
                        PrintWhiteSpace(edgeLines + edgeLines + ii + 1);
                        continue;
                    }

                    if (nodes[jj].Left() != null)
                    {
                        Console.Write("/");
                    }
                    else
                    {
                        PrintWhiteSpace(1);
                    }

                    PrintWhiteSpace(ii + ii - 1);

                    if (nodes[jj].Right() != null)
                    {
                        Console.Write("\\");
                    }
                    else
                    {
                        PrintWhiteSpace(1);
                    }

                    PrintWhiteSpace(edgeLines + edgeLines - ii);
                }
                Console.WriteLine("");
            }

            PrintTree(queue, level + 1, maxLevel);
        }
开发者ID:Algorithmix,项目名称:Papyrus,代码行数:85,代码来源:Helpers.cs

示例7: ParseChunk

        public static IList<ParsedChunk> ParseChunk(string input)
        {
            #region init

            // init
            var toReturn = new List<ParsedChunk>();
            var openTags = new Stack<BbTag>();
            var tags = new Queue<BbTag>();
            var processedQueue = new Queue<BbTag>();

            var finder = new BbFinder(input);

            // find all tags
            while (!finder.HasReachedEnd)
            {
                var next = finder.Next();
                if (next != null)
                    tags.Enqueue(next);
            }


            // return original input if we've no valid bbcode tags
            if (tags.All(x => x.Type == BbCodeType.None))
                return new[] {AsChunk(input)};

            #endregion

            while (tags.Count > 0)
            {
                // get the next tag to process
                var tag = tags.Dequeue();
                var addToQueue = true;

                #region add as child of last tag

                // check if we're in the context of another open tag
                if (openTags.Count > 0)
                {
                    var lastOpen = openTags.Peek();
                    var lastMatching = openTags.FirstOrDefault(x => tag.IsClosing && x.Type == tag.Type);

                    // check if we're closing any previous tags
                    if (lastMatching != null)
                    {
                        lastMatching.ClosingTag = tag;

                        // keep going through our opened tag stack until we find the one
                        // we're closing
                        do
                        {
                            lastOpen = openTags.Pop();

                            // if we end up with a tag that isn't the one we're closing,
                            // it must not have been closed correctly, e.g
                            // [i] [b] [/i]
                            // we'll treat that '[b]' as text
                            if (lastOpen != lastMatching) lastOpen.Type = BbCodeType.None;
                        } while (lastOpen != lastMatching);

                        #region handle noparse

                        if (lastMatching.Type == BbCodeType.NoParse)
                        {
                            lastMatching.Children = lastMatching.Children ?? new List<BbTag>();
                            lastMatching.Children.Add(new BbTag
                            {
                                Type = BbCodeType.None,
                                End = tag.Start,
                                Start = lastMatching.End
                            });
                        }

                        #endregion
                    }
                    else
                    {
                        if (openTags.All(x => x.Type != BbCodeType.NoParse))
                        {
                            // if not, we have to be a child of it
                            lastOpen.Children = lastOpen.Children ?? new List<BbTag>();

                            lastOpen.Children.Add(tag);
                        }

                        // any matching closing tags would be caught in the if part of this
                        // branch, this is an invalid tag, treat as text
                        if (tag.IsClosing) tag.Type = BbCodeType.None;

                        addToQueue = false;
                    }
                }

                #endregion

                // we don't need to continue processing closing tags
                if (tag.IsClosing) continue;

                // tell the system we're in the context of this tag now
                // though ignore children of 'text' and 'hr'
                if (tag.Type != BbCodeType.None && tag.Type != BbCodeType.HorizontalRule)
//.........这里部分代码省略.........
开发者ID:ZornTaov,项目名称:slimCat,代码行数:101,代码来源:BbCodeBaseConverter.cs


注:本文中的Queue.All方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。