Equal overrides

This commit is contained in:
glax 2024-01-29 17:05:13 +01:00
parent 60c1ece41d
commit 90f804c7c6
7 changed files with 79 additions and 1 deletions

View File

@ -69,6 +69,21 @@ public abstract class Device : IDisposable
$"DurationRange: {DurationRange}\n\r";
}
public override bool Equals(object? obj)
{
return obj is Device d && Equals(d);
}
protected bool Equals(Device other)
{
return IntensityRange.Equals(other.IntensityRange) && DurationRange.Equals(other.DurationRange) && ApiType == other.ApiType;
}
public override int GetHashCode()
{
return HashCode.Combine(IntensityRange, DurationRange, (int)ApiType);
}
public void Dispose()
{
_workQueue = false;

View File

@ -18,7 +18,22 @@ public abstract class OpenShockDevice : Device
this.Endpoint = endpoint;
this.ApiKey = apiKey;
}
public override bool Equals(object? obj)
{
return obj is OpenShockDevice osd && Equals(osd);
}
private bool Equals(OpenShockDevice other)
{
return base.Equals(other) && Endpoint == other.Endpoint && ApiKey == other.ApiKey;
}
public override int GetHashCode()
{
return HashCode.Combine(Endpoint, ApiKey);
}
public List<OpenShockShocker> GetShockers()
{
List<OpenShockShocker> shockers = new();

View File

@ -6,4 +6,9 @@ public class DurationRange : RandomIntegerRange
{
}
public override bool Equals(object? obj)
{
return obj is IntensityRange && base.Equals(obj);
}
}

View File

@ -6,4 +6,9 @@ public class IntensityRange : RandomIntegerRange
{
}
public override bool Equals(object? obj)
{
return obj is IntensityRange && base.Equals(obj);
}
}

View File

@ -24,4 +24,11 @@ public abstract class RandomIntegerRange
{
return $"Min: {Min} Max: {Max}";
}
public override bool Equals(object? obj)
{
return obj is RandomIntegerRange rir &&
this.Min == rir.Min &&
this.Max == rir.Max;
}
}

View File

@ -29,4 +29,20 @@ public struct OpenShockShocker : IShocker
$"Created On: {createdOn}\n" +
$"Paused: {isPaused}\n\r";
}
public override bool Equals(object? obj)
{
return obj is OpenShockShocker oss && Equals(oss);
}
private bool Equals(OpenShockShocker other)
{
return id == other.id && rfId == other.rfId && model == other.model && createdOn.Equals(other.createdOn);
}
public override int GetHashCode()
{
return HashCode.Combine(id, rfId, (int)model, createdOn);
}
}

View File

@ -5,4 +5,19 @@ namespace CShocker.Shockers;
public struct PiShockShocker : IShocker
{
public string Code;
public override bool Equals(object? obj)
{
return obj is PiShockShocker pss && Equals(pss);
}
private bool Equals(PiShockShocker other)
{
return Code == other.Code;
}
public override int GetHashCode()
{
return Code.GetHashCode();
}
}