Index: Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationStochastAssigner.cs
===================================================================
diff -u -r65c74eaad22b576971bae588c9793d76950b8cad -rf55334a0d7385c56ef1add20effeac5a6994a4a7
--- Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationStochastAssigner.cs (.../StructuresCalculationStochastAssigner.cs) (revision 65c74eaad22b576971bae588c9793d76950b8cad)
+++ Ringtoets/Common/src/Ringtoets.Common.IO/Configurations/StructuresCalculationStochastAssigner.cs (.../StructuresCalculationStochastAssigner.cs) (revision f55334a0d7385c56ef1add20effeac5a6994a4a7)
@@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using log4net;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.Probabilistics;
@@ -80,27 +81,9 @@
/// otherwise.
public bool Assign()
{
- if (!Validate())
- {
- return false;
- }
-
- foreach (StandardDeviationDefinition stochastDefinition in GetStandardDeviationStochasts())
- {
- if (!SetStandardDeviationStochast(stochastDefinition))
- {
- return false;
- }
- }
-
- foreach (VariationCoefficientDefinition stochastDefinition in GetVariationCoefficientStochasts())
- {
- if (!SetVariationCoefficientStochast(stochastDefinition))
- {
- return false;
- }
- }
- return true;
+ return Validate()
+ && GetStandardDeviationStochasts().All(SetStandardDeviationStochast)
+ && GetVariationCoefficientStochasts().All(SetVariationCoefficientStochast);
}
///
@@ -120,7 +103,7 @@
/// The standard deviation stochasts definitions for the calculation.
protected abstract IEnumerable GetStandardDeviationStochasts(bool structureDependent = false);
- /// bas
+ ///
/// Gets the definitions for all stochasts with variation coefficient that are defined for the calculation input.
///
/// Optional. If set to true, only definitions for structure dependent
@@ -134,29 +117,9 @@
/// true if all the stochasts are valid, false otherwise.
private bool Validate()
{
- if (!ValidateBaseStochasts())
- {
- return false;
- }
- if (!ValidateSpecificStochasts())
- {
- return false;
- }
-
- if (Configuration.StructureName != null)
- {
- return true;
- }
-
- foreach (Tuple stochastValidationDefinition in GetStochastsForParameterValidation())
- {
- if (!ValidateNoParametersDefined(stochastValidationDefinition.Item2, stochastValidationDefinition.Item1))
- {
- return false;
- }
- }
-
- return true;
+ return ValidateBaseStochasts()
+ && ValidateSpecificStochasts()
+ && (Configuration.StructureName != null || GetStochastsForParameterValidation().All(ValidateNoParametersDefined));
}
private bool SetVariationCoefficientStochast(VariationCoefficientDefinition definition)
@@ -183,8 +146,11 @@
Log);
}
- private bool ValidateNoParametersDefined(StochastConfiguration stochastConfiguration, string stochastName)
+ private bool ValidateNoParametersDefined(Tuple stochastValidationDefinition)
{
+ string stochastName = stochastValidationDefinition.Item1;
+ StochastConfiguration stochastConfiguration = stochastValidationDefinition.Item2;
+
string calculationName = Configuration.Name;
bool parameterDefined = stochastConfiguration != null && (stochastConfiguration.Mean.HasValue || stochastConfiguration.StandardDeviation.HasValue || stochastConfiguration.VariationCoefficient.HasValue);
@@ -232,22 +198,40 @@
///
public class StandardDeviationDefinition
{
- public string StochastName;
- public StochastConfiguration Configuration;
- public Func Getter;
- public Action Setter;
+ ///
+ /// Gets the name of the stochast.
+ ///
+ public string StochastName { get; }
- private StandardDeviationDefinition() {}
+ ///
+ /// Gets the configuration of the stochast. Can return null
+ /// if no configuration was defined.
+ ///
+ public StochastConfiguration Configuration { get; }
///
+ /// The method for obtaining the distribution matching the stochast
+ /// to be configured, from the input.
+ ///
+ public Func Getter { get; }
+
+ ///
+ /// The method for assigning the distribution matching the stochast
+ /// to be configured, to the input.
+ ///
+ public Action Setter { get; }
+
+ ///
/// Creates a new instance of .
///
/// The name of the stochast.
/// The configuration of the stochast, which can be null.
/// Operation of obtaining the stochast from an input.
- /// Operation of assigning the stuchast to an input.
+ /// Operation of assigning the stochast to an input.
/// The newly created definition.
- public static StandardDeviationDefinition Create(
+ /// Thrown when the ,
+ /// or is null.
+ public StandardDeviationDefinition(
string stochastName,
StochastConfiguration configuration,
Func getter,
@@ -266,13 +250,10 @@
throw new ArgumentNullException(nameof(setter));
}
- return new StandardDeviationDefinition
- {
- StochastName = stochastName,
- Configuration = configuration,
- Getter = getter,
- Setter = setter
- };
+ StochastName = stochastName;
+ Configuration = configuration;
+ Getter = getter;
+ Setter = setter;
}
}
@@ -281,47 +262,49 @@
///
public class VariationCoefficientDefinition
{
- public string StochastName;
- public StochastConfiguration Configuration;
- public Func Getter;
- public Action Setter;
+ ///
+ /// Gets the name of the stochast.
+ ///
+ public string StochastName { get; }
- private VariationCoefficientDefinition() {}
+ ///
+ /// Gets the configuration of the stochast. Can return null
+ /// if no configuration was defined.
+ ///
+ public StochastConfiguration Configuration { get; }
///
+ /// The method for obtaining the distribution matching the stochast
+ /// to be configured, from the input.
+ ///
+ public Func Getter { get; }
+
+ ///
+ /// The method for assigning the distribution matching the stochast
+ /// to be configured, to the input.
+ ///
+ public Action Setter { get; }
+
+ ///
/// Creates a new instance of .
///
/// The name of the stochast.
/// The configuration of the stochast, which can be null.
/// Operation of obtaining the stochast from an input.
- /// Operation of assigning the stuchast to an input.
+ /// Operation of assigning the stochast to an input.
/// The newly created definition.
- public static VariationCoefficientDefinition Create(
+ /// Thrown when the ,
+ /// or is null.
+ public VariationCoefficientDefinition(
string stochastName,
StochastConfiguration configuration,
Func getter,
Action setter)
{
- if (stochastName == null)
- {
- throw new ArgumentNullException(nameof(stochastName));
- }
- if (getter == null)
- {
- throw new ArgumentNullException(nameof(getter));
- }
- if (setter == null)
- {
- throw new ArgumentNullException(nameof(setter));
- }
-
- return new VariationCoefficientDefinition
- {
- StochastName = stochastName,
- Configuration = configuration,
- Getter = getter,
- Setter = setter
- };
+ StochastName = stochastName;
+ Configuration = configuration;
+ Getter = getter;
+ Setter = setter;
}
}
}