Пример #1
0
        public void ValidateIndexPath()
        {
            RunOnUIThread.Execute(() =>
            {
                IndexPath path = IndexPath.CreateFromIndices(null);
                Verify.AreEqual(0, path.GetSize());

                path = IndexPath.CreateFrom(5);
                Verify.AreEqual(1, path.GetSize());
                Verify.AreEqual(5, path.GetAt(0));

                path = IndexPath.CreateFrom(1, 2);
                Verify.AreEqual(2, path.GetSize());
                Verify.AreEqual(1, path.GetAt(0));
                Verify.AreEqual(2, path.GetAt(1));

                Verify.AreEqual(0, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(0, 1)));
                Verify.AreEqual(-1, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(1, 0)));
                Verify.AreEqual(1, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(0, 0)));

                Verify.AreEqual(-1, IndexPath.CreateFrom(1, 0).CompareTo(IndexPath.CreateFrom(1, 1)));
                Verify.AreEqual(0, IndexPath.CreateFrom(1, 0).CompareTo(IndexPath.CreateFrom(1, 0)));
                Verify.AreEqual(1, IndexPath.CreateFrom(1, 1).CompareTo(IndexPath.CreateFrom(1, 0)));


                var emptyPath = IndexPath.CreateFromIndices(null);
                Verify.AreEqual(0, emptyPath.CompareTo(emptyPath));
                var path1 = IndexPath.CreateFrom(1);
                Verify.AreEqual(-1, emptyPath.CompareTo(path1));
                Verify.AreEqual(1, path1.CompareTo(emptyPath));
                var path12 = IndexPath.CreateFrom(1, 2);
                Verify.AreEqual(-1, path1.CompareTo(path12));
                Verify.AreEqual(1, path12.CompareTo(path1));
            });
        }
Пример #2
0
        private static void Traverse(object root, Action <TreeWalkNodeInfo> nodeAction)
        {
            var       pendingNodes = new Stack <TreeWalkNodeInfo>();
            IndexPath current      = Path(null);

            pendingNodes.Push(new TreeWalkNodeInfo()
            {
                Current = root, Path = current
            });

            while (pendingNodes.Count > 0)
            {
                var currentNode   = pendingNodes.Pop();
                var currentObject = currentNode.Current as IList;

                if (currentObject != null)
                {
                    for (int i = currentObject.Count - 1; i >= 0; i--)
                    {
                        var        child = currentObject[i];
                        List <int> path  = new List <int>();
                        for (int idx = 0; idx < currentNode.Path.GetSize(); idx++)
                        {
                            path.Add(currentNode.Path.GetAt(idx));
                        }

                        path.Add(i);
                        var childPath = IndexPath.CreateFromIndices(path);
                        if (child != null)
                        {
                            pendingNodes.Push(new TreeWalkNodeInfo()
                            {
                                Current = child, Path = childPath
                            });
                        }
                    }
                }

                nodeAction(currentNode);
            }
        }
Пример #3
0
 public static IndexPath Path(params int[] path)
 {
     return(IndexPath.CreateFromIndices(path));
 }