// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Groups { /// /// /// Represents a ledgroup containing arbitrary . /// public class ListLedGroup : AbstractLedGroup { #region Properties & Fields /// /// Gets the list containing the of this . /// protected IList GroupLeds { get; } = new List(); #endregion #region Constructors /// /// /// Initializes a new instance of the class. /// /// Specifies whether this should be automatically attached or not. public ListLedGroup(bool autoAttach = true) : base(autoAttach) { } /// /// /// Initializes a new instance of the class. /// /// The initial of this . public ListLedGroup(params Led[] leds) : this(true, leds) { } /// /// /// Initializes a new instance of the class. /// /// The initial of this . public ListLedGroup(IEnumerable leds) : this(true, leds) { } /// /// /// Initializes a new instance of the class. /// /// Specifies whether this should be automatically attached or not. /// The initial of this . public ListLedGroup(bool autoAttach, IEnumerable leds) : base(autoAttach) { AddLeds(leds); } /// /// /// Initializes a new instance of the class. /// /// Specifies whether this should be automatically attached or not. /// The initial of this . public ListLedGroup(bool autoAttach, params Led[] leds) : base(autoAttach) { AddLeds(leds); } #endregion #region Methods /// /// Adds the given LED(s) to this . /// /// The LED(s) to add. public void AddLed(params Led[] leds) => AddLeds(leds); /// /// Adds the given to this . /// /// The to add. public void AddLeds(IEnumerable leds) { if (leds == null) return; foreach (Led led in leds) if ((led != null) && !ContainsLed(led)) GroupLeds.Add(led); } /// /// Removes the given LED(s) from this . /// /// The LED(s) to remove. public void RemoveLed(params Led[] leds) => RemoveLeds(leds); /// /// Removes the given from this . /// /// The to remove. public void RemoveLeds(IEnumerable leds) { if (leds == null) return; foreach (Led led in leds) if (led != null) GroupLeds.Remove(led); } /// /// Checks if a given LED is contained by this ledgroup. /// /// The LED which should be checked. /// true if the LED is contained by this ledgroup; otherwise, false. public bool ContainsLed(Led led) => (led != null) && GroupLeds.Contains(led); /// /// Merges the from the given ledgroup in this ledgroup. /// /// The ledgroup to merge. public void MergeLeds(ILedGroup groupToMerge) { foreach (Led led in groupToMerge.GetLeds()) if (!GroupLeds.Contains(led)) GroupLeds.Add(led); } /// /// /// Gets a list containing the from this group. /// /// The list containing the . public override IEnumerable GetLeds() => GroupLeds; #endregion } }