blob: 3306103d131c874233630632ebc5283889375c75 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// <copyright file="WaitKey.cs" company="JP Dillingham">
// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
// █__ --█ █__ --█ ◄█ - █
// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
// │ Copyright (c) JP Dillingham.
// │
// │ This program is free software: you can redistribute it and/or modify
// │ it under the terms of the GNU Affero General Public License as published
// │ by the Free Software Foundation, version 3.
// │
// │ This program is distributed in the hope that it will be useful,
// │ but WITHOUT ANY WARRANTY; without even the implied warranty of
// │ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// │ GNU Affero General Public License for more details.
// │
// │ You should have received a copy of the GNU Affero General Public License
// │ along with this program. If not, see https://www.gnu.org/licenses/.
// │
// │ This program is distributed with Additional Terms pursuant to Section 7
// │ of the AGPLv3. See the LICENSE file in the root directory of this
// │ project for the complete terms and conditions.
// │
// │ https://slskd.org
// │
// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌
// │ SPDX-FileCopyrightText: JP Dillingham
// │ SPDX-License-Identifier: AGPL-3.0-only
// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
// </copyright>
namespace slskd
{
using System;
/// <summary>
/// Uniquely identifies a Wait.
/// </summary>
public sealed class WaitKey : IEquatable<WaitKey>
{
/// <summary>
/// Initializes a new instance of the <see cref="WaitKey"/> class.
/// </summary>
/// <param name="tokenParts">The parts which make up the key.</param>
public WaitKey(params object[] tokenParts)
{
TokenParts = tokenParts;
Token = string.Join(":", TokenParts);
}
/// <summary>
/// Gets the wait token.
/// </summary>
public string Token { get; }
/// <summary>
/// Gets the parts which make up the key.
/// </summary>
public object[] TokenParts { get; }
public static bool operator !=(WaitKey lhs, WaitKey rhs)
{
return !(lhs == rhs);
}
public static bool operator ==(WaitKey lhs, WaitKey rhs)
{
return lhs is null ? rhs is null : lhs.Equals(rhs);
}
/// <summary>
/// Compares the specified <paramref name="obj"/> to this instance.
/// </summary>
/// <param name="obj">The object to which to compare.</param>
/// <returns>A value indicating whether the specified object is equal to this instance.</returns>
public override bool Equals(object obj)
{
try
{
return Equals((WaitKey)obj);
}
catch (InvalidCastException)
{
return false;
}
}
/// <summary>
/// Compares the specified <paramref name="other"/> WaitKey to this instance.
/// </summary>
/// <param name="other">The WaitKey to which to compare.</param>
/// <returns>A value indicating whether the specified WaitKey is equal to this instance.</returns>
public bool Equals(WaitKey other)
{
return other is not null && Token == other.Token;
}
/// <summary>
/// Returns the hash code of this instance.
/// </summary>
/// <returns>The hash code of this instance.</returns>
public override int GetHashCode()
{
#if NETSTANDARD2_0
return string.IsNullOrEmpty(Token) ? 0 : Token.GetHashCode();
#else
return string.IsNullOrEmpty(Token) ? 0 : Token.GetHashCode(StringComparison.InvariantCulture);
#endif
}
/// <summary>
/// Returns the string representation of the key.
/// </summary>
/// <returns>The string representation of the key.</returns>
public override string ToString()
{
return Token;
}
}
}
|