// Copyright (C) Stichting Deltares 2017. 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 Core.Common.Base; using Ringtoets.Common.Data.Probability; using Ringtoets.MacroStabilityInwards.Data.Properties; namespace Ringtoets.MacroStabilityInwards.Data.SoilProfile { /// /// This class couples a /// to a probability of occurrence. /// public class MacroStabilityInwardsStochasticSoilProfile : Observable { private double probability; /// /// Creates a new instance of . /// /// Probability of the stochastic soil profile. /// The soil profile. /// Thrown when /// is null. /// Thrown when the /// is outside the range [0, 1]. public MacroStabilityInwardsStochasticSoilProfile(double probability, IMacroStabilityInwardsSoilProfile soilProfile) { if (soilProfile == null) { throw new ArgumentNullException(nameof(soilProfile)); } Probability = probability; SoilProfile = soilProfile; } /// /// Gets the . /// public IMacroStabilityInwardsSoilProfile SoilProfile { get; private set; } /// /// Gets the probability of the stochastic soil profile. /// /// Thrown when the is outside the range /// [0, 1]. public double Probability { get { return probability; } private set { ProbabilityHelper.ValidateProbability( value, nameof(value), Resources.StochasticSoilProfile_Probability_Should_be_in_range_0_); probability = value; } } /// /// Updates the with the properties /// from . /// /// The to /// obtain the property values from. /// Thrown when /// is null. /// true if the profile has been updated; false otherwise. public void Update(MacroStabilityInwardsStochasticSoilProfile fromProfile) { if (fromProfile == null) { throw new ArgumentNullException(nameof(fromProfile)); } SoilProfile = fromProfile.SoilProfile; Probability = fromProfile.Probability; } /// /// Updates the probability of the /// by adding . /// /// The amount to increase the /// with. /// Thrown when the /// is outside the range [0, 1]. public void AddProbability(double probabilityToAdd) { Probability += probabilityToAdd; } public override string ToString() { return SoilProfile?.ToString() ?? string.Empty; } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != GetType()) { return false; } return Equals((MacroStabilityInwardsStochasticSoilProfile) obj); } public override int GetHashCode() { unchecked { int hashCode = Probability.GetHashCode(); hashCode = (hashCode * 397) ^ (SoilProfile?.GetHashCode() ?? 0); return hashCode; } } private bool Equals(MacroStabilityInwardsStochasticSoilProfile other) { return Probability.Equals(other.Probability) && Equals(SoilProfile, other.SoilProfile); } } }