diff --git a/CS2JLibrary/NetFramework/System/Collections/Generic/IComparer'1.xml b/CS2JLibrary/NetFramework/System/Collections/Generic/IComparer'1.xml new file mode 100644 index 0000000..59a2d2d --- /dev/null +++ b/CS2JLibrary/NetFramework/System/Collections/Generic/IComparer'1.xml @@ -0,0 +1,36 @@ + + + + + java.util.Comparator + + Comparator*[${T}]* + System.Collections.Generic.IComparer + + T + + + + + + T + x + + + T + y + + + compare(${x}, ${y}) + Compare + + + + +FzD0ISaWZKb/GDgZSI4werJrHHs=NeU9k5KOXySVLGMadMEZfh5bsC928iltYWSnpm/5N0sN3NSyfZYUPZ3mL8DG8bZPzJbTIla2fkkZH0FbsDbtU1AeTYpFg9C8NSGDeYqR1mNEaCqYUZQmmP5MP9TtyT9dZOItpb4TXSWjKdkahUaw6CbFRn38Az9Wfh+8DdHIzjg= diff --git a/CS2JLibrary/NetFramework/System/Number.xml b/CS2JLibrary/NetFramework/System/Number.xml index 1729c7f..b8c47e6 100644 --- a/CS2JLibrary/NetFramework/System/Number.xml +++ b/CS2JLibrary/NetFramework/System/Number.xml @@ -1,4 +1,4 @@ - + CS2JNet.System.StringSupport @@ -38,6 +39,20 @@ Compare System.Int32 + + + CS2JNet.System.StringSupport + + StringSupport.Compare(${arg1}, ${this}) + + + System.String + arg1 + + + CompareTo + System.Int32 + CS2JNet.System.StringSupport diff --git a/CS2JLibrary/src/CS2JNet/System/StringSupport.java b/CS2JLibrary/src/CS2JNet/System/StringSupport.java index 92e8fa2..b578f18 100755 --- a/CS2JLibrary/src/CS2JNet/System/StringSupport.java +++ b/CS2JLibrary/src/CS2JNet/System/StringSupport.java @@ -80,7 +80,7 @@ public class StringSupport { public static int Compare(String s1, String s2, boolean ignoreCase) { - // Handele nulls, null is smaller than a real string + // Handle nulls, null is smaller than a real string if (s1 == null) { if (s2 == null) { return 0; diff --git a/CSharpTranslator/tests/Tester/Main.cs b/CSharpTranslator/tests/Tester/Main.cs index bffa301..7e6afdc 100644 --- a/CSharpTranslator/tests/Tester/Main.cs +++ b/CSharpTranslator/tests/Tester/Main.cs @@ -14,7 +14,8 @@ namespace Tester //Tester.Delegates.EventHandler.Sample.EHMain(); - Tester.Misc.RenameTest.RNMain("hello world"); + // Tester.Misc.RenameTest.RNMain("hello world"); + Tester.Misc.Sorter.Example.SorterMain(); } } diff --git a/CSharpTranslator/tests/Tester/Misc/Sorter.cs b/CSharpTranslator/tests/Tester/Misc/Sorter.cs new file mode 100644 index 0000000..1fff32c --- /dev/null +++ b/CSharpTranslator/tests/Tester/Misc/Sorter.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; + +namespace Tester.Misc.Sorter +{ + public class Example : IComparer + { + private static int CompareDinosByLength (string x, string y) + { + if (x == null) { + if (y == null) { + // If x is null and y is null, they're + // equal. + return 0; + } else { + // If x is null and y is not null, y + // is greater. + return -1; + } + } else { + // If x is not null... + // + // ...and y is null, x is greater. + if (y == null) { + return 1; + } else { + // ...and y is not null, compare the + // lengths of the two strings. + // + int retval = x.Length.CompareTo (y.Length); + + if (retval != 0) { + // If the strings are not of equal length, + // the longer string is greater. + // + return retval; + } else { + // If the strings are of equal length, + // sort them with ordinary string comparison. + // + return x.CompareTo (y); + } + } + } + } + + public int Compare(String x, String y) { + return CompareDinosByLength(x,y); + } + + public static void SorterMain () + { + List dinosaurs = new List (); + dinosaurs.Add ("Pachycephalosaurus"); + dinosaurs.Add ("Amargasaurus"); + dinosaurs.Add (""); + dinosaurs.Add (null); + dinosaurs.Add ("Mamenchisaurus"); + dinosaurs.Add ("Deinonychus"); + Display (dinosaurs); + + Console.WriteLine ("\nSort with generic Comparison delegate:"); + dinosaurs.Sort (new Example()); + Display (dinosaurs); + + } + + private static void Display (List list) + { + Console.WriteLine (); + foreach (string s in list) { + if (s == null) + Console.WriteLine ("(null)"); + else + Console.WriteLine ("\"{0}\"", s); + } + } + } + +} +/* This code example produces the following output: + +"Pachycephalosaurus" +"Amargasaurus" +"" +(null) +"Mamenchisaurus" +"Deinonychus" + +Sort with generic Comparison delegate: + +(null) +"" +"Deinonychus" +"Amargasaurus" +"Mamenchisaurus" +"Pachycephalosaurus" + */ diff --git a/CSharpTranslator/tests/Tester/Tester.csproj b/CSharpTranslator/tests/Tester/Tester.csproj index 83474a2..d6e651d 100644 --- a/CSharpTranslator/tests/Tester/Tester.csproj +++ b/CSharpTranslator/tests/Tester/Tester.csproj @@ -58,6 +58,7 @@ +