// 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 System.Collections.Generic; using System.Linq; using Ringtoets.MacroStabilityInwards.Primitives; using Ringtoets.MacroStabilityInwards.Primitives.Properties; namespace Ringtoets.MacroStabilityInwards.Data.SoilProfile { /// /// This class represents a soil profile, which was imported for use in a macro stability inwards calculation. /// public class MacroStabilityInwardsSoilProfile2D : IMacroStabilityInwardsSoilProfile { private MacroStabilityInwardsSoilLayer2D[] layers; private string name; /// /// Creates a new instance of , with the given /// and . /// A new collection is created for and used in the . /// /// The name of the profile. /// The collection of layers that should be part of the profile. /// The preconsolidation stresses that are part of the profile. /// Thrown when any parameter is null. /// Thrown when contains no layers. public MacroStabilityInwardsSoilProfile2D(string name, IEnumerable layers, IEnumerable preconsolidationStresses) { if (preconsolidationStresses == null) { throw new ArgumentNullException(nameof(preconsolidationStresses)); } Name = name; ValidateLayersCollection(layers); Layers = layers; PreconsolidationStresses = preconsolidationStresses.ToArray(); } /// /// Gets an of /// for the . /// public IEnumerable PreconsolidationStresses { get; } public IEnumerable Layers { get { return layers; } private set { layers = value.ToArray(); } } /// /// Gets the name of . /// /// Thrown when the value is null. public string Name { get { return name; } private set { if (value == null) { throw new ArgumentNullException(nameof(value)); } name = value; } } public override string ToString() { return Name; } 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((MacroStabilityInwardsSoilProfile2D) obj); } public override int GetHashCode() { unchecked { int hashCode = Name.GetHashCode(); return PreconsolidationStresses.Aggregate(hashCode, (currentHashCode, stress) => (currentHashCode * 397) ^ stress.GetHashCode()); } } private bool Equals(MacroStabilityInwardsSoilProfile2D other) { return layers.SequenceEqual(other.layers) && PreconsolidationStresses.SequenceEqual(other.PreconsolidationStresses) && string.Equals(Name, other.Name); } /// /// Validates the given . A valid has layers. /// /// The collection of to validate. /// Thrown when is null. /// Thrown when contains no layers. private void ValidateLayersCollection(IEnumerable collection) { if (collection == null) { throw new ArgumentNullException(nameof(collection), string.Format(Resources.Error_Cannot_Construct_MacroStabilityInwardsSoilProfile_Without_Layers)); } if (!collection.Any()) { throw new ArgumentException(Resources.Error_Cannot_Construct_MacroStabilityInwardsSoilProfile_Without_Layers); } } } }