//
// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
// █__ --█ █__ --█ ◄█ - █
// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
// │ 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
// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
//
namespace slskd
{
using System;
///
/// Uniquely identifies a Wait.
///
public sealed class WaitKey : IEquatable
{
///
/// Initializes a new instance of the class.
///
/// The parts which make up the key.
public WaitKey(params object[] tokenParts)
{
TokenParts = tokenParts;
Token = string.Join(":", TokenParts);
}
///
/// Gets the wait token.
///
public string Token { get; }
///
/// Gets the parts which make up the key.
///
public object[] TokenParts { get; }
public static bool operator !=(WaitKey lhs, WaitKey rhs)
{
return !lhs.Equals(rhs);
}
public static bool operator ==(WaitKey lhs, WaitKey rhs)
{
return lhs.Equals(rhs);
}
///
/// Compares the specified to this instance.
///
/// The object to which to compare.
/// A value indicating whether the specified object is equal to this instance.
public override bool Equals(object obj)
{
try
{
return Equals((WaitKey)obj);
}
catch (InvalidCastException)
{
return false;
}
}
///
/// Compares the specified WaitKey to this instance.
///
/// The WaitKey to which to compare.
/// A value indicating whether the specified WaitKey is equal to this instance.
public bool Equals(WaitKey other)
{
return Token == other.Token;
}
///
/// Returns the hash code of this instance.
///
/// The hash code of this instance.
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
}
///
/// Returns the string representation of the key.
///
/// The string representation of the key.
public override string ToString()
{
return Token;
}
}
}