public override bool GetOptimized(out Path optimizedPath) { if (Steps.Count > 1 && (Steps[0].NodeTest != Step.NODE_TEST_ANY_NODE) && (from psmClass in Schema.PSMClasses where psmClass.IsStructuralRepresentative select psmClass.RepresentedClass).All(rep => rep.Schema == Schema) && Steps.Take(Steps.Count - 1).All(s => s.Axis.IsAmong(Axis.child, Axis.descendant, Axis.descendantOrSelf))) { Step lastStep = Steps.Last(); if (!string.IsNullOrEmpty(lastStep.NodeTest) && lastStep.NodeTest != Step.NODE_TEST_ANY_NODE && Schema.GetAllXMLElementNames()[lastStep.NodeTest] == 1 && lastStep.Axis.IsAmong(Axis.child, Axis.descendant, Axis.descendantOrSelf, Axis.attribute) ) { SimplePath simplePath = new SimplePath(Schema); simplePath.AddStep(new Step { Axis = Axis.descendantOrSelf, NodeTest = Step.NODE_TEST_ANY_NODE }); simplePath.AddStep(new Step { Axis = lastStep.Axis != Axis.attribute ? Axis.child : Axis.attribute, NodeTest = lastStep.NodeTest }); optimizedPath = simplePath; return(true); } } optimizedPath = this; return(false); }
private Path JoinInSteps(UnionPath optimizedComponents) { SimplePath joined = new SimplePath(Schema); for (int i = 0; i < ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps.Count; i++) { if (optimizedComponents.ComponentPaths.Select(path => ((SimplePath)path).Steps[i]).TransitiveTrue((s1, s2) => s1 == s2)) { // ale are equal, so take first one Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i]; joined.AddStep(imageStep.DeepCopy()); } else { Step imageStep = ((SimplePath)optimizedComponents.ComponentPaths.First()).Steps[i]; // they must be joined Step newStep = new Step() { Axis = Axis.descendant, NodeTest = imageStep.NodeTest }; joined.AddStep(newStep); } } return(joined); }
public override Path DeepCopy() { SimplePath copy = new SimplePath(Schema); base.FillCopy(copy); foreach (Step step in Steps) { copy.Steps.Add(step.DeepCopy()); } return(copy); }
private bool CanBeJoinedInSteps(Path path1, Path path2) { if (path1 is SimplePath && path2 is SimplePath) { SimplePath sp1 = (SimplePath)path1; SimplePath sp2 = (SimplePath)path2; if (sp1.Steps.Count == sp2.Steps.Count) { for (int i = 0; i < sp1.Steps.Count; i++) { Step step1 = sp1.Steps[i]; Step step2 = sp2.Steps[i]; bool stepOk = false; if (step1 == step2) { stepOk = true; } if (!stepOk && step1.Axis.IsAmong(Axis.child, Axis.descendant) && step2.Axis.IsAmong(Axis.child, Axis.descendant) && step1.NodeTest == step2.NodeTest) { stepOk = true; } if (!stepOk) { return(false); } } } return(true); } else { return(false); } }