|
5 | 5 |
|
6 | 6 | namespace GitHub.Models |
7 | 7 | { |
8 | | - public class RepositoryModel : SimpleRepositoryModel, IRepositoryModel, IEquatable<RepositoryModel> |
| 8 | + public class RepositoryModel : SimpleRepositoryModel, IRepositoryModel, |
| 9 | + IEquatable<RepositoryModel>, IComparable<RepositoryModel> |
9 | 10 | { |
10 | | - public RepositoryModel(string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount) |
| 11 | + public RepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount) |
11 | 12 | : base(name, cloneUrl) |
12 | 13 | { |
| 14 | + Id = id; |
13 | 15 | Owner = ownerAccount; |
14 | 16 | SetIcon(isPrivate, isFork); |
15 | 17 | } |
16 | 18 |
|
17 | | - public IAccount Owner { get; private set; } |
| 19 | + public void CopyFrom(IRepositoryModel other) |
| 20 | + { |
| 21 | + if (!Equals(other)) |
| 22 | + throw new ArgumentException("Instance to copy from doesn't match this instance. this:(" + this + ") other:(" + other + ")", nameof(other)); |
| 23 | + Icon = other.Icon; |
| 24 | + } |
| 25 | + |
18 | 26 | public override int GetHashCode() |
19 | 27 | { |
20 | | - return (Owner?.GetHashCode() ?? 0) ^ base.GetHashCode(); |
| 28 | + return Id.GetHashCode(); |
21 | 29 | } |
22 | 30 |
|
23 | 31 | public override bool Equals([AllowNull]object obj) |
24 | 32 | { |
25 | 33 | if (ReferenceEquals(this, obj)) |
26 | 34 | return true; |
27 | 35 | var other = obj as RepositoryModel; |
28 | | - return other != null && Equals(Owner, other.Owner) && base.Equals(obj); |
| 36 | + return other != null && Id == other.Id; |
| 37 | + } |
| 38 | + |
| 39 | + bool IEquatable<IRepositoryModel>.Equals([AllowNull]IRepositoryModel other) |
| 40 | + { |
| 41 | + if (ReferenceEquals(this, other)) |
| 42 | + return true; |
| 43 | + return other != null && Id == other.Id; |
29 | 44 | } |
30 | 45 |
|
31 | 46 | bool IEquatable<RepositoryModel>.Equals([AllowNull]RepositoryModel other) |
32 | 47 | { |
33 | 48 | if (ReferenceEquals(this, other)) |
34 | 49 | return true; |
35 | | - return other != null && Equals(Owner, other.Owner) && base.Equals(other as SimpleRepositoryModel); |
| 50 | + return other != null && Id == other.Id; |
| 51 | + } |
| 52 | + |
| 53 | + public int CompareTo([AllowNull]IRepositoryModel other) |
| 54 | + { |
| 55 | + return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1; |
| 56 | + } |
| 57 | + |
| 58 | + public int CompareTo([AllowNull]RepositoryModel other) |
| 59 | + { |
| 60 | + return other != null ? UpdatedAt.CompareTo(other.UpdatedAt) : 1; |
36 | 61 | } |
37 | 62 |
|
| 63 | + public static bool operator >([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs) |
| 64 | + { |
| 65 | + if (ReferenceEquals(lhs, rhs)) |
| 66 | + return false; |
| 67 | + return lhs?.CompareTo(rhs) > 0; |
| 68 | + } |
| 69 | + |
| 70 | + public static bool operator <([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs) |
| 71 | + { |
| 72 | + if (ReferenceEquals(lhs, rhs)) |
| 73 | + return false; |
| 74 | + return (object)lhs == null || lhs.CompareTo(rhs) < 0; |
| 75 | + } |
| 76 | + |
| 77 | + public static bool operator ==([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs) |
| 78 | + { |
| 79 | + return ReferenceEquals(lhs, rhs); |
| 80 | + } |
| 81 | + |
| 82 | + public static bool operator !=([AllowNull]RepositoryModel lhs, [AllowNull]RepositoryModel rhs) |
| 83 | + { |
| 84 | + return !(lhs == rhs); |
| 85 | + } |
| 86 | + |
| 87 | + public IAccount Owner { get; } |
| 88 | + public long Id { get; } |
| 89 | + public DateTimeOffset CreatedAt { get; set; } |
| 90 | + public DateTimeOffset UpdatedAt { get; set; } |
| 91 | + |
38 | 92 | internal string DebuggerDisplay |
39 | 93 | { |
40 | 94 | get |
41 | 95 | { |
42 | 96 | return String.Format(CultureInfo.InvariantCulture, |
43 | | - "{4}\tName: {0} CloneUrl: {1} LocalPath: {2} Account: {3}", Name, CloneUrl, LocalPath, Owner, GetHashCode()); |
| 97 | + "{5}\tId: {0} Name: {1} CloneUrl: {2} LocalPath: {3} Account: {4}", Id, Name, CloneUrl, LocalPath, Owner, GetHashCode()); |
44 | 98 | } |
45 | 99 | } |
46 | 100 | } |
|
0 commit comments