bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/30061] Comparator interface arguments get reversed


From: dwhire at yahoo dot com
Subject: [Bug classpath/30061] Comparator interface arguments get reversed
Date: 6 Dec 2006 07:34:16 -0000


------- Comment #5 from dwhire at yahoo dot com  2006-12-06 07:34 -------
I have modified my test code so that the Comparator arguments are of the same
type. Sun's JVM gives the results -3 , -6 while GNU classpath gives -3 , -8.
You will note that I have nulls at the top end of the target array. I expect
that the binary search will return an insertion point (result) that corresponds
to the first null.

Test code:

import java.util.Arrays;
import java.util.Comparator;

public class Test1 implements Comparator {
        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
       Test1 t = new Test1();
       t.doit();
        }

        void doit (){
                System.out.println("test1 vs 001");
        String [] sa = {"01","04","07","14","16",null,null} ;
                String key = "05";
                int result = Arrays.binarySearch(sa, key, (Comparator) this);
                System.out.println (result);
                key = "17";
                result = Arrays.binarySearch(sa, key, (Comparator) this);
                System.out.println (result);

        }

        public int compare(Object o1, Object o2) {
                if (o1 == null ) return 1 ; // null is greater 
                                            // in this context
                if (o2 == null ) return 1 ; // or else IKVM/GNU 
                                            // claaspath will fail
                String s1 = (String) o1 ; 
                String s2 = (String) o2 ; 
                return s1.compareTo(s2);
    }

}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30061





reply via email to

[Prev in Thread] Current Thread [Next in Thread]