2014-09-01 02:28:42 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Qualities
|
|
|
|
|
{
|
|
|
|
|
public class Revision : IEquatable<Revision>, IComparable<Revision>
|
|
|
|
|
{
|
2019-12-18 02:17:47 +00:00
|
|
|
|
private Revision()
|
2014-09-23 02:48:28 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2019-12-22 21:24:11 +00:00
|
|
|
|
|
2019-07-13 03:56:58 +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;
|
2019-07-13 03:56:58 +00:00
|
|
|
|
IsRepack = isRepack;
|
2014-09-01 02:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 17:45:26 +00:00
|
|
|
|
public int Version { get; set; }
|
|
|
|
|
public int Real { get; set; }
|
2019-07-13 03:56:58 +00:00
|
|
|
|
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-23 17:56:15 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|