예제 #1
0
파일: Identity.cs 프로젝트: rfellers/pwiz
        public static IdentityPath ToIdentityPath(IList <int> idPath, SrmDocument document)
        {
            IdentityPath identityPath = ROOT;
            DocNode      next         = document;

            foreach (int globalIndex in idPath)
            {
                DocNodeParent parent = next as DocNodeParent;
                if (null == parent)
                {
                    return(null);
                }
                next = null;
                foreach (var child in parent.Children)
                {
                    if (child.Id.GlobalIndex == globalIndex)
                    {
                        next = child;
                        break;
                    }
                }
                if (null == next)
                {
                    return(null);
                }
                identityPath = new IdentityPath(identityPath, next.Id);
            }
            return(identityPath);
        }
예제 #2
0
        /// <summary>
        /// Traverses the <see cref="DocNode"/> tree, performing an action on the
        /// final node specified in the path.
        /// </summary>
        /// <typeparam name="TTag">Type of the tag object used at the final node to perform the action</typeparam>
        /// <param name="parent">The parent node to use in the next recursive call</param>
        /// <param name="tag">The tag instance that will be used to perform the action</param>
        /// <returns>An alterer parent node</returns>
        /// <param name="recurse">Recursive descent function</param>
        /// <param name="act">Action function</param>
        /// <returns>An altered copy of the <see cref="parent"/> node</returns>
        public DocNodeParent Traverse <TTag>(DocNodeParent parent, TTag tag, Recurse <TTag> recurse, Act <TTag> act)
        {
            if (HasNext)
            {
                Identity nextId = Next();

                // Look for the right child
                foreach (DocNode nodeNext in parent.Children)
                {
                    if (ReferenceEquals(nextId, nodeNext.Id))
                    {
                        DocNodeParent subParent = nodeNext as DocNodeParent;
                        if (subParent == null)
                        {
                            throw new InvalidOperationException(Resources.IdentityPathTraversal_Traverse_Invalid_attempt_to_perform_parent_operation_on_leaf_node);
                        }

                        // Make recursive call into the specified child
                        return(parent.ReplaceChild(recurse(subParent, this, tag)));
                    }
                }
                throw new IdentityNotFoundException(nextId);
            }

            return(act(tag));
        }
예제 #3
0
        protected override IList <DocNode> OnChangingChildren(DocNodeParent clone, int indexReplaced)
        {
            var childrenNew = clone.Children;

            if (IsColorComplete(childrenNew, indexReplaced))
            {
                return(childrenNew);
            }
            return(GenerateColors(childrenNew));
        }
예제 #4
0
파일: Identity.cs 프로젝트: rfellers/pwiz
        /// <summary>
        /// Traverses the <see cref="DocNode"/> tree, performing an action on the
        /// final node specified in the path.
        /// </summary>
        /// <typeparam name="TTag">Type of the tag object used at the final node to perform the action</typeparam>
        /// <param name="parent">The parent node to use in the next recursive call</param>
        /// <param name="tag">The tag instance that will be used to perform the action</param>
        /// <returns>An alterer parent node</returns>
        /// <param name="recurse">Recursive descent function</param>
        /// <param name="act">Action function</param>
        /// <returns>An altered copy of the <see cref="parent"/> node</returns>
        public DocNodeParent Traverse <TTag>(DocNodeParent parent, TTag tag, Recurse <TTag> recurse, Act <TTag> act)
        {
            if (HasNext)
            {
                Identity nextId = Next();

                var nodeNext = parent.FindNode(nextId);
                if (nodeNext != null)
                {
                    DocNodeParent subParent = nodeNext as DocNodeParent;
                    if (subParent == null)
                    {
                        throw new InvalidOperationException(Resources.IdentityPathTraversal_Traverse_Invalid_attempt_to_perform_parent_operation_on_leaf_node);
                    }

                    // Make recursive call into the specified child
                    return(parent.ReplaceChild(recurse(subParent, this, tag)));
                }
                throw new IdentityNotFoundException(nextId);
            }

            return(act(tag));
        }
예제 #5
0
 protected override NodeRef <SrmDocument> ChangeDocNode(DocNodeParent parent, SrmDocument docNode)
 {
     return(this);
 }
예제 #6
0
 protected override bool Matches(DocNodeParent parent, SrmDocument docNode)
 {
     return(true);
 }
예제 #7
0
 protected override NodeRef <TransitionDocNode> ChangeDocNode(DocNodeParent parent, TransitionDocNode docNode)
 {
     return((TransitionRef)ChangeName(GetName((TransitionGroupDocNode)parent, docNode)));
 }
예제 #8
0
 protected override NodeRef <PeptideDocNode> ChangeDocNode(DocNodeParent parent, PeptideDocNode docNode)
 {
     return((MoleculeRef)ChangeName(GetName(docNode)));
 }
예제 #9
0
 protected override IList <DocNode> OnChangingChildren(DocNodeParent clone)
 {
     return(GenerateColors(clone.Children));
 }
예제 #10
0
 protected override IList<DocNode> OnChangingChildren(DocNodeParent clone)
 {
     return GenerateColors(clone.Children);
 }
예제 #11
0
        private bool ChangedResults(DocNodeParent nodePeptide)
        {
            if (nodePeptide.Children.Count != Children.Count)
                return true;

            int iChild = 0;
            foreach (TransitionGroupDocNode nodeGroup in Children)
            {
                // Results will differ if the identies of the children differ
                // at all.
                var nodeGroup2 = (TransitionGroupDocNode)nodePeptide.Children[iChild];
                if (!ReferenceEquals(nodeGroup.Id, nodeGroup2.Id))
                    return true;

                // or if the results for any child have changed
                if (!ReferenceEquals(nodeGroup.Results, nodeGroup2.Results))
                    return true;

                iChild++;
            }
            return false;
        }