// 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.Base.Properties; using log4net; using Ringtoets.Common.IO.Exceptions; namespace Ringtoets.Common.IO.SoilProfile { /// /// Class which provides helper methods for the . /// public static class StochasticSoilProfileHelper { private static readonly ILog log = LogManager.GetLogger(typeof(StochasticSoilProfileHelper)); /// /// Validates a collection of to determine which items /// should be transformed. /// /// The collection of /// to validate. /// The name of the soil model. /// A collection of validated to transform. /// Thrown when any parameter is null. /// Thrown when a /// is invalid. public static IEnumerable GetValidatedStochasticSoilProfilesToTransform(IEnumerable stochasticSoilProfiles, string soilModelName) { if (stochasticSoilProfiles == null) { throw new ArgumentNullException(nameof(stochasticSoilProfiles)); } if (soilModelName == null) { throw new ArgumentNullException(nameof(soilModelName)); } List profilesToTransform = stochasticSoilProfiles.ToList(); StochasticSoilProfile[] allStochasticSoilProfiles = profilesToTransform.ToArray(); try { for (var i = 1; i < allStochasticSoilProfiles.Length; i++) { StochasticSoilProfile previousProfile = allStochasticSoilProfiles[i - 1]; StochasticSoilProfile currentProfile = allStochasticSoilProfiles[i]; if (ReferenceEquals(currentProfile.SoilProfile, previousProfile.SoilProfile)) { log.Warn(string.Format(Resources.StochasticSoilProfileHelper_GetValidatedStochasticProfilesToTransform_StochasticSoilProfile_0_has_multiple_occurences_in_SoilModel_1_Probability_Summed, previousProfile.SoilProfile.Name, soilModelName)); previousProfile.AddProbability(currentProfile.Probability); profilesToTransform.Remove(currentProfile); } } } catch (ArgumentOutOfRangeException e) { throw new ImportedDataTransformException(e.Message, e); } return profilesToTransform; } } }