Refactor event handling and improve argument validation across indicators

- Updated event handler signatures to use TValueEventArgs for consistency in Mama, Mgdi, Pwma, Rma, Sma, Ssf, Super, T3, Tema, Trima, Usf, Vidya, Wma, and Atr classes.
- Enhanced argument validation by specifying parameter names in exceptions for clarity.
- Adjusted tests to align with new event handler signatures.
- Improved code readability and maintainability by using structured records and lambda expressions.
This commit is contained in:
Miha Kralj
2025-12-27 15:46:28 -08:00
parent 4750c2b1e8
commit d7dbd7078a
73 changed files with 502 additions and 300 deletions
+8 -4
View File
@@ -23,6 +23,7 @@ namespace QuanTAlib;
[SkipLocalsInit]
public sealed class Bessel : AbstractBase, IDisposable
{
[StructLayout(LayoutKind.Auto)]
private record struct State(double F1, double F2, double LastValidValue, int Count, bool IsHot)
{
public static State New() => new()
@@ -37,7 +38,7 @@ public sealed class Bessel : AbstractBase, IDisposable
private readonly double _c1, _c2, _c3;
private readonly ITValuePublisher? _publisher;
private readonly Action<TValue>? _handler;
private readonly TValuePublishedHandler? _handler;
private State _state = State.New();
private State _p_state = State.New();
@@ -68,7 +69,7 @@ public sealed class Bessel : AbstractBase, IDisposable
public Bessel(ITValuePublisher source, int length) : this(length)
{
_publisher = source;
_handler = item => Update(item);
_handler = Handle;
source.Pub += _handler;
}
@@ -84,7 +85,7 @@ public sealed class Bessel : AbstractBase, IDisposable
}
_publisher = source;
_handler = item => Update(item);
_handler = Handle;
source.Pub += _handler;
}
@@ -291,7 +292,7 @@ public sealed class Bessel : AbstractBase, IDisposable
throw new ArgumentException("Length must be greater than 0", nameof(length));
if (source.Length != output.Length)
throw new ArgumentException("Source and output must have the same length");
throw new ArgumentException("Source and output must have the same length", nameof(output));
if (source.Length == 0)
return;
@@ -309,6 +310,9 @@ public sealed class Bessel : AbstractBase, IDisposable
CalculateCore(source, output, c1, c2, c3, length, ref state);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Handle(object? sender, TValueEventArgs e) => Update(e.Value, e.IsNew);
public override void Reset()
{
_state = State.New();