sonarr-repo-only/NzbDrone.Core/Model/QualityModel.cs

116 lines
3.0 KiB
C#
Raw Normal View History

2011-05-28 19:23:35 +00:00
using System;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Model
{
2012-10-13 21:15:21 +00:00
public class QualityModel : IComparable<QualityModel>
2011-05-28 19:23:35 +00:00
{
public QualityTypes QualityType { get; set; }
public Boolean Proper { get; set; }
2012-10-13 21:15:21 +00:00
public QualityModel() { }
2011-05-28 19:23:35 +00:00
2012-10-13 21:15:21 +00:00
public QualityModel(QualityTypes quality, Boolean proper)
2011-05-28 19:23:35 +00:00
{
QualityType = quality;
Proper = proper;
}
2012-10-13 21:15:21 +00:00
public int CompareTo(QualityModel other)
2011-05-28 19:23:35 +00:00
{
2011-06-18 01:46:22 +00:00
if (other.QualityType > QualityType)
2011-05-28 19:23:35 +00:00
return -1;
2011-06-18 01:46:22 +00:00
if (other.QualityType < QualityType)
2011-05-28 19:23:35 +00:00
return 1;
2011-06-18 01:46:22 +00:00
if (other.QualityType == QualityType && other.Proper == Proper)
2011-05-28 19:23:35 +00:00
return 0;
2011-06-18 01:46:22 +00:00
if (Proper && !other.Proper)
2011-05-28 19:23:35 +00:00
return 1;
2011-06-18 01:46:22 +00:00
if (!Proper && other.Proper)
2011-05-28 19:23:35 +00:00
return -1;
return 0;
}
2012-10-13 21:15:21 +00:00
public static bool operator !=(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
return !(x == y);
}
2012-10-13 21:15:21 +00:00
public static bool operator ==(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
var xObj = (Object)x;
var yObj = (object)y;
if (xObj == null || yObj == null)
{
return xObj == yObj;
}
return x.CompareTo(y) == 0;
}
2012-10-13 21:15:21 +00:00
public static bool operator >(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
return x.CompareTo(y) > 0;
}
2012-10-13 21:15:21 +00:00
public static bool operator <(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
return x.CompareTo(y) < 1;
}
2012-10-13 21:15:21 +00:00
public static bool operator <=(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
return x.CompareTo(y) <= 0;
}
2012-10-13 21:15:21 +00:00
public static bool operator >=(QualityModel x, QualityModel y)
2011-05-28 19:23:35 +00:00
{
return x.CompareTo(y) >= 0;
}
public override string ToString()
{
string result = QualityType.ToString();
if (Proper)
{
result += " [proper]";
}
return result;
}
2011-06-19 20:43:47 +00:00
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
hash = hash * 23 + Proper.GetHashCode();
hash = hash * 23 + QualityType.GetHashCode();
return hash;
}
}
2012-10-13 21:15:21 +00:00
public bool Equals(QualityModel other)
2011-06-19 20:43:47 +00:00
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other.QualityType, QualityType) && other.Proper.Equals(Proper);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
2012-10-13 21:15:21 +00:00
if (obj.GetType() != typeof (QualityModel)) return false;
return Equals((QualityModel) obj);
2011-06-19 20:43:47 +00:00
}
2011-05-28 19:23:35 +00:00
}
}