diff --git a/mcs/class/corlib/System/Tuples.cs b/mcs/class/corlib/System/Tuples.cs index e5e8f6ec2199d..96e7d638715bc 100644 --- a/mcs/class/corlib/System/Tuples.cs +++ b/mcs/class/corlib/System/Tuples.cs @@ -82,9 +82,15 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + return comparer.Compare (item1, t.item1); } public override bool Equals (object obj) @@ -144,9 +150,17 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + return comparer.Compare (item2, t.item2); } public override bool Equals (object obj) @@ -215,9 +229,19 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + return comparer.Compare (item3, t.item3); } public override bool Equals (object obj) @@ -294,9 +318,21 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + res = comparer.Compare (item3, t.item3); + if (res != 0) return res; + return comparer.Compare (item4, t.item4); } public override bool Equals (object obj) @@ -381,9 +417,23 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + res = comparer.Compare (item3, t.item3); + if (res != 0) return res; + res = comparer.Compare (item4, t.item4); + if (res != 0) return res; + return comparer.Compare (item5, t.item5); } public override bool Equals (object obj) @@ -476,9 +526,25 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + res = comparer.Compare (item3, t.item3); + if (res != 0) return res; + res = comparer.Compare (item4, t.item4); + if (res != 0) return res; + res = comparer.Compare (item5, t.item5); + if (res != 0) return res; + return comparer.Compare (item6, t.item6); } public override bool Equals (object obj) @@ -579,9 +645,27 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + res = comparer.Compare (item3, t.item3); + if (res != 0) return res; + res = comparer.Compare (item4, t.item4); + if (res != 0) return res; + res = comparer.Compare (item5, t.item5); + if (res != 0) return res; + res = comparer.Compare (item6, t.item6); + if (res != 0) return res; + return comparer.Compare (item7, t.item7); } public override bool Equals (object obj) @@ -678,9 +762,29 @@ int IComparable.CompareTo (object obj) return ((IStructuralComparable) this).CompareTo (obj, Comparer.Default); } - [MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer) + int IStructuralComparable.CompareTo (object other, IComparer comparer) { - throw new NotImplementedException (); + var t = other as Tuple; + if (t == null) { + if (other == null) return 1; + throw new ArgumentException (); + } + + int res = comparer.Compare (item1, t.item1); + if (res != 0) return res; + res = comparer.Compare (item2, t.item2); + if (res != 0) return res; + res = comparer.Compare (item3, t.item3); + if (res != 0) return res; + res = comparer.Compare (item4, t.item4); + if (res != 0) return res; + res = comparer.Compare (item5, t.item5); + if (res != 0) return res; + res = comparer.Compare (item6, t.item6); + if (res != 0) return res; + res = comparer.Compare (item7, t.item7); + if (res != 0) return res; + return comparer.Compare (rest, t.rest); } public override bool Equals (object obj) @@ -788,10 +892,25 @@ public class TupleGen Console.WriteLine ("\t\t}"); Console.WriteLine (); - Console.WriteLine ("\t\t[MonoTODO] int IStructuralComparable.CompareTo (object other, IComparer comparer)"); + Console.WriteLine ("\t\tint IStructuralComparable.CompareTo (object other, IComparer comparer)"); Console.WriteLine ("\t\t{"); - Console.WriteLine ("\t\t\tthrow new NotImplementedException ();"); - Console.WriteLine ("\t\t}"); + Console.WriteLine ("\t\t\tvar t = other as {0};", type_name); + Console.WriteLine ("\t\t\tif (t == null) {"); + Console.WriteLine ("\t\t\t\tif (other == null) return 1;"); + Console.WriteLine ("\t\t\t\tthrow new ArgumentException ();"); + Console.WriteLine ("\t\t\t}"); + Console.WriteLine (); + + for (int i = 1; i < arity; ++i) { + Console.Write ("\t\t\t"); + if (i == 1) + Console.Write ("int "); + + Console.WriteLine ("res = comparer.Compare ({0}, t.{0});", GetItemName (i)); + Console.WriteLine ("\t\t\tif (res != 0) return res;"); + } + Console.WriteLine ("\t\t\treturn comparer.Compare ({0}, t.{0});", GetItemName (arity)); + Console.WriteLine ("\t\t}"); Console.WriteLine (); Console.WriteLine ("\t\tpublic override bool Equals (object obj)"); @@ -827,7 +946,7 @@ public class TupleGen Console.WriteLine (); Console.WriteLine ("\t\tpublic override int GetHashCode ()"); Console.WriteLine ("\t\t{"); - Console.WriteLine ("\t\t\treturn GetHashCode (EqualityComparer.Default);"); + Console.WriteLine ("\t\t\treturn ((IStructuralEquatable) this).GetHashCode (EqualityComparer.Default);"); Console.WriteLine ("\t\t}"); Console.WriteLine ();