| OLD | NEW |
| (Empty) | |
| 1 library java.core; |
| 2 |
| 3 import "dart:math" as math; |
| 4 |
| 5 class System { |
| 6 static int currentTimeMillis() { |
| 7 return (new Date.now()).millisecondsSinceEpoch; |
| 8 } |
| 9 } |
| 10 |
| 11 /** |
| 12 * Limited implementation of "o is instanceOfType", see |
| 13 * http://code.google.com/p/dart/issues/detail?id=8184 |
| 14 */ |
| 15 bool isInstanceOf(o, Type t) { |
| 16 if (o == null) { |
| 17 return false; |
| 18 } |
| 19 if (o.runtimeType == t) { |
| 20 return true; |
| 21 } |
| 22 String oTypeName = o.runtimeType.toString(); |
| 23 if (oTypeName == "${t.toString()}Impl") { |
| 24 return true; |
| 25 } |
| 26 return false; |
| 27 } |
| 28 |
| 29 class JavaArrays { |
| 30 static bool equals(List a, List b) { |
| 31 if (a.length != b.length) { |
| 32 return false; |
| 33 } |
| 34 var len = a.length; |
| 35 for (int i = 0; i < len; i++) { |
| 36 if (a[i] != b[i]) { |
| 37 return false; |
| 38 } |
| 39 } |
| 40 return true; |
| 41 } |
| 42 static int makeHashCode(List a) { |
| 43 if (a == null) { |
| 44 return 0; |
| 45 } |
| 46 int result = 1; |
| 47 for (var element in a) { |
| 48 result = 31 * result + (element == null ? 0 : element.hashCode()); |
| 49 } |
| 50 return result; |
| 51 } |
| 52 } |
| 53 |
| 54 class Character { |
| 55 static const int MAX_VALUE = 0xffff; |
| 56 static const int MAX_CODE_POINT = 0x10ffff; |
| 57 static bool isLetter(int c) { |
| 58 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; |
| 59 } |
| 60 static bool isLetterOrDigit(int c) { |
| 61 return isLetter(c) || c >= 0x30 && c <= 0x39; |
| 62 } |
| 63 static int digit(int codePoint, int radix) { |
| 64 if (radix != 16) { |
| 65 throw new ArgumentError("only radix == 16 is supported"); |
| 66 } |
| 67 if (0x30 <= codePoint && codePoint <= 0x39) { |
| 68 return codePoint - 0x30; |
| 69 } |
| 70 if (0x41 <= codePoint && codePoint <= 0x46) { |
| 71 return 0xA + (codePoint - 0x41); |
| 72 } |
| 73 } |
| 74 static String toChars(int codePoint) { |
| 75 throw new UnsupportedOperationException(); |
| 76 } |
| 77 } |
| 78 |
| 79 class CharBuffer { |
| 80 final String _content; |
| 81 CharBuffer(this._content); |
| 82 static CharBuffer wrap(String content) => new CharBuffer(content); |
| 83 int charAt(int index) => _content.charCodeAt(index); |
| 84 int length() => _content.length; |
| 85 String subSequence(int start, int end) => _content.substring(start, end); |
| 86 } |
| 87 |
| 88 class JavaString { |
| 89 static String format(String fmt, List args) { |
| 90 return fmt; |
| 91 } |
| 92 } |
| 93 |
| 94 /** |
| 95 * Very limited printf implementation, supports only %s and %d. |
| 96 */ |
| 97 String _printf(String fmt, List args) { |
| 98 StringBuffer sb = new StringBuffer(); |
| 99 bool markFound = false; |
| 100 int argIndex = 0; |
| 101 for (int i = 0; i < fmt.length; i++) { |
| 102 int c = fmt.charCodeAt(i); |
| 103 if (c == 0x25) { |
| 104 if (markFound) { |
| 105 sb.addCharCode(c); |
| 106 markFound = false; |
| 107 } else { |
| 108 markFound = true; |
| 109 } |
| 110 continue; |
| 111 } |
| 112 if (markFound) { |
| 113 markFound = false; |
| 114 // %d |
| 115 if (c == 0x64) { |
| 116 sb.add(args[argIndex++]); |
| 117 continue; |
| 118 } |
| 119 // %s |
| 120 if (c == 0x73) { |
| 121 sb.add(args[argIndex++]); |
| 122 continue; |
| 123 } |
| 124 // unknown |
| 125 throw new IllegalArgumentException('[$fmt][$i] = 0x${c.toRadixString(16)}'
); |
| 126 } else { |
| 127 sb.addCharCode(c); |
| 128 } |
| 129 } |
| 130 return sb.toString(); |
| 131 } |
| 132 |
| 133 abstract class PrintWriter { |
| 134 void print(x); |
| 135 |
| 136 void println() { |
| 137 this.print('\n'); |
| 138 } |
| 139 |
| 140 void printlnObject(String s) { |
| 141 this.print(s); |
| 142 this.println(); |
| 143 } |
| 144 |
| 145 void printf(String fmt, List args) { |
| 146 this.print(_printf(fmt, args)); |
| 147 } |
| 148 } |
| 149 |
| 150 class PrintStringWriter extends PrintWriter { |
| 151 final StringBuffer _sb = new StringBuffer(); |
| 152 |
| 153 void print(x) { |
| 154 _sb.add(x); |
| 155 } |
| 156 |
| 157 String toString() => _sb.toString(); |
| 158 } |
| 159 |
| 160 class StringUtils { |
| 161 static List<String> split(String s, String pattern) => s.split(pattern); |
| 162 static String replace(String s, String from, String to) => s.replaceAll(from,
to); |
| 163 static String repeat(String s, int n) { |
| 164 StringBuffer sb = new StringBuffer(); |
| 165 for (int i = 0; i < n; i++) { |
| 166 sb.add(s); |
| 167 } |
| 168 return sb.toString(); |
| 169 } |
| 170 } |
| 171 |
| 172 class Math { |
| 173 static num max(num a, num b) => math.max(a, b); |
| 174 static num min(num a, num b) => math.min(a, b); |
| 175 } |
| 176 |
| 177 class RuntimeException implements Exception { |
| 178 String toString() => "RuntimeException"; |
| 179 } |
| 180 |
| 181 class IllegalArgumentException implements Exception { |
| 182 final String message; |
| 183 const IllegalArgumentException([this.message = ""]); |
| 184 String toString() => "IllegalStateException: $message"; |
| 185 } |
| 186 |
| 187 class IllegalStateException implements Exception { |
| 188 final String message; |
| 189 const IllegalStateException([this.message = ""]); |
| 190 String toString() => "IllegalStateException: $message"; |
| 191 } |
| 192 |
| 193 class UnsupportedOperationException implements Exception { |
| 194 String toString() => "UnsupportedOperationException"; |
| 195 } |
| 196 |
| 197 class NumberFormatException implements Exception { |
| 198 String toString() => "NumberFormatException"; |
| 199 } |
| 200 |
| 201 class ListWrapper<E> extends Collection<E> implements List<E> { |
| 202 List<E> elements = new List<E>(); |
| 203 |
| 204 Iterator<E> get iterator { |
| 205 return elements.iterator; |
| 206 } |
| 207 |
| 208 E operator [](int index) { |
| 209 return elements[index]; |
| 210 } |
| 211 |
| 212 void operator []=(int index, E value) { |
| 213 elements[index] = value; |
| 214 } |
| 215 |
| 216 void set length(int newLength) { |
| 217 elements.length = newLength; |
| 218 } |
| 219 |
| 220 void add(E value) { |
| 221 elements.add(value); |
| 222 } |
| 223 |
| 224 void addLast(E value) { |
| 225 elements.addLast(value); |
| 226 } |
| 227 |
| 228 void addAll(Iterable<E> iterable) { |
| 229 elements.addAll(iterable); |
| 230 } |
| 231 |
| 232 void sort([int compare(E a, E b)]) { |
| 233 elements.sort(compare); |
| 234 } |
| 235 |
| 236 int indexOf(E element, [int start = 0]) { |
| 237 return elements.indexOf(element, start); |
| 238 } |
| 239 |
| 240 int lastIndexOf(E element, [int start]) { |
| 241 return elements.lastIndexOf(element, start); |
| 242 } |
| 243 |
| 244 void clear() { |
| 245 elements.clear(); |
| 246 } |
| 247 |
| 248 void remove(Object element) { |
| 249 return elements.remove(element); |
| 250 } |
| 251 |
| 252 E removeAt(int index) { |
| 253 return elements.removeAt(index); |
| 254 } |
| 255 |
| 256 E removeLast() { |
| 257 return elements.removeLast(); |
| 258 } |
| 259 |
| 260 List<E> get reversed => elements.reversed; |
| 261 |
| 262 List<E> getRange(int start, int length) { |
| 263 return elements.getRange(start, length); |
| 264 } |
| 265 |
| 266 void setRange(int start, int length, List<E> from, [int startFrom]) { |
| 267 elements.setRange(start, length, from, startFrom); |
| 268 } |
| 269 |
| 270 void removeRange(int start, int length) { |
| 271 elements.removeRange(start, length); |
| 272 } |
| 273 |
| 274 void insertRange(int start, int length, [E fill]) { |
| 275 elements.insertRange(start, length, fill); |
| 276 } |
| 277 } |
| 278 |
| 279 class MapEntry<K, V> { |
| 280 K _key; |
| 281 V _value; |
| 282 MapEntry(this._key, this._value); |
| 283 K getKey() => _key; |
| 284 V getValue() => _value; |
| 285 } |
| 286 |
| 287 Set<MapEntry> getMapEntrySet(Map m) { |
| 288 Set<MapEntry> result = new Set(); |
| 289 m.forEach((k, v) { |
| 290 result.add(new MapEntry(k, v)); |
| 291 }); |
| 292 return result; |
| 293 } |
| 294 |
| 295 bool javaSetAdd(Set s, o) { |
| 296 if (!s.contains(o)) { |
| 297 s.add(o); |
| 298 return true; |
| 299 } |
| 300 return false; |
| 301 } |
| OLD | NEW |