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); }
/// <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)); }
protected override IList <DocNode> OnChangingChildren(DocNodeParent clone, int indexReplaced) { var childrenNew = clone.Children; if (IsColorComplete(childrenNew, indexReplaced)) { return(childrenNew); } return(GenerateColors(childrenNew)); }
/// <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)); }
protected override NodeRef <SrmDocument> ChangeDocNode(DocNodeParent parent, SrmDocument docNode) { return(this); }
protected override bool Matches(DocNodeParent parent, SrmDocument docNode) { return(true); }
protected override NodeRef <TransitionDocNode> ChangeDocNode(DocNodeParent parent, TransitionDocNode docNode) { return((TransitionRef)ChangeName(GetName((TransitionGroupDocNode)parent, docNode))); }
protected override NodeRef <PeptideDocNode> ChangeDocNode(DocNodeParent parent, PeptideDocNode docNode) { return((MoleculeRef)ChangeName(GetName(docNode))); }
protected override IList <DocNode> OnChangingChildren(DocNodeParent clone) { return(GenerateColors(clone.Children)); }
protected override IList<DocNode> OnChangingChildren(DocNodeParent clone) { return GenerateColors(clone.Children); }
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; }