comparison java/src/java/util/Arrays.d @ 10:eb8ff453285d

Added java.util collection classes.
author Frank Benoit <benoit@tionex.de>
date Fri, 13 Mar 2009 16:57:07 +0100
parents
children 9b96950f2c3c
comparison
equal deleted inserted replaced
9:950d84783eac 10:eb8ff453285d
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
8 class Arrays {
9 public static bool equals(T)(T[] a, T[] b){
10 if( a.length !is b.length ){
11 return false;
12 }
13 for( int i = 0; i < a.length; i++ ){
14 if( a[i] is null && b[i] is null ){
15 continue;
16 }
17 if( a[i] !is null && b[i] !is null && a[i] == b[i] ){
18 continue;
19 }
20 return false;
21 }
22 return true;
23 }
24 /+ public static bool equals(Object[] a, Object[] b){
25 if( a.length !is b.length ){
26 return false;
27 }
28 for( int i = 0; i < a.length; i++ ){
29 if( a[i] is null && b[i] is null ){
30 continue;
31 }
32 if( a[i] !is null && b[i] !is null && a[i] == b[i] ){
33 continue;
34 }
35 return false;
36 }
37 return true;
38 }
39 +/
40 static void sort( T )( T[] a, Comparator c ){
41 static if( is( T : char[] )){
42 bool isLess( String o1, String o2 ){
43 return c.compare( stringcast(o1), stringcast(o2) ) < 0;
44 }
45 }
46 else{
47 bool isLess( T o1, T o2 ){
48 return c.compare( cast(Object)o1, cast(Object)o2 ) < 0;
49 }
50 }
51 tango.core.Array.sort( a, &isLess );
52 }
53 static List asList(Object[] a) {
54 if( a.length is 0 ) return Collections.EMPTY_LIST;
55 ArrayList res = new ArrayList( a.length );
56 foreach( o; a ){
57 res.add(o);
58 }
59 return res;
60 }
61 public static void fill( String str, char c ){
62 str[] = c;
63 }
64 }
65