diff --git a/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs b/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs index c042c2fb..bec6f3e5 100644 --- a/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs +++ b/RDFSharp/Query/Mirella/Algebra/RDFPropertyPath.cs @@ -31,6 +31,11 @@ public class RDFPropertyPath : RDFPatternGroupMember /// public RDFPatternMember Start { get; internal set; } + /// + /// End of the path + /// + public RDFPatternMember End { get; internal set; } + /// /// Steps of the path /// @@ -40,11 +45,6 @@ public class RDFPropertyPath : RDFPatternGroupMember /// Depth of the path /// internal int Depth { get; set; } - - /// - /// End of the path - /// - public RDFPatternMember End { get; internal set; } #endregion #region Ctors @@ -53,6 +53,7 @@ public class RDFPropertyPath : RDFPatternGroupMember /// public RDFPropertyPath(RDFPatternMember start, RDFPatternMember end) { + #region Guards if (start == null) throw new RDFQueryException("Cannot create RDFPropertyPath because given \"start\" parameter is null."); if (!(start is RDFResource || start is RDFVariable)) @@ -61,6 +62,7 @@ public RDFPropertyPath(RDFPatternMember start, RDFPatternMember end) throw new RDFQueryException("Cannot create RDFPropertyPath because given \"end\" parameter is null."); if (!(end is RDFResource || end is RDFVariable)) throw new RDFQueryException("Cannot create RDFPropertyPath because given \"end\" parameter is neither a resource or a variable."); + #endregion Start = start; End = end; @@ -85,40 +87,31 @@ internal string ToString(List prefixes) /// public RDFPropertyPath AddAlternativeSteps(List alternativeSteps) { + #region Guards if (alternativeSteps == null || alternativeSteps.Count == 0) throw new RDFQueryException("Cannot add alternative steps because the given list is null or it does not contain elements."); if (alternativeSteps.Any(step => step == null)) throw new RDFQueryException("Cannot add alternative steps because the given list contains a null element."); + #endregion - #region Depth Guard + //Update depth status of the property path if (Steps.Count == 0 - || alternativeSteps.Count == 1 - || Steps.LastOrDefault()?.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence) - { + || alternativeSteps.Count == 1 + || Steps.LastOrDefault()?.StepFlavor == RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence) Depth++; - } - #endregion - - #region Steps Update + + //Collect the given steps into the property path if (alternativeSteps.Count == 1) - { Steps.Add(alternativeSteps[0].SetOrdinal(Steps.Count) - .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence)); - } + .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence)); else - { - alternativeSteps.ForEach(alternativeStep => - { + foreach (RDFPropertyPathStep alternativeStep in alternativeSteps) Steps.Add(alternativeStep.SetOrdinal(Steps.Count) - .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative)); - }); - } - #endregion - - #region Evaluability Guard + .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Alternative)); + + //Update evaluability status of the property path if (Start is RDFVariable || End is RDFVariable || Depth > 1) IsEvaluable = true; - #endregion return this; } @@ -128,19 +121,21 @@ public RDFPropertyPath AddAlternativeSteps(List alternative /// public RDFPropertyPath AddSequenceStep(RDFPropertyPathStep sequenceStep) { + #region Guards if (sequenceStep == null) throw new RDFQueryException("Cannot add sequence step because it is null."); + #endregion - #region Steps Update + //Update depth status of the property path Depth++; + + //Collect the given step into the property path Steps.Add(sequenceStep.SetOrdinal(Steps.Count) - .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence)); - #endregion + .SetFlavor(RDFQueryEnums.RDFPropertyPathStepFlavors.Sequence)); - #region Evaluability Guard + //Update evaluability status of the property path if (Start is RDFVariable || End is RDFVariable || Depth > 1) IsEvaluable = true; - #endregion return this; }