Files
HLib/InBox/LineFilterUxer.cs
2026-06-01 13:23:34 +09:00

43 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KssSmaPlaLib.InBox
{
public class LineFilterUxer : IFilterUxer<string>
{
private readonly HashSet<string> includedLines;
private readonly HashSet<string> excludedLines;
public LineFilterUxer(IEnumerable<string> included, IEnumerable<string> excluded)
{
includedLines = new HashSet<string>(included ?? Enumerable.Empty<string>());
excludedLines = new HashSet<string>(excluded ?? Enumerable.Empty<string>());
}
public IEnumerable<string> ApplyFilter(IEnumerable<string> lineNames)
{
if (includedLines.Any())
{
// Included優先 → lineNamesの中でincludedに含まれるものだけ返す
return lineNames.Where(name => includedLines.Contains(name));
}
// Excluded適用 → lineNamesの中でexcludedに含まれないものだけ返す
return lineNames.Where(name => !excludedLines.Contains(name));
}
public bool CanPass(string lineName)
{
return HasAnyPass(new[] { lineName });
}
public bool HasAnyPass(IEnumerable<string> candidates)
{
return ApplyFilter(candidates).Any();
}
}
}