OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart._collection.dev; | 5 part of dart._collection.dev; |
6 | 6 |
7 | 7 |
8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, | 8 // This is a hack to make @deprecated work in dart:io. Don't remove or use this, |
9 // unless coordinated with either me or the core library team. Thanks! | 9 // unless coordinated with either me or the core library team. Thanks! |
10 // TODO(ajohnsen): Remove at the 11th of August 2013. | 10 // TODO(ajohnsen): Remove at the 11th of August 2013. |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 | 946 |
947 static Iterable reversedList(List list) { | 947 static Iterable reversedList(List list) { |
948 return new ReversedListIterable(list); | 948 return new ReversedListIterable(list); |
949 } | 949 } |
950 | 950 |
951 static void sortList(List list, int compare(a, b)) { | 951 static void sortList(List list, int compare(a, b)) { |
952 if (compare == null) compare = Comparable.compare; | 952 if (compare == null) compare = Comparable.compare; |
953 Sort.sort(list, compare); | 953 Sort.sort(list, compare); |
954 } | 954 } |
955 | 955 |
| 956 static void shuffleList(List list) { |
| 957 Random random = new Random(); |
| 958 int length = list.length; |
| 959 while (length > 1) { |
| 960 int pos = random.nextInt(length); |
| 961 length -= 1; |
| 962 var tmp = list[length]; |
| 963 list[length] = list[pos]; |
| 964 list[pos] = tmp; |
| 965 } |
| 966 } |
| 967 |
956 static int indexOfList(List list, var element, int start) { | 968 static int indexOfList(List list, var element, int start) { |
957 return Arrays.indexOf(list, element, start, list.length); | 969 return Arrays.indexOf(list, element, start, list.length); |
958 } | 970 } |
959 | 971 |
960 static int lastIndexOfList(List list, var element, int start) { | 972 static int lastIndexOfList(List list, var element, int start) { |
961 if (start == null) start = list.length - 1; | 973 if (start == null) start = list.length - 1; |
962 return Arrays.lastIndexOf(list, element, start); | 974 return Arrays.lastIndexOf(list, element, start); |
963 } | 975 } |
964 | 976 |
965 static void _rangeCheck(List list, int start, int end) { | 977 static void _rangeCheck(List list, int start, int end) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 | 1089 |
1078 static Set setDifference(Set set, Set other, Set result) { | 1090 static Set setDifference(Set set, Set other, Set result) { |
1079 for (var element in set) { | 1091 for (var element in set) { |
1080 if (!other.contains(element)) { | 1092 if (!other.contains(element)) { |
1081 result.add(element); | 1093 result.add(element); |
1082 } | 1094 } |
1083 } | 1095 } |
1084 return result; | 1096 return result; |
1085 } | 1097 } |
1086 } | 1098 } |
OLD | NEW |