Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/Assembly/CombinedAssemblyFailureMechanismSectionFactory.cs =================================================================== diff -u -r548fd3a9c2e2609a1f8103eb424504bd1a87f2a9 -rb6e702538afcbc012fccd0df2e5759abc33902ce --- Ringtoets/Integration/src/Ringtoets.Integration.Data/Assembly/CombinedAssemblyFailureMechanismSectionFactory.cs (.../CombinedAssemblyFailureMechanismSectionFactory.cs) (revision 548fd3a9c2e2609a1f8103eb424504bd1a87f2a9) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/Assembly/CombinedAssemblyFailureMechanismSectionFactory.cs (.../CombinedAssemblyFailureMechanismSectionFactory.cs) (revision b6e702538afcbc012fccd0df2e5759abc33902ce) @@ -103,55 +103,55 @@ if (failureMechanisms.Contains(microstabilityFailureMechanism)) { inputs.Add(CreateCombinedSections(microstabilityFailureMechanism.SectionResults, - assessmentSection, MicrostabilityAssemblyFunc) + MicrostabilityAssemblyFunc) .ToArray()); } StabilityStoneCoverFailureMechanism stabilityStoneCoverFailureMechanism = assessmentSection.StabilityStoneCover; if (failureMechanisms.Contains(stabilityStoneCoverFailureMechanism)) { inputs.Add(CreateCombinedSections(stabilityStoneCoverFailureMechanism.SectionResults, - assessmentSection, StabilityStoneCoverAssemblyFunc) + StabilityStoneCoverAssemblyFunc) .ToArray()); } WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism = assessmentSection.WaveImpactAsphaltCover; if (failureMechanisms.Contains(waveImpactAsphaltCoverFailureMechanism)) { inputs.Add(CreateCombinedSections(waveImpactAsphaltCoverFailureMechanism.SectionResults, - assessmentSection, WaveImpactAsphaltCoverAssemblyFunc) + WaveImpactAsphaltCoverAssemblyFunc) .ToArray()); } WaterPressureAsphaltCoverFailureMechanism waterPressureAsphaltCoverFailureMechanism = assessmentSection.WaterPressureAsphaltCover; if (failureMechanisms.Contains(waterPressureAsphaltCoverFailureMechanism)) { inputs.Add(CreateCombinedSections(waterPressureAsphaltCoverFailureMechanism.SectionResults, - assessmentSection, WaterPressureAsphaltCoverAssemblyFunc) + WaterPressureAsphaltCoverAssemblyFunc) .ToArray()); } GrassCoverErosionOutwardsFailureMechanism grassCoverErosionOutwardsFailureMechanism = assessmentSection.GrassCoverErosionOutwards; if (failureMechanisms.Contains(grassCoverErosionOutwardsFailureMechanism)) { inputs.Add(CreateCombinedSections(grassCoverErosionOutwardsFailureMechanism.SectionResults, - assessmentSection, GrassCoverErosionOutwardsAssemblyFunc) + GrassCoverErosionOutwardsAssemblyFunc) .ToArray()); } GrassCoverSlipOffOutwardsFailureMechanism grassCoverSlipOffOutwardsFailureMechanism = assessmentSection.GrassCoverSlipOffOutwards; if (failureMechanisms.Contains(grassCoverSlipOffOutwardsFailureMechanism)) { inputs.Add(CreateCombinedSections(grassCoverSlipOffOutwardsFailureMechanism.SectionResults, - assessmentSection, GrassCoverSlipOffOutwardsAssemblyFunc) + GrassCoverSlipOffOutwardsAssemblyFunc) .ToArray()); } GrassCoverSlipOffInwardsFailureMechanism grassCoverSlipOffInwardsFailureMechanism = assessmentSection.GrassCoverSlipOffInwards; if (failureMechanisms.Contains(grassCoverSlipOffOutwardsFailureMechanism)) { inputs.Add(CreateCombinedSections(grassCoverSlipOffInwardsFailureMechanism.SectionResults, - assessmentSection, GrassCoverSlipOffInwardsAssemblyFunc) + GrassCoverSlipOffInwardsAssemblyFunc) .ToArray()); } @@ -175,7 +175,7 @@ if (failureMechanisms.Contains(pipingStructureFailureMechanism)) { inputs.Add(CreateCombinedSections(pipingStructureFailureMechanism.SectionResults, - assessmentSection, PipingStructureAssemblyFunc) + PipingStructureAssemblyFunc) .ToArray()); } @@ -191,23 +191,23 @@ if (failureMechanisms.Contains(strengthStabilityLengthwiseConstructionFailureMechanism)) { inputs.Add(CreateCombinedSections(strengthStabilityLengthwiseConstructionFailureMechanism.SectionResults, - assessmentSection, StrengthStabilityLengthwiseConstructionAssemblyFunc) + StrengthStabilityLengthwiseConstructionAssemblyFunc) .ToArray()); } DuneErosionFailureMechanism duneErosionFailureMechanism = assessmentSection.DuneErosion; if (failureMechanisms.Contains(duneErosionFailureMechanism)) { inputs.Add(CreateCombinedSections(duneErosionFailureMechanism.SectionResults, - assessmentSection, DuneErosionAssemblyFunc) + DuneErosionAssemblyFunc) .ToArray()); } TechnicalInnovationFailureMechanism technicalInnovationFailureMechanism = assessmentSection.TechnicalInnovation; if (failureMechanisms.Contains(technicalInnovationFailureMechanism)) { inputs.Add(CreateCombinedSections(technicalInnovationFailureMechanism.SectionResults, - assessmentSection, TechnicalInnovationAssemblyFunc) + TechnicalInnovationAssemblyFunc) .ToArray()); } @@ -222,20 +222,32 @@ { double totalSectionsLength = 0; - var combinedSections = new List(); - foreach (TFailureMechanismSectionResult sectionResult in sectionResults) - { - double endPoint = sectionResult.Section.Length + totalSectionsLength; - combinedSections.Add(new CombinedAssemblyFailureMechanismSection(totalSectionsLength, - endPoint, - getAssemblyFunc(sectionResult, assessmentSection))); + return sectionResults.Select(sectionResult => CreateSection(sectionResult, getAssemblyFunc(sectionResult, assessmentSection), ref totalSectionsLength)) + .ToArray(); + } - totalSectionsLength = endPoint; - } + private static IEnumerable CreateCombinedSections( + IEnumerable sectionResults, + Func getAssemblyFunc) + where TFailureMechanismSectionResult : FailureMechanismSectionResult + { + double totalSectionsLength = 0; - return combinedSections.ToArray(); + return sectionResults.Select(sectionResult => CreateSection(sectionResult, getAssemblyFunc(sectionResult), ref totalSectionsLength)) + .ToArray(); } + private static CombinedAssemblyFailureMechanismSection CreateSection( + TFailureMechanismSectionResult sectionResult, FailureMechanismSectionAssemblyCategoryGroup assemblyCategoryGroup, + ref double sectionStart) + where TFailureMechanismSectionResult : FailureMechanismSectionResult + { + double sectionEnd = sectionResult.Section.Length + sectionStart; + var section = new CombinedAssemblyFailureMechanismSection(sectionStart, sectionEnd, assemblyCategoryGroup); + sectionStart = sectionEnd; + return section; + } + #region Assembly Funcs private static Func PipingAssemblyFunc @@ -274,59 +286,59 @@ } } - private static Func MicrostabilityAssemblyFunc + private static Func MicrostabilityAssemblyFunc { get { - return (sectionResult, assessmentSection) => MicrostabilityFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return MicrostabilityFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func StabilityStoneCoverAssemblyFunc + private static Func StabilityStoneCoverAssemblyFunc { get { - return (sectionResult, assessmentSection) => StabilityStoneCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return StabilityStoneCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func WaveImpactAsphaltCoverAssemblyFunc + private static Func WaveImpactAsphaltCoverAssemblyFunc { get { - return (sectionResult, assessmentSection) => WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return WaveImpactAsphaltCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func WaterPressureAsphaltCoverAssemblyFunc + private static Func WaterPressureAsphaltCoverAssemblyFunc { get { - return (sectionResult, assessmentSection) => WaterPressureAsphaltCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return WaterPressureAsphaltCoverFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func GrassCoverErosionOutwardsAssemblyFunc + private static Func GrassCoverErosionOutwardsAssemblyFunc { get { - return (sectionResult, assessmentSection) => GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return GrassCoverErosionOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func GrassCoverSlipOffOutwardsAssemblyFunc + private static Func GrassCoverSlipOffOutwardsAssemblyFunc { get { - return (sectionResult, assessmentSection) => GrassCoverSlipOffOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return GrassCoverSlipOffOutwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func GrassCoverSlipOffInwardsAssemblyFunc + private static Func GrassCoverSlipOffInwardsAssemblyFunc { get { - return (sectionResult, assessmentSection) => GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return GrassCoverSlipOffInwardsFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } @@ -348,11 +360,11 @@ } } - private static Func PipingStructureAssemblyFunc + private static Func PipingStructureAssemblyFunc { get { - return (sectionResult, assessmentSection) => PipingStructureFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return PipingStructureFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } @@ -365,27 +377,27 @@ } } - private static Func StrengthStabilityLengthwiseConstructionAssemblyFunc + private static Func StrengthStabilityLengthwiseConstructionAssemblyFunc { get { - return (sectionResult, assessmentSection) => StrengthStabilityLengthwiseConstructionFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return StrengthStabilityLengthwiseConstructionFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func DuneErosionAssemblyFunc + private static Func DuneErosionAssemblyFunc { get { - return (sectionResult, assessmentSection) => DuneErosionFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return DuneErosionFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } } - private static Func TechnicalInnovationAssemblyFunc + private static Func TechnicalInnovationAssemblyFunc { get { - return (sectionResult, assessmentSection) => TechnicalInnovationFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup(sectionResult); + return TechnicalInnovationFailureMechanismAssemblyFactory.GetSectionAssemblyCategoryGroup; } }