Index: Ringtoets/Common/src/Ringtoets.Common.Data/BaseFailureMechanism.cs =================================================================== diff -u -rbb0c146c092dadc5f82f0fad45ed92658d436d5c -r337f02d824bf5352ed8148dbda0ca6b2b61a20c1 --- Ringtoets/Common/src/Ringtoets.Common.Data/BaseFailureMechanism.cs (.../BaseFailureMechanism.cs) (revision bb0c146c092dadc5f82f0fad45ed92658d436d5c) +++ Ringtoets/Common/src/Ringtoets.Common.Data/BaseFailureMechanism.cs (.../BaseFailureMechanism.cs) (revision 337f02d824bf5352ed8148dbda0ca6b2b61a20c1) @@ -21,6 +21,8 @@ using System; using System.Collections.Generic; +using System.Linq; + using Core.Common.Base; using Ringtoets.Common.Data.Properties; @@ -33,8 +35,19 @@ public abstract class BaseFailureMechanism : Observable, IFailureMechanism { private double contribution; + private readonly List sections; /// + /// Initializes a new instance of the class. + /// + /// The name of the failure mechanism. + protected BaseFailureMechanism(string failureMechanismName) + { + Name = failureMechanismName; + sections = new List(); + } + + /// /// Gets the amount of contribution as a percentage (0-100) for the /// as part of the overall verdict. /// @@ -55,12 +68,65 @@ } } + public string Name { get; private set; } + + public abstract IEnumerable CalculationItems { get; } + + public IEnumerable Sections + { + get + { + return sections; + } + } + + public void AddSection(FailureMechanismSection section) + { + if (section == null) + { + throw new ArgumentNullException("section"); + } + + if (!sections.Any()) + { + sections.Add(section); + } + else + { + InsertSectionWhileMaintainingConnectivityOrder(section); + } + } + /// - /// Gets or sets the name of the . + /// Inserts the section to while maintaining connectivity + /// order (Neighboring have same start- and + /// endpoints). /// - public string Name { get; protected set; } + /// The new section. + /// When cannot + /// be connected to elements already defined in . + private void InsertSectionWhileMaintainingConnectivityOrder(FailureMechanismSection sectionToInsert) + { + if (sections[0].GetStart().Equals(sectionToInsert.GetLast())) + { + sections.Insert(0, sectionToInsert); + } + else if (sections[sections.Count - 1].GetLast().Equals(sectionToInsert.GetStart())) + { + sections.Add(sectionToInsert); + } + else + { + string message = string.Format(Resources.BaseFailureMechanism_AddSection_Section_0_must_connect_to_existing_sections, + sectionToInsert.Name); + throw new ArgumentException(message, "sectionToInsert"); + } + } - public abstract IEnumerable CalculationItems { get; } + public void ClearAllSections() + { + throw new NotImplementedException(); + } /// /// Gets or sets the unique identifier for the storage of the class.