for Push.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.InBox
|
||||
{
|
||||
// インターフェース定義
|
||||
public interface IFilterUxer<T>
|
||||
{
|
||||
// 単一:候補がフィルタを通過できるか?
|
||||
bool CanPass(string candidate);
|
||||
|
||||
// 複数:1件でも通過できるか?(ガード句向け)
|
||||
bool HasAnyPass(IEnumerable<string> candidates);
|
||||
|
||||
// 複数:通過したものだけを返す(既存流儀)
|
||||
IEnumerable<string> ApplyFilter(IEnumerable<string> candidates);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using KssSmaPlaLib.Commons;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KssSmaPlaLib.InBox
|
||||
{
|
||||
public class SheetFilterUxer : IFilterUxer<string>
|
||||
{
|
||||
private readonly HashSet<string> includedSheets;
|
||||
private readonly HashSet<string> excludedSheets;
|
||||
|
||||
public SheetFilterUxer(IEnumerable<string> included, IEnumerable<string> excluded)
|
||||
{
|
||||
includedSheets = new HashSet<string>(included ?? Enumerable.Empty<string>());
|
||||
excludedSheets = new HashSet<string>(excluded ?? Enumerable.Empty<string>());
|
||||
}
|
||||
|
||||
public IEnumerable<string> ApplyFilter(IEnumerable<string> sheetNames)
|
||||
{
|
||||
if (includedSheets.Any())
|
||||
{
|
||||
// Included優先 → lineNamesの中でincludedに含まれるものだけ返す
|
||||
//return sheetNames.Where(name => includedSheets.Contains(name));
|
||||
// ワイルドカード(*)ありとする!
|
||||
List<string> listA = new List<string>();
|
||||
foreach (var name in sheetNames)
|
||||
{
|
||||
foreach (var iName in includedSheets)
|
||||
{
|
||||
if (StringUxer.WildcardMatch(name, iName))
|
||||
{
|
||||
listA.Add(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return listA;
|
||||
}
|
||||
|
||||
// Excluded適用 → lineNamesの中でexcludedに含まれないものだけ返す
|
||||
//return sheetNames.Where(name => !excludedSheets.Contains(name));
|
||||
// ワイルドカード(*)ありとする!
|
||||
List<string> listB = new List<string>();
|
||||
foreach (var name in sheetNames)
|
||||
{
|
||||
var isMatch = false;
|
||||
foreach (var eName in excludedSheets)
|
||||
{
|
||||
if (StringUxer.WildcardMatch(name, eName))
|
||||
{
|
||||
isMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isMatch) listB.Add(name);
|
||||
}
|
||||
return listB;
|
||||
}
|
||||
public bool CanPass(string sheetName)
|
||||
{
|
||||
return HasAnyPass(new[] { sheetName });
|
||||
}
|
||||
|
||||
public bool HasAnyPass(IEnumerable<string> sheetNames)
|
||||
{
|
||||
return ApplyFilter(sheetNames).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user