Index: Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs
===================================================================
diff -u -r3716307f520488309250ca011e43fe660ecc0e6a -r0eddea1a45f0d9efb0a2a12e90eb99e814d1becb
--- Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision 3716307f520488309250ca011e43fe660ecc0e6a)
+++ Ringtoets/GrassCoverErosionOutwards/src/Ringtoets.GrassCoverErosionOutwards.Data/GrassCoverErosionOutwardsFailureMechanismExtensions.cs (.../GrassCoverErosionOutwardsFailureMechanismExtensions.cs) (revision 0eddea1a45f0d9efb0a2a12e90eb99e814d1becb)
@@ -72,37 +72,51 @@
throw new ArgumentNullException(nameof(assessmentSection));
}
- if (!Enum.IsDefined(typeof(FailureMechanismCategoryType), categoryType))
+ return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation,
+ GetHydraulicBoundaryLocationCalculations(failureMechanism,
+ assessmentSection,
+ categoryType));
+ }
+
+ ///
+ /// Gets the for a
+ /// based on .
+ /// The failure mechanism to get the from.
+ /// 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 output.
+ ///
+ ///
+ /// Thrown when or
+ /// is null.
+ /// Thrown when
+ /// is an invalid .
+ /// Thrown when
+ /// is a valid but unsupported .
+ public static HydraulicBoundaryLocationCalculation GetHydraulicBoundaryLocationCalculation(this GrassCoverErosionOutwardsFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection,
+ HydraulicBoundaryLocation hydraulicBoundaryLocation,
+ FailureMechanismCategoryType categoryType)
+ {
+ if (failureMechanism == null)
{
- throw new InvalidEnumArgumentException(nameof(categoryType),
- (int) categoryType,
- typeof(FailureMechanismCategoryType));
+ throw new ArgumentNullException(nameof(failureMechanism));
}
- IEnumerable calculations;
-
- switch (categoryType)
+ if (assessmentSection == null)
{
- case FailureMechanismCategoryType.MechanismSpecificFactorizedSignalingNorm:
- calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm;
- break;
- case FailureMechanismCategoryType.MechanismSpecificSignalingNorm:
- calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm;
- break;
- case FailureMechanismCategoryType.MechanismSpecificLowerLimitNorm:
- calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm;
- break;
- case FailureMechanismCategoryType.LowerLimitNorm:
- calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm;
- break;
- case FailureMechanismCategoryType.FactorizedLowerLimitNorm:
- calculations = assessmentSection.WaterLevelCalculationsForFactorizedLowerLimitNorm;
- break;
- default:
- throw new NotSupportedException();
+ throw new ArgumentNullException(nameof(assessmentSection));
}
- return GetAssessmentLevelFromCalculations(hydraulicBoundaryLocation, calculations);
+ return GetHydraulicBoundaryLocationCalculationFromCalculations(hydraulicBoundaryLocation,
+ GetHydraulicBoundaryLocationCalculations(failureMechanism,
+ assessmentSection,
+ categoryType));
}
///
@@ -133,11 +147,65 @@
failureMechanism.GeneralInput.N);
}
+ ///
+ /// Gets the collection of that belongs to
+ /// the given .
+ ///
+ /// The failure mechanism to get the calculations from.
+ /// 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(GrassCoverErosionOutwardsFailureMechanism failureMechanism,
+ IAssessmentSection assessmentSection,
+ FailureMechanismCategoryType categoryType)
+ {
+ if (!Enum.IsDefined(typeof(FailureMechanismCategoryType), categoryType))
+ {
+ throw new InvalidEnumArgumentException(nameof(categoryType),
+ (int) categoryType,
+ typeof(FailureMechanismCategoryType));
+ }
+
+ IEnumerable calculations;
+
+ switch (categoryType)
+ {
+ case FailureMechanismCategoryType.MechanismSpecificFactorizedSignalingNorm:
+ calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificFactorizedSignalingNorm;
+ break;
+ case FailureMechanismCategoryType.MechanismSpecificSignalingNorm:
+ calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificSignalingNorm;
+ break;
+ case FailureMechanismCategoryType.MechanismSpecificLowerLimitNorm:
+ calculations = failureMechanism.WaterLevelCalculationsForMechanismSpecificLowerLimitNorm;
+ break;
+ case FailureMechanismCategoryType.LowerLimitNorm:
+ calculations = assessmentSection.WaterLevelCalculationsForLowerLimitNorm;
+ break;
+ case FailureMechanismCategoryType.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