Commit ee7576fa authored by Nick Craver's avatar Nick Craver

Cleanup: SortedSetEntry

parent 343d1345
......@@ -4,10 +4,6 @@
namespace StackExchange.Redis
{
/// <summary>
/// Describes a sorted-set element with the corresponding value
/// </summary>
......@@ -17,13 +13,16 @@ public struct SortedSetEntry : IEquatable<SortedSetEntry>, IComparable, ICompara
internal readonly double score;
/// <summary>
/// Initializes a SortedSetEntry value
/// Initializes a <see cref="SortedSetEntry"/> value.
/// </summary>
/// <param name="element">The <see cref="RedisValue"/> to get an entry for.</param>
/// <param name="score">The redis score for <paramref name="element"/>.</param>
public SortedSetEntry(RedisValue element, double score)
{
this.element = element;
this.score = score;
}
/// <summary>
/// The unique element stored in the sorted set
/// </summary>
......@@ -51,78 +50,61 @@ public SortedSetEntry(RedisValue element, double score)
/// <summary>
/// Converts to a key/value pair
/// </summary>
public static implicit operator KeyValuePair<RedisValue,double>(SortedSetEntry value)
{
return new KeyValuePair<RedisValue, double>(value.element, value.score);
}
/// <param name="value">The <see cref="SortedSetEntry"/> to get a <see cref="KeyValuePair{TKey, TValue}"/> for.</param>
public static implicit operator KeyValuePair<RedisValue, double>(SortedSetEntry value) => new KeyValuePair<RedisValue, double>(value.element, value.score);
/// <summary>
/// Converts from a key/value pair
/// </summary>
public static implicit operator SortedSetEntry(KeyValuePair<RedisValue, double> value)
{
return new SortedSetEntry(value.Key, value.Value);
}
/// <param name="value">The <see cref="KeyValuePair{TKey, TValue}"/> to get a <see cref="SortedSetEntry"/> for.</param>
public static implicit operator SortedSetEntry(KeyValuePair<RedisValue, double> value) => new SortedSetEntry(value.Key, value.Value);
/// <summary>
/// See Object.ToString()
/// </summary>
public override string ToString()
{
return element + ": " + score;
}
public override string ToString() => element + ": " + score;
/// <summary>
/// See Object.GetHashCode()
/// </summary>
public override int GetHashCode()
{
return element.GetHashCode() ^ score.GetHashCode();
}
public override int GetHashCode() => element.GetHashCode() ^ score.GetHashCode();
/// <summary>
/// Compares two values for equality
/// </summary>
public override bool Equals(object obj)
{
return obj is SortedSetEntry && Equals((SortedSetEntry)obj);
}
/// <param name="obj">The <see cref="SortedSetEntry"/> to compare to.</param>
public override bool Equals(object obj) => obj is SortedSetEntry ssObj && Equals(ssObj);
/// <summary>
/// Compares two values for equality
/// </summary>
public bool Equals(SortedSetEntry other)
{
return score == other.score && element == other.element;
}
/// <param name="other">The <see cref="SortedSetEntry"/> to compare to.</param>
public bool Equals(SortedSetEntry other) => score == other.score && element == other.element;
/// <summary>
/// Compares two values by score
/// </summary>
public int CompareTo(SortedSetEntry other)
{
return score.CompareTo(other.score);
}
/// <param name="other">The <see cref="SortedSetEntry"/> to compare to.</param>
public int CompareTo(SortedSetEntry other) => score.CompareTo(other.score);
/// <summary>
/// Compares two values by score
/// </summary>
public int CompareTo(object obj)
{
return obj is SortedSetEntry ? CompareTo((SortedSetEntry)obj) : -1;
}
/// <param name="obj">The <see cref="SortedSetEntry"/> to compare to.</param>
public int CompareTo(object obj) => obj is SortedSetEntry ssObj ? CompareTo(ssObj) : -1;
/// <summary>
/// Compares two values for equality
/// </summary>
public static bool operator ==(SortedSetEntry x, SortedSetEntry y)
{
return x.score == y.score && x.element == y.element;
}
/// <param name="x">The first <see cref="SortedSetEntry"/> to compare.</param>
/// <param name="y">The second <see cref="SortedSetEntry"/> to compare.</param>
public static bool operator ==(SortedSetEntry x, SortedSetEntry y) => x.score == y.score && x.element == y.element;
/// <summary>
/// Compares two values for non-equality
/// </summary>
public static bool operator !=(SortedSetEntry x, SortedSetEntry y)
{
return x.score != y.score || x.element != y.element;
}
/// <param name="x">The first <see cref="SortedSetEntry"/> to compare.</param>
/// <param name="y">The second <see cref="SortedSetEntry"/> to compare.</param>
public static bool operator !=(SortedSetEntry x, SortedSetEntry y) => x.score != y.score || x.element != y.element;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment