Index: Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs =================================================================== diff -u -rf4efcc2bb58d597f4a19884d98d0ab79bab04b1c -r24145cb7feea063e2986e8f4b2270bb2a478b3fd --- Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision f4efcc2bb58d597f4a19884d98d0ab79bab04b1c) +++ Ringtoets/Piping/src/Ringtoets.Piping.Data/StochasticSoilProfile.cs (.../StochasticSoilProfile.cs) (revision 24145cb7feea063e2986e8f4b2270bb2a478b3fd) @@ -20,7 +20,6 @@ // All rights reserved. using System; -using Ringtoets.Piping.Data.Properties; using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.Data @@ -30,8 +29,6 @@ /// public class StochasticSoilProfile { - private double probability; - /// /// Creates a new instance of . /// @@ -48,12 +45,12 @@ /// /// Gets the type of the stochastic soil profile. /// - public SoilProfileType SoilProfileType { get; private set; } + public SoilProfileType SoilProfileType { get; } /// /// Gets the database identifier of the stochastic soil profile. /// - public long SoilProfileId { get; private set; } + public long SoilProfileId { get; } /// /// Gets the . @@ -63,23 +60,7 @@ /// /// 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 - { - if (!double.IsNaN(value) && (value < 0 || value > 1)) - { - throw new ArgumentOutOfRangeException(nameof(value), Resources.StochasticSoilProfile_Probability_Should_be_in_range_0_1); - } - probability = value; - } - } + public double Probability { get; private set; } /// /// Updates the probability of the @@ -100,19 +81,53 @@ /// obtain the property values from. /// Thrown when /// is null. - public void Update(StochasticSoilProfile fromProfile) + /// true if the profile has been updated; false otherwise. + public bool Update(StochasticSoilProfile fromProfile) { if (fromProfile == null) { throw new ArgumentNullException(nameof(fromProfile)); } - SoilProfile = fromProfile.SoilProfile; - Probability = fromProfile.Probability; + if (!Equals(fromProfile)) + { + SoilProfile = fromProfile.SoilProfile; + Probability = fromProfile.Probability; + return true; + } + return false; } public override string ToString() { - return SoilProfile == null ? string.Empty : SoilProfile.ToString(); + return SoilProfile?.ToString() ?? string.Empty; } + + protected bool Equals(StochasticSoilProfile other) + { + return Probability.Equals(other.Probability) + && SoilProfileType == other.SoilProfileType + && SoilProfileId == other.SoilProfileId + && Equals(SoilProfile, other.SoilProfile); + } + + 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((StochasticSoilProfile) obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = Probability.GetHashCode(); + hashCode = (hashCode * 397) ^ (int) SoilProfileType; + hashCode = (hashCode * 397) ^ SoilProfileId.GetHashCode(); + hashCode = (hashCode * 397) ^ (SoilProfile?.GetHashCode() ?? 0); + return hashCode; + } + } } } \ No newline at end of file