2013-02-19 09:01:03 +03:00
|
|
|
using System.Linq;
|
|
|
|
using System;
|
2013-03-26 08:51:56 +03:00
|
|
|
using NzbDrone.Core.Datastore;
|
2013-02-27 06:19:22 +03:00
|
|
|
using NzbDrone.Core.Qualities;
|
2011-05-28 22:23:35 +03:00
|
|
|
|
2013-02-19 09:01:03 +03:00
|
|
|
namespace NzbDrone.Core.Tv
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
2013-03-26 08:51:56 +03:00
|
|
|
public class QualityModel : IComparable<QualityModel>, IEmbeddedDocument
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
public Quality Quality { get; set; }
|
2011-05-28 22:23:35 +03:00
|
|
|
|
|
|
|
public Boolean Proper { get; set; }
|
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public QualityModel():this(Quality.Unknown, false)
|
2013-02-24 00:29:22 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2011-05-28 22:23:35 +03:00
|
|
|
|
2013-02-27 06:19:22 +03:00
|
|
|
public QualityModel(Quality quality, Boolean proper)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
2012-10-14 03:36:16 +03:00
|
|
|
Quality = quality;
|
2011-05-28 22:23:35 +03:00
|
|
|
Proper = proper;
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public int CompareTo(QualityModel other)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
2012-10-14 03:36:16 +03:00
|
|
|
if (other.Quality > Quality)
|
2011-05-28 22:23:35 +03:00
|
|
|
return -1;
|
|
|
|
|
2012-10-14 03:36:16 +03:00
|
|
|
if (other.Quality < Quality)
|
2011-05-28 22:23:35 +03:00
|
|
|
return 1;
|
|
|
|
|
2012-10-14 03:36:16 +03:00
|
|
|
if (other.Quality == Quality && other.Proper == Proper)
|
2011-05-28 22:23:35 +03:00
|
|
|
return 0;
|
|
|
|
|
2011-06-18 04:46:22 +03:00
|
|
|
if (Proper && !other.Proper)
|
2011-05-28 22:23:35 +03:00
|
|
|
return 1;
|
|
|
|
|
2011-06-18 04:46:22 +03:00
|
|
|
if (!Proper && other.Proper)
|
2011-05-28 22:23:35 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator !=(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
|
|
|
return !(x == y);
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator ==(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
|
|
|
var xObj = (Object)x;
|
|
|
|
var yObj = (object)y;
|
|
|
|
|
|
|
|
if (xObj == null || yObj == null)
|
|
|
|
{
|
|
|
|
return xObj == yObj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x.CompareTo(y) == 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator >(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) > 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator <(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
2012-10-14 03:36:16 +03:00
|
|
|
return x.CompareTo(y) < 0;
|
2011-05-28 22:23:35 +03:00
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator <=(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) <= 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public static bool operator >=(QualityModel x, QualityModel y)
|
2011-05-28 22:23:35 +03:00
|
|
|
{
|
|
|
|
return x.CompareTo(y) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2012-10-14 03:36:16 +03:00
|
|
|
string result = Quality.ToString();
|
2011-05-28 22:23:35 +03:00
|
|
|
if (Proper)
|
|
|
|
{
|
|
|
|
result += " [proper]";
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-06-19 23:43:47 +03:00
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
unchecked // Overflow is fine, just wrap
|
|
|
|
{
|
|
|
|
int hash = 17;
|
|
|
|
hash = hash * 23 + Proper.GetHashCode();
|
2012-10-14 03:36:16 +03:00
|
|
|
hash = hash * 23 + Quality.GetHashCode();
|
2011-06-19 23:43:47 +03:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 00:15:21 +03:00
|
|
|
public bool Equals(QualityModel other)
|
2011-06-19 23:43:47 +03:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, other)) return false;
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
2012-10-14 03:36:16 +03:00
|
|
|
return Equals(other.Quality, Quality) && other.Proper.Equals(Proper);
|
2011-06-19 23:43:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, obj)) return false;
|
|
|
|
if (ReferenceEquals(this, obj)) return true;
|
2012-10-14 00:15:21 +03:00
|
|
|
if (obj.GetType() != typeof (QualityModel)) return false;
|
|
|
|
return Equals((QualityModel) obj);
|
2011-06-19 23:43:47 +03:00
|
|
|
}
|
2011-05-28 22:23:35 +03:00
|
|
|
}
|
|
|
|
}
|