// 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.Collections; using System.Linq; using System.Windows.Forms; namespace Ringtoets.Common.Forms.PresentationObjects { /// /// Object that allows for grouping child nodes of instances. /// public class CategoryTreeFolder { /// /// Initializes a new instance of the class. /// /// The name of the category folder. /// The contents of the folder. /// Optional: The category descriptor of the folder. Default: . public CategoryTreeFolder(string name, IList contents, TreeFolderCategory category = TreeFolderCategory.General) { Name = name; Contents = contents.OfType().ToArray(); Category = category; } /// /// Gets the name of the folder. /// public string Name { get; } /// /// Gets the contents of the folder. /// public IList Contents { get; } /// /// Gets the category of the folder. /// public TreeFolderCategory Category { get; private set; } 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((CategoryTreeFolder) obj); } public override int GetHashCode() { return Contents.Cast().Aggregate(Name?.GetHashCode() ?? 0, (current, content) => current ^ content.GetHashCode()); } private bool Equals(CategoryTreeFolder other) { if (Name != other.Name) { return false; } if (Contents.Count != other.Contents.Count) { return false; } for (var i = 0; i < Contents.Count; i++) { if (!Contents[i].Equals(other.Contents[i])) { return false; } } return true; } } }