// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using Core.Common.Base; using Core.Common.Utils.Extensions; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.Contribution { /// /// This class represents the distribution of all failure mechanism contributions. /// public class FailureMechanismContribution : Observable { private readonly ICollection distribution = new List(); private readonly OtherFailureMechanism otherFailureMechanism = new OtherFailureMechanism(); private double norm; /// /// Creates a new instance of . Values are taken from the /// and one item is added with a value of /// which represents the contribution of any other failure mechanisms. /// /// The of /// on which to base the . /// The collective contribution for other failure mechanisms. /// The norm defined on the assessment section. /// Thrown when is null. /// Thrown when: /// /// any of the has a value for /// not in the interval [0, 100]. /// the value of is not in the interval [0, 100] /// /// /// Thrown when /// is not in the interval [0.0, 1.0] or is . public FailureMechanismContribution(IEnumerable failureMechanisms, double otherContribution, double norm) { Norm = norm; UpdateContributions(failureMechanisms, otherContribution); } /// /// Gets or sets the norm which has been defined on the assessment section. /// /// Thrown when the new value is not in /// the interval [0.0, 1.0] or is . public double Norm { get { return norm; } set { ProbabilityHelper.ValidateProbability(value, nameof(value)); norm = value; distribution.ForEachElementDo(d => d.Norm = norm); } } /// /// Gets the distribution of failure mechanism contributions. /// public IEnumerable Distribution { get { return distribution; } } /// /// Fully updates the contents of for a new set of failure /// mechanisms and the remainder contribution. /// /// The new failure mechanisms. /// The collective contribution for other failure mechanisms. /// Thrown when is null. /// Thrown when: /// /// any of the has a value for /// not in the interval [0, 100]. /// the value of is not in the interval [0, 100] /// /// public void UpdateContributions(IEnumerable newFailureMechanisms, double otherContribution) { if (newFailureMechanisms == null) { throw new ArgumentNullException(nameof(newFailureMechanisms), Resources.FailureMechanismContribution_UpdateContributions_Can_not_create_FailureMechanismContribution_without_FailureMechanism_collection); } distribution.Clear(); newFailureMechanisms.ForEachElementDo(AddContributionItem); AddOtherContributionItem(otherContribution); } /// /// Adds a based on . /// /// The to add a for. /// Thrown when is null. private void AddContributionItem(IFailureMechanism failureMechanism) { distribution.Add(new FailureMechanismContributionItem(failureMechanism, norm)); } /// /// Adds a representing all other failure mechanisms not in the failure mechanism /// list supported within Ringtoets. /// /// The contribution to set for other failure mechanisms. /// Thrown when is not in the interval [0, 100] private void AddOtherContributionItem(double otherContribution) { otherFailureMechanism.Contribution = otherContribution; var otherContributionItem = new FailureMechanismContributionItem(otherFailureMechanism, norm, true); distribution.Add(otherContributionItem); } } }