Radarr/src/NzbDrone.Core/Qualities/Revision.cs

163 lines
3.5 KiB
C#
Raw Normal View History

2014-09-01 02:28:42 +00:00
using System;
using System.Text;
namespace NzbDrone.Core.Qualities
{
public class Revision : IEquatable<Revision>, IComparable<Revision>
{
private Revision()
{
}
2019-12-22 21:24:11 +00:00
public Revision(int version = 1, int real = 0, bool isRepack = false)
2014-09-01 02:28:42 +00:00
{
Version = version;
Real = real;
IsRepack = isRepack;
2014-09-01 02:28:42 +00:00
}
public int Version { get; set; }
public int Real { get; set; }
public bool IsRepack { get; set; }
2014-09-01 02:28:42 +00:00
public bool Equals(Revision other)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, other))
{
return false;
}
2014-09-01 02:28:42 +00:00
return other.Version.Equals(Version) && other.Real.Equals(Real);
}
public int CompareTo(Revision other)
{
2019-12-22 22:08:53 +00:00
if (Real > other.Real)
{
return 1;
}
if (Real < other.Real)
{
return -1;
}
if (Version > other.Version)
{
return 1;
}
if (Version < other.Version)
{
return -1;
}
2014-09-01 02:28:42 +00:00
return 0;
}
public override string ToString()
{
var sb = new StringBuilder();
2014-09-01 02:28:42 +00:00
sb.AppendFormat("v{0}", Version);
if (Real > 0)
{
sb.AppendFormat(" Real:{0}", Real);
}
return sb.ToString();
}
public override int GetHashCode()
{
return Version ^ Real << 8;
}
public override bool Equals(object obj)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
2014-09-01 02:28:42 +00:00
return Equals(obj as Revision);
}
public static bool operator ==(Revision left, Revision right)
{
return Equals(left, right);
}
public static bool operator !=(Revision left, Revision right)
{
return !Equals(left, right);
}
public static bool operator >(Revision left, Revision right)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, left))
{
return false;
}
if (ReferenceEquals(null, right))
{
return true;
}
2014-09-01 02:28:42 +00:00
return left.CompareTo(right) > 0;
}
public static bool operator <(Revision left, Revision right)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, left))
{
return true;
}
if (ReferenceEquals(null, right))
{
return false;
}
2014-09-01 02:28:42 +00:00
return left.CompareTo(right) < 0;
}
public static bool operator >=(Revision left, Revision right)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, left))
{
return false;
}
if (ReferenceEquals(null, right))
{
return true;
}
2014-09-01 02:28:42 +00:00
return left.CompareTo(right) >= 0;
}
public static bool operator <=(Revision left, Revision right)
{
2019-12-22 22:08:53 +00:00
if (ReferenceEquals(null, left))
{
return true;
}
if (ReferenceEquals(null, right))
{
return false;
}
2014-09-01 02:28:42 +00:00
return left.CompareTo(right) <= 0;
}
}
}