Mercurial > projects > dwt2
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/java/src/java/util/Arrays.d Fri Mar 13 16:57:07 2009 +0100 @@ -0,0 +1,65 @@ +module java.util.Arrays; + +import java.lang.all; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +class Arrays { + public static bool equals(T)(T[] a, T[] b){ + if( a.length !is b.length ){ + return false; + } + for( int i = 0; i < a.length; i++ ){ + if( a[i] is null && b[i] is null ){ + continue; + } + if( a[i] !is null && b[i] !is null && a[i] == b[i] ){ + continue; + } + return false; + } + return true; + } +/+ public static bool equals(Object[] a, Object[] b){ + if( a.length !is b.length ){ + return false; + } + for( int i = 0; i < a.length; i++ ){ + if( a[i] is null && b[i] is null ){ + continue; + } + if( a[i] !is null && b[i] !is null && a[i] == b[i] ){ + continue; + } + return false; + } + return true; + } ++/ + static void sort( T )( T[] a, Comparator c ){ + static if( is( T : char[] )){ + bool isLess( String o1, String o2 ){ + return c.compare( stringcast(o1), stringcast(o2) ) < 0; + } + } + else{ + bool isLess( T o1, T o2 ){ + return c.compare( cast(Object)o1, cast(Object)o2 ) < 0; + } + } + tango.core.Array.sort( a, &isLess ); + } + static List asList(Object[] a) { + if( a.length is 0 ) return Collections.EMPTY_LIST; + ArrayList res = new ArrayList( a.length ); + foreach( o; a ){ + res.add(o); + } + return res; + } + public static void fill( String str, char c ){ + str[] = c; + } +} +