Exemple #1
0
        /// <summary>Insert the given element to the created/deleted list.</summary>
        /// <param name="i">
        /// the insertion point defined
        /// in
        /// <see cref="Sharpen.Collections.BinarySearch{T}(System.Collections.Generic.IList{E}, object)
        ///     "/>
        /// </param>
        private void Insert(Diff.ListType type, E element, int i)
        {
            IList <E> list = type == Diff.ListType.Created ? created : deleted;

            if (i >= 0)
            {
                throw new Exception("Element already exists: element=" + element + ", " + type +
                                    "=" + list);
            }
            if (list == null)
            {
                list = new AList <E>(DefaultArrayInitialCapacity);
                if (type == Diff.ListType.Created)
                {
                    created = list;
                }
                else
                {
                    if (type == Diff.ListType.Deleted)
                    {
                        deleted = list;
                    }
                }
            }
            list.Add(-i - 1, element);
        }
Exemple #2
0
        /// <returns>
        /// null if the element is not found;
        /// otherwise, return the element in the created/deleted list.
        /// </returns>
        public virtual E Search(Diff.ListType type, K name)
        {
            IList <E> list = GetList(type);
            int       c    = Search(list, name);

            return(c < 0 ? null : list[c]);
        }
Exemple #3
0
            private bool RemoveChild(Diff.ListType type, INode child)
            {
                IList <INode> list = GetList(type);
                int           i    = SearchIndex(type, child.GetLocalNameBytes());

                if (i >= 0 && list[i] == child)
                {
                    list.Remove(i);
                    return(true);
                }
                return(false);
            }
Exemple #4
0
            /// <summary>Remove the given child in the created/deleted list, if there is any.</summary>
            public virtual bool RemoveChild(Diff.ListType type, INode child)
            {
                IList <DirectoryWithSnapshotFeature.DirectoryDiff> diffList = AsList();

                for (int i = diffList.Count - 1; i >= 0; i--)
                {
                    DirectoryWithSnapshotFeature.ChildrenDiff diff = diffList[i].diff;
                    if (diff.RemoveChild(type, child))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemple #5
0
            /// <summary>Replace the given child from the created/deleted list.</summary>
            /// <returns>true if the child is replaced; false if the child is not found.</returns>
            private bool Replace(Diff.ListType type, INode oldChild, INode newChild)
            {
                IList <INode> list = GetList(type);
                int           i    = Search(list, oldChild.GetLocalNameBytes());

                if (i < 0 || list[i].GetId() != oldChild.GetId())
                {
                    return(false);
                }
                INode removed = list.Set(i, newChild);

                Preconditions.CheckState(removed == oldChild);
                return(true);
            }
Exemple #6
0
 public virtual int SearchIndex(Diff.ListType type, K name)
 {
     return(Search(GetList(type), name));
 }
Exemple #7
0
        /// <returns>the created list, which is never null.</returns>
        public virtual IList <E> GetList(Diff.ListType type)
        {
            IList <E> list = type == Diff.ListType.Created ? created : deleted;

            return(list == null?Sharpen.Collections.EmptyList <E>() : list);
        }