// 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 Core.Common.Utils.Extensions; using Ringtoets.Common.Data.Properties; namespace Ringtoets.Common.Data.IllustrationPoints { /// /// The general illustration point result. /// /// The type of /// that the general result holds. public class GeneralResult : ICloneable where T : TopLevelIllustrationPointBase { /// /// Creates a new instance of /// /// The governing wind direction. /// The general alpha values. /// A collection of illustration points /// for every combination of wind directions and closing situations. /// Thrown when any of the input /// parameters is null. public GeneralResult(WindDirection governingWindDirection, IEnumerable stochasts, IEnumerable topLevelIllustrationPoints) { if (governingWindDirection == null) { throw new ArgumentNullException(nameof(governingWindDirection)); } if (stochasts == null) { throw new ArgumentNullException(nameof(stochasts)); } if (topLevelIllustrationPoints == null) { throw new ArgumentNullException(nameof(topLevelIllustrationPoints)); } ValidateStochasts(stochasts); ValidateTopLevelIllustrationPoints(topLevelIllustrationPoints); GoverningWindDirection = governingWindDirection; Stochasts = stochasts; TopLevelIllustrationPoints = topLevelIllustrationPoints; } /// /// Gets the governing wind direction. /// public WindDirection GoverningWindDirection { get; private set; } /// /// Gets the general alpha values. /// public IEnumerable Stochasts { get; private set; } /// /// Gets the collection of illustration points for every combination of a wind direction and a closing situation. /// public IEnumerable TopLevelIllustrationPoints { get; private set; } public object Clone() { var clone = (GeneralResult) MemberwiseClone(); clone.GoverningWindDirection = (WindDirection) GoverningWindDirection.Clone(); clone.Stochasts = Stochasts.Select(s => (Stochast) s.Clone()).ToArray(); clone.TopLevelIllustrationPoints = TopLevelIllustrationPoints.Select(s => (T) s.Clone()).ToArray(); return clone; } private static void ValidateTopLevelIllustrationPoints(IEnumerable topLevelIllustrationPoints) { bool hasNonDistinctIllustrationPointsPerWindDirection = topLevelIllustrationPoints.AnyNonDistinct(t => $"{t.ClosingSituation} {t.WindDirection.Angle}"); if (hasNonDistinctIllustrationPointsPerWindDirection) { throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_closing_situations_or_wind_direction)); } } private static void ValidateStochasts(IEnumerable stochasts) { bool hasNonDistinctStochasts = stochasts.AnyNonDistinct(s => s.Name); if (hasNonDistinctStochasts) { throw new ArgumentException(string.Format(Resources.GeneralResult_Imported_non_unique_stochasts)); } } } }