Removes old comparable/comparers. (#31)
This commit is contained in:
parent
513e54f70e
commit
a45094f2dc
23 changed files with 95 additions and 249 deletions
|
|
@ -161,10 +161,10 @@ namespace Server
|
|||
return Compare(l, r) < 0;
|
||||
}
|
||||
|
||||
// public override int GetHashCode()
|
||||
// {
|
||||
// return Major ^ Minor ^ Revision ^ Patch ^ (int)Type;
|
||||
// }
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Major ^ Minor ^ Revision ^ Patch ^ (int)Type;
|
||||
}
|
||||
|
||||
int IComparer<ClientVersion>.Compare(ClientVersion x, ClientVersion y)
|
||||
{
|
||||
|
|
@ -173,15 +173,9 @@ namespace Server
|
|||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
|
||||
ClientVersion v = obj as ClientVersion;
|
||||
|
||||
if (v == null)
|
||||
return false;
|
||||
|
||||
return Major == v.Major
|
||||
return Major == v?.Major
|
||||
&& Minor == v.Minor
|
||||
&& Revision == v.Revision
|
||||
&& Patch == v.Patch
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ namespace Server.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public class CommandEntry : IComparable
|
||||
public class CommandEntry : IComparable<CommandEntry>
|
||||
{
|
||||
public CommandEntry(string command, CommandEventHandler handler, AccessLevel accessLevel)
|
||||
{
|
||||
|
|
@ -110,17 +110,9 @@ namespace Server.Commands
|
|||
|
||||
public AccessLevel AccessLevel{ get; }
|
||||
|
||||
public int CompareTo(object obj)
|
||||
public int CompareTo(CommandEntry e)
|
||||
{
|
||||
if (obj == this)
|
||||
return 0;
|
||||
if (obj == null)
|
||||
return 1;
|
||||
|
||||
if (!(obj is CommandEntry e))
|
||||
throw new ArgumentException();
|
||||
|
||||
return Command.CompareTo(e.Command);
|
||||
return e == null ? 1 : Command.CompareTo(e.Command);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,16 +84,6 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other is Point2D d)
|
||||
return CompareTo(d);
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
return o is IPoint2D p && m_X == p.X && m_Y == p.Y;
|
||||
|
|
@ -301,16 +291,6 @@ namespace Server
|
|||
|
||||
return v;
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other is Point3D d)
|
||||
return CompareTo(d);
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
[NoSort]
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ using System;
|
|||
|
||||
namespace Server
|
||||
{
|
||||
public interface IEntity : IPoint3D, IComparable, IComparable<IEntity>
|
||||
public interface IEntity : IPoint3D, IComparable<IEntity>
|
||||
{
|
||||
Serial Serial{ get; }
|
||||
Point3D Location{ get; }
|
||||
|
|
@ -51,18 +51,7 @@ namespace Server
|
|||
|
||||
public int CompareTo(IEntity other)
|
||||
{
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
return Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other == null || other is IEntity)
|
||||
return CompareTo((IEntity)other);
|
||||
|
||||
throw new ArgumentException();
|
||||
return other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public Serial Serial{ get; }
|
||||
|
|
@ -93,4 +82,4 @@ namespace Server
|
|||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,14 @@
|
|||
*
|
||||
***************************************************************************/
|
||||
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public static class Insensitive
|
||||
{
|
||||
public static IComparer Comparer{ get; } = CaseInsensitiveComparer.Default;
|
||||
public static IComparer<string> Comparer{ get; } = StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
public static int Compare(string a, string b)
|
||||
{
|
||||
|
|
@ -68,4 +69,4 @@ namespace Server
|
|||
return a.IndexOf(b) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1349,25 +1349,14 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
int IComparable<IEntity>.CompareTo(IEntity other)
|
||||
{
|
||||
return other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public int CompareTo(Item other)
|
||||
{
|
||||
return CompareTo((IEntity)other);
|
||||
}
|
||||
|
||||
public int CompareTo(IEntity other)
|
||||
{
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
return Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other == null || other is IEntity)
|
||||
return CompareTo((IEntity)other);
|
||||
|
||||
throw new ArgumentException();
|
||||
return other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -754,7 +754,7 @@ namespace Server.Items
|
|||
from.SendLocalizedMessage(500446); // That is too far away.
|
||||
}
|
||||
|
||||
private class GroupComparer : IComparer
|
||||
private class GroupComparer : IComparer<Item>
|
||||
{
|
||||
private CheckItemGroup m_Grouper;
|
||||
|
||||
|
|
@ -763,11 +763,8 @@ namespace Server.Items
|
|||
m_Grouper = grouper;
|
||||
}
|
||||
|
||||
public int Compare(object x, object y)
|
||||
public int Compare(Item a, Item b)
|
||||
{
|
||||
Item a = (Item)x;
|
||||
Item b = (Item)y;
|
||||
|
||||
return m_Grouper(a, b);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ namespace Server
|
|||
|
||||
[Parsable]
|
||||
//[CustomEnum( new string[]{ "Felucca", "Trammel", "Ilshenar", "Malas", "Internal" } )]
|
||||
public sealed class Map : IComparable, IComparable<Map>
|
||||
public sealed class Map : IComparable<Map>
|
||||
{
|
||||
public const int SectorSize = 16;
|
||||
public const int SectorShift = 4;
|
||||
|
|
@ -391,20 +391,9 @@ namespace Server
|
|||
|
||||
public static int[] InvalidLandTiles{ get; set; } = { 0x244 };
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other == null || other is Map)
|
||||
return CompareTo(other);
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
public int CompareTo(Map other)
|
||||
{
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
return MapID.CompareTo(other.MapID);
|
||||
return other == null ? -1 : MapID.CompareTo(other.MapID);
|
||||
}
|
||||
|
||||
public static string[] GetMapNames()
|
||||
|
|
@ -428,7 +417,7 @@ namespace Server
|
|||
if (!int.TryParse(value, out int index))
|
||||
return Maps.FirstOrDefault(m => m != null && Insensitive.Equals(m.Name, value));
|
||||
|
||||
return index == 127 ? Internal : Maps.FirstOrDefault(m => m != null && m.MapIndex == index);
|
||||
return index == 127 ? Internal : Maps.FirstOrDefault(m => m?.MapIndex == index);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -967,16 +956,6 @@ namespace Server
|
|||
return p;
|
||||
}
|
||||
|
||||
private class ZComparer : IComparer<Item>
|
||||
{
|
||||
public static readonly ZComparer Default = new ZComparer();
|
||||
|
||||
public int Compare(Item x, Item y)
|
||||
{
|
||||
return x.Z.CompareTo(y.Z);
|
||||
}
|
||||
}
|
||||
|
||||
public class NullEnumerable<T> : IPooledEnumerable<T>
|
||||
{
|
||||
public static readonly NullEnumerable<T> Instance = new NullEnumerable<T>();
|
||||
|
|
|
|||
|
|
@ -7694,31 +7694,16 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
#region CompareTo(...)
|
||||
|
||||
public int CompareTo(IEntity other)
|
||||
int IComparable<IEntity>.CompareTo(IEntity other)
|
||||
{
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
return Serial.CompareTo(other.Serial);
|
||||
return other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public int CompareTo(Mobile other)
|
||||
{
|
||||
return CompareTo((IEntity)other);
|
||||
return other == null ? -1 : Serial.CompareTo(other.Serial);
|
||||
}
|
||||
|
||||
public int CompareTo(object other)
|
||||
{
|
||||
if (other == null || other is IEntity)
|
||||
return CompareTo((IEntity)other);
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Handlers
|
||||
|
||||
public static AllowBeneficialHandler AllowBeneficialHandler{ get; set; }
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ using System;
|
|||
|
||||
namespace Server
|
||||
{
|
||||
public struct Serial : IComparable, IComparable<Serial>, IComparable<uint>
|
||||
public struct Serial : IComparable<Serial>, IComparable<uint>
|
||||
{
|
||||
public static readonly Serial MinusOne = new Serial(0xFFFFFFFF);
|
||||
public static readonly Serial Zero = new Serial(0);
|
||||
|
|
@ -72,17 +72,12 @@ namespace Server
|
|||
{
|
||||
return Value.GetHashCode();
|
||||
}
|
||||
|
||||
|
||||
public int CompareTo(Serial other)
|
||||
{
|
||||
return Value.CompareTo(other.Value);
|
||||
}
|
||||
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
return Value.CompareTo(obj);
|
||||
}
|
||||
|
||||
public int CompareTo(uint other)
|
||||
{
|
||||
return Value.CompareTo(other);
|
||||
|
|
@ -148,4 +143,4 @@ namespace Server
|
|||
return new Serial(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue