// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
namespace RGB.NET.Core;
///
///
/// 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 the surface to attach this group to or null if the group should not be attached on creation.
public ListLedGroup(RGBSurface? surface)
: base(surface)
{ }
///
///
/// Initializes a new instance of the class.
///
/// Specifies the surface to attach this group to or null if the group should not be attached on creation.
/// The initial of this .
public ListLedGroup(RGBSurface? surface, IEnumerable leds)
: base(surface)
{
AddLeds(leds);
}
///
///
/// Initializes a new instance of the class.
///
/// Specifies the surface to attach this group to or null if the group should not be attached on creation.
/// The initial of this .
public ListLedGroup(RGBSurface? surface, params Led[] leds)
: base(surface)
{
AddLeds(leds);
}
#endregion
#region Methods
///
/// Adds the specified LED(s) to this .
///
/// The LED(s) to add.
public void AddLed(params Led[] leds) => AddLeds(leds);
///
/// Adds the specified to this .
///
/// The to add.
public void AddLeds(IEnumerable leds)
{
lock (GroupLeds)
foreach (Led led in leds)
if (!ContainsLed(led))
GroupLeds.Add(led);
}
///
/// Removes the specified LED(s) from this .
///
/// The LED(s) to remove.
public void RemoveLed(params Led[] leds) => RemoveLeds(leds);
///
/// Removes the specified from this .
///
/// The to remove.
public void RemoveLeds(IEnumerable leds)
{
lock (GroupLeds)
foreach (Led led in leds)
GroupLeds.Remove(led);
}
///
/// Checks if a specified 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)
{
lock (GroupLeds)
return GroupLeds.Contains(led);
}
///
/// Merges the from the specified ledgroup in this ledgroup.
///
/// The ledgroup to merge.
public void MergeLeds(ILedGroup groupToMerge)
{
lock (GroupLeds)
foreach (Led led in groupToMerge)
if (!GroupLeds.Contains(led))
GroupLeds.Add(led);
}
///
///
/// Gets a list containing the from this group.
///
/// The list containing the .
protected override IEnumerable GetLeds()
{
lock (GroupLeds)
return new List(GroupLeds);
}
#endregion
}