[Nice-commit] Nice/stdlib/nice/lang collections.nice,1.45,1.46
Brought to you by:
bonniot
From: <bo...@us...> - 2003-03-03 16:42:51
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang In directory sc8-pr-cvs1:/tmp/cvs-serv20382/stdlib/nice/lang Modified Files: collections.nice Log Message: Sorting collections using an anonymous comparator. Index: collections.nice =================================================================== RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/collections.nice,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** collections.nice 26 Feb 2003 19:19:37 -0000 1.45 --- collections.nice 3 Mar 2003 16:42:45 -0000 1.46 *************** *** 161,164 **** --- 161,184 ---- /**************************************************************** + * Sort + ****************************************************************/ + + /** + comparator must return a negative integer, zero, or a positive integer + as the first argument is less than, equal to, or greater than the second. + */ + <T> void sort(List<T> list, (T,T) -> int comparator) + { + Collections.sort(list, new NiceComparator(comparator: comparator)); + } + + class NiceComparator<T> implements java.util.Comparator + { + final (T,T) -> int comparator; + + compare(x, y) = (this.comparator)(x,y); + } + + /**************************************************************** * Standard operations ****************************************************************/ |