Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs =================================================================== diff -u -r1e14ee40087ad0c42f889f6ee86c13bf6d7d192b -r0eddea1a45f0d9efb0a2a12e90eb99e814d1becb --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 1e14ee40087ad0c42f889f6ee86c13bf6d7d192b) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/AssessmentSectionExtensions.cs (.../AssessmentSectionExtensions.cs) (revision 0eddea1a45f0d9efb0a2a12e90eb99e814d1becb) @@ -116,34 +116,40 @@ throw new ArgumentNullException(nameof(assessmentSection)); } - if (!Enum.IsDefined(typeof(AssessmentSectionCategoryType), categoryType)) - { - throw new InvalidEnumArgumentException(nameof(categoryType), - (int) categoryType, - typeof(AssessmentSectionCategoryType)); - } + return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation, + GetHydraulicBoundaryLocationCalculations(assessmentSection, categoryType)); + } - IEnumerable calculations; - - switch (categoryType) + /// + /// Gets the for a + /// based on . + /// The assessment section to get the from. + /// The hydraulic boundary location to get the for. + /// The category type to use while obtaining the . + /// The , or null when: + /// + /// is null; + /// is not part of ; + /// contains no corresponding calculation. + /// + /// + /// Thrown when + /// is null. + /// Thrown when + /// is an invalid . + /// Thrown when + /// is a valid but unsupported . + public static HydraulicBoundaryLocationCalculation GetHydraulicBoundaryLocationCalculation(this IAssessmentSection assessmentSection, + HydraulicBoundaryLocation hydraulicBoundaryLocation, + AssessmentSectionCategoryType categoryType) + { + if (assessmentSection == null) { - case AssessmentSectionCategoryType.FactorizedSignalingNorm: - calculations = assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm; - break; - case AssessmentSectionCategoryType.SignalingNorm: - calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; - break; - case AssessmentSectionCategoryType.LowerLimitNorm: - calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; - break; - case AssessmentSectionCategoryType.FactorizedLowerLimitNorm: - calculations = assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm; - break; - default: - throw new NotSupportedException(); + throw new ArgumentNullException(nameof(assessmentSection)); } - return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation, calculations); + return GetHydraulicBoundaryLocationCalculationFromCalculations(hydraulicBoundaryLocation, + GetHydraulicBoundaryLocationCalculations(assessmentSection, categoryType)); } /// @@ -196,11 +202,60 @@ } } + /// + /// Gets the collection of that belongs to + /// the given . + /// + /// The assessment section to get the calculations from. + /// The used to determine which calculations to return. + /// A collection of . + /// Thrown when + /// is an invalid . + /// Thrown when + /// is a valid but unsupported . + private static IEnumerable GetHydraulicBoundaryLocationCalculations(IAssessmentSection assessmentSection, + AssessmentSectionCategoryType categoryType) + { + if (!Enum.IsDefined(typeof(AssessmentSectionCategoryType), categoryType)) + { + throw new InvalidEnumArgumentException(nameof(categoryType), + (int) categoryType, + typeof(AssessmentSectionCategoryType)); + } + + IEnumerable calculations; + + switch (categoryType) + { + case AssessmentSectionCategoryType.FactorizedSignalingNorm: + calculations = assessmentSection.WaterLevelCalculationsForFactorizedSignalingNorm; + break; + case AssessmentSectionCategoryType.SignalingNorm: + calculations = assessmentSection.WaterLevelCalculationsForSignalingNorm; + break; + case AssessmentSectionCategoryType.LowerLimitNorm: + calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm; + break; + case AssessmentSectionCategoryType.FactorizedLowerLimitNorm: + calculations = assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm; + break; + default: + throw new NotSupportedException(); + } + + return calculations; + } + + private static HydraulicBoundaryLocationCalculation GetHydraulicBoundaryLocationCalculationFromCalculations(HydraulicBoundaryLocation hydraulicBoundaryLocation, + IEnumerable calculations) + { + return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation)); + } + private static RoundedDouble GetAssessmentLevelFromCalculations(HydraulicBoundaryLocation hydraulicBoundaryLocation, IEnumerable calculations) { - return calculations.FirstOrDefault(c => ReferenceEquals(c.HydraulicBoundaryLocation, hydraulicBoundaryLocation))?.Output?.Result - ?? RoundedDouble.NaN; + return GetHydraulicBoundaryLocationCalculationFromCalculations(hydraulicBoundaryLocation, calculations)?.Output?.Result ?? RoundedDouble.NaN; } } } \ No newline at end of file