1 module java.util.Arrays;
2 
3 import java.lang.all;
4 import java.util.List;
5 import java.util.ArrayList;
6 import java.util.Collections;
7 version(Tango){
8     static import tango.core.Array;
9 } else { // Phobos
10 }
11 
12 class Arrays {
13     public static bool equals(T)(T[] a, T[] b){
14         if( a.length !is b.length ){
15             return false;
16         }
17         for( int i = 0; i < a.length; i++ ){
18             if( a[i] is null && b[i] is null ){
19                 continue;
20             }
21             if( a[i] !is null && b[i] !is null && a[i] == b[i] ){
22                 continue;
23             }
24             return false;
25         }
26         return true;
27     }
28 /+    public static bool equals(Object[] a, Object[] b){
29         if( a.length !is b.length ){
30             return false;
31         }
32         for( int i = 0; i < a.length; i++ ){
33             if( a[i] is null && b[i] is null ){
34                 continue;
35             }
36             if( a[i] !is null && b[i] !is null && a[i] == b[i] ){
37                 continue;
38             }
39             return false;
40         }
41         return true;
42     }
43 +/
44     static int binarySearch( T )( T[] a, T b ){
45         if( tango.core.Array.bsearch( a, b )){
46             tango.core.Array.lbound( a, b );
47         }
48         else{
49             return -(tango.core.Array.lbound( a, b ))-1;
50         }
51     }
52     static void sort( T )( T[] a ){
53         tango.core.Array.sort( a );
54     }
55     static void sort( T )( T[] a, Comparator c ){
56         static if( is( T : char[] )){
57             bool isLess( String o1, String o2 ){
58                 return c.compare( stringcast(o1), stringcast(o2) ) < 0;
59             }
60         }
61         else{
62             bool isLess( T o1, T o2 ){
63                 return c.compare( cast(Object)o1, cast(Object)o2 ) < 0;
64             }
65         }
66         tango.core.Array.sort( a, &isLess );
67     }
68     static List    asList(T)(T[] a) {
69         static if( is(T==String)){
70             if( a.length is 0 ) return Collections.EMPTY_LIST;
71             ArrayList res = new ArrayList( a.length );
72             foreach( o; a ){
73                 res.add( stringcast(o));
74             }
75             return res;
76         }
77         else{
78             static assert( is(T==interface) || is(T==class), "asList");
79             if( a.length is 0 ) return Collections.EMPTY_LIST;
80             ArrayList res = new ArrayList( a.length );
81             foreach( o; a ){
82                 res.add( cast(Object)o);
83             }
84             return res;
85         }
86     }
87     public static void fill( char[] str, char c ){
88         str[] = c;
89     }
90 }
91