Import from internal git
This commit is contained in:
76
Core/ProcessEnumerator.cs
Normal file
76
Core/ProcessEnumerator.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System.Collections;
|
||||
using Core.Helpers;
|
||||
using Core.SpecConfig;
|
||||
|
||||
namespace Core;
|
||||
|
||||
public class ProcessEnumerator : IEnumerator
|
||||
{
|
||||
|
||||
private int _languagePosition;
|
||||
private int _typePosition;
|
||||
|
||||
private readonly List<ProcessTask> _enumerable;
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public ProcessTask Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enumerable.First(pt => (int)pt.GenerationType == _typePosition
|
||||
&& (int)pt.Language == _languagePosition);
|
||||
}
|
||||
}
|
||||
|
||||
public ProcessEnumerator(List<ProcessTask> current)
|
||||
{
|
||||
_languagePosition = -1;
|
||||
_typePosition = -1;
|
||||
_enumerable = current;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (_typePosition == -1 && _languagePosition == -1)
|
||||
{
|
||||
_typePosition += 1;
|
||||
_languagePosition += 1;
|
||||
|
||||
} else if (PassedTypeBoundaries())
|
||||
{
|
||||
_typePosition = 0;
|
||||
_languagePosition += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_typePosition += 1;
|
||||
}
|
||||
|
||||
if (!HasElement() && !PassedMaxPosition())
|
||||
{
|
||||
MoveNext();
|
||||
}
|
||||
return !PassedMaxPosition();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_languagePosition = -1;
|
||||
_typePosition = -1;
|
||||
}
|
||||
|
||||
private bool PassedLanguageBoundaries() => _languagePosition >= EnumHelper.GetMaxValue<Language>() - 1;
|
||||
|
||||
private bool PassedTypeBoundaries() => _typePosition >= EnumHelper.GetMaxValue<GenerationType>() - 1;
|
||||
|
||||
private bool PassedMaxPosition() => PassedLanguageBoundaries() && PassedTypeBoundaries();
|
||||
|
||||
private bool HasElement()
|
||||
{
|
||||
var e= _enumerable.FirstOrDefault(pt => (int)pt.GenerationType == _typePosition
|
||||
&& (int)pt.Language == _languagePosition);
|
||||
return e != null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user