Files
ALGA/ALGA/Paradigmak/02_FunkcionalisParadigma.cs
2025-09-28 13:53:38 +02:00

101 lines
2.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
namespace OE.ALGA.Paradigmak
{
public class FeltetelesFeladatTarolo<T> : FeladatTarolo<T>, IEnumerable<T> where T : IVegrehajthato
{
public Func<T, bool> BejaroFeltetel
{
get;
set;
}
public bool Igaz(T t)
{
return true;
}
public FeltetelesFeladatTarolo(int l) : base(l)
{
BejaroFeltetel = Igaz;
}
public void FeltetelesVegrehajtas(Func<T, bool> feltetel)
{
foreach (T t in tarolo)
{
if (t != null && feltetel(t))
{
t.Vegrehajtas();
}
}
}
new public IEnumerator GetEnumerator()
{
FeltetelesFeladatTaroloBejaro<T> bejaro = new FeltetelesFeladatTaroloBejaro<T>(tarolo, n, BejaroFeltetel);
return bejaro.GetEnumerator();
}
}
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T> where T : IVegrehajthato
{
T[] tarolo;
int n;
int aktualisindex;
public Func<T, bool> Feltetel
{
get;
}
public T Current
{
get { return tarolo[aktualisindex]; }
}
public FeltetelesFeladatTaroloBejaro(T[] tarolo, int n, Func<T, bool> feltetel)
{
this.tarolo = tarolo;
this.n = n;
aktualisindex = 0;
Feltetel = feltetel;
}
object IEnumerator.Current => throw new NotImplementedException();
public IEnumerator GetEnumerator()
{
foreach (T t in tarolo)
{
if (t != null && Feltetel(t))
{
yield return t;
}
}
}
public void Dispose()
{
throw new NotImplementedException();
}
public bool MoveNext()
{
if (aktualisindex < n - 1)
{
aktualisindex++;
if (Feltetel(tarolo[aktualisindex]))
{
return true;
}
return MoveNext();
}
else
{
return false;
}
}
public void Reset()
{
aktualisindex = -1;
}
}
}