using System;
namespace Harlinn.Oracle.DBTool.Example.Types.Utils
{
public class CompareHelper
{
public static int Compare(bool x, bool y)
{
return x.CompareTo(y);
}
public static int Compare(bool? x, bool? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(Guid x, Guid y)
{
return x.CompareTo(y);
}
public static int Compare(DateTime x, DateTime y)
{
return x.CompareTo(y);
}
public static int Compare(DateTime? x, DateTime? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(TimeSpan x, TimeSpan y)
{
return x.CompareTo(y);
}
public static int Compare(TimeSpan? x, TimeSpan? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(short x, short y)
{
return x.CompareTo(y);
}
public static int Compare(short? x, short? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(int x, int y)
{
return x - y;
}
public static int Compare(int? x, int? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value - y.Value;
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(long x, long y)
{
return x.CompareTo(y);
}
public static int Compare(long? x, long? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(double x, double y)
{
return x.CompareTo(y);
}
public static int Compare(double? x, double? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(float x, float y)
{
return x.CompareTo(y);
}
public static int Compare(float? x, float? y)
{
if (x.HasValue)
{
if (y.HasValue)
{
return x.Value.CompareTo(y.Value);
}
return 1;
}
if (y.HasValue)
{
return -1;
}
return 0;
}
public static int Compare(string x, string y)
{
if (x != null)
{
if (y != null)
{
return x.CompareTo(y);
}
return 1;
}
if (y != null)
{
return -1;
}
return 0;
}
public static int Compare(byte[] x, byte[] y)
{
if (x == y)
{
return 0;
}
if (x != null)
{
if (y != null)
{
int result = 0;
int maxCompareLength = x.Length < y.Length ? x.Length : y.Length;
for (int i = 0; (i < maxCompareLength) && (result == 0); i++)
{
result = ((int)x[i]) - ((int)y[i]);
}
if (result == 0)
{
result = x.Length - y.Length;
}
return result;
}
return 1;
}
if (y != null)
{
return -1;
}
return 0;
}
}
}