| OLD | NEW |
| 1 library java.core; | 1 library java.core; |
| 2 | 2 |
| 3 import "dart:math" as math; | 3 import "dart:math" as math; |
| 4 import "dart:io"; |
| 5 import "dart:uri"; |
| 4 | 6 |
| 5 class System { | 7 class System { |
| 8 static final String pathSeparator = Platform.pathSeparator; |
| 9 static final int pathSeparatorChar = Platform.pathSeparator.codeUnitAt(0); |
| 10 |
| 6 static int currentTimeMillis() { | 11 static int currentTimeMillis() { |
| 7 return (new Date.now()).millisecondsSinceEpoch; | 12 return (new DateTime.now()).millisecondsSinceEpoch; |
| 8 } | 13 } |
| 14 static String getProperty(String name) { |
| 15 if (name == 'os.name') { |
| 16 return Platform.operatingSystem; |
| 17 } |
| 18 if (name == 'line.separator') { |
| 19 if (Platform.operatingSystem == 'windows') { |
| 20 return '\r\n'; |
| 21 } |
| 22 return '\n'; |
| 23 } |
| 24 return null; |
| 25 } |
| 26 static String getenv(String name) => Platform.environment[name]; |
| 27 |
| 9 } | 28 } |
| 10 | 29 |
| 11 /** | 30 /** |
| 12 * Limited implementation of "o is instanceOfType", see | 31 * Limited implementation of "o is instanceOfType", see |
| 13 * http://code.google.com/p/dart/issues/detail?id=8184 | 32 * http://code.google.com/p/dart/issues/detail?id=8184 |
| 14 */ | 33 */ |
| 15 bool isInstanceOf(o, Type t) { | 34 bool isInstanceOf(o, Type t) { |
| 16 if (o == null) { | 35 if (o == null) { |
| 17 return false; | 36 return false; |
| 18 } | 37 } |
| 19 if (o.runtimeType == t) { | 38 if (o.runtimeType == t) { |
| 20 return true; | 39 return true; |
| 21 } | 40 } |
| 22 String oTypeName = o.runtimeType.toString(); | 41 String oTypeName = o.runtimeType.toString(); |
| 23 if (oTypeName == "${t.toString()}Impl") { | 42 String tTypeName = t.toString(); |
| 43 if (oTypeName == tTypeName) { |
| 44 return true; |
| 45 } |
| 46 if (oTypeName == "${tTypeName}Impl") { |
| 47 return true; |
| 48 } |
| 49 if (oTypeName.startsWith("_HashMap") && tTypeName == "Map") { |
| 50 return true; |
| 51 } |
| 52 if (oTypeName.startsWith("List") && tTypeName == "List") { |
| 24 return true; | 53 return true; |
| 25 } | 54 } |
| 26 return false; | 55 return false; |
| 27 } | 56 } |
| 28 | 57 |
| 29 class JavaArrays { | 58 class JavaArrays { |
| 30 static bool equals(List a, List b) { | 59 static bool equals(List a, List b) { |
| 31 if (a.length != b.length) { | 60 if (a.length != b.length) { |
| 32 return false; | 61 return false; |
| 33 } | 62 } |
| 34 var len = a.length; | 63 var len = a.length; |
| 35 for (int i = 0; i < len; i++) { | 64 for (int i = 0; i < len; i++) { |
| 36 if (a[i] != b[i]) { | 65 if (a[i] != b[i]) { |
| 37 return false; | 66 return false; |
| 38 } | 67 } |
| 39 } | 68 } |
| 40 return true; | 69 return true; |
| 41 } | 70 } |
| 42 static int makeHashCode(List a) { | 71 static int makeHashCode(List a) { |
| 43 if (a == null) { | 72 if (a == null) { |
| 44 return 0; | 73 return 0; |
| 45 } | 74 } |
| 46 int result = 1; | 75 int result = 1; |
| 47 for (var element in a) { | 76 for (var element in a) { |
| 48 result = 31 * result + (element == null ? 0 : element.hashCode()); | 77 result = 31 * result + (element == null ? 0 : element.hashCode); |
| 49 } | 78 } |
| 50 return result; | 79 return result; |
| 51 } | 80 } |
| 81 static List asList(List list) => list; |
| 52 } | 82 } |
| 53 | 83 |
| 54 class Character { | 84 class Character { |
| 55 static const int MAX_VALUE = 0xffff; | 85 static const int MAX_VALUE = 0xffff; |
| 56 static const int MAX_CODE_POINT = 0x10ffff; | 86 static const int MAX_CODE_POINT = 0x10ffff; |
| 57 static bool isLetter(int c) { | 87 static bool isLetter(int c) { |
| 58 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; | 88 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; |
| 59 } | 89 } |
| 60 static bool isLetterOrDigit(int c) { | 90 static bool isLetterOrDigit(int c) { |
| 61 return isLetter(c) || c >= 0x30 && c <= 0x39; | 91 return isLetter(c) || c >= 0x30 && c <= 0x39; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 73 } | 103 } |
| 74 static String toChars(int codePoint) { | 104 static String toChars(int codePoint) { |
| 75 throw new UnsupportedOperationException(); | 105 throw new UnsupportedOperationException(); |
| 76 } | 106 } |
| 77 } | 107 } |
| 78 | 108 |
| 79 class CharBuffer { | 109 class CharBuffer { |
| 80 final String _content; | 110 final String _content; |
| 81 CharBuffer(this._content); | 111 CharBuffer(this._content); |
| 82 static CharBuffer wrap(String content) => new CharBuffer(content); | 112 static CharBuffer wrap(String content) => new CharBuffer(content); |
| 83 int charAt(int index) => _content.charCodeAt(index); | 113 int charAt(int index) => _content.codeUnitAt(index); |
| 84 int length() => _content.length; | 114 int length() => _content.length; |
| 85 String subSequence(int start, int end) => _content.substring(start, end); | 115 String subSequence(int start, int end) => _content.substring(start, end); |
| 86 } | 116 } |
| 87 | 117 |
| 88 class JavaString { | 118 class JavaString { |
| 89 static String format(String fmt, List args) { | 119 static String format(String fmt, List args) { |
| 90 return fmt; | 120 return fmt; |
| 91 } | 121 } |
| 92 } | 122 } |
| 93 | 123 |
| 94 /** | 124 /** |
| 95 * Very limited printf implementation, supports only %s and %d. | 125 * Very limited printf implementation, supports only %s and %d. |
| 96 */ | 126 */ |
| 97 String _printf(String fmt, List args) { | 127 String _printf(String fmt, List args) { |
| 98 StringBuffer sb = new StringBuffer(); | 128 StringBuffer sb = new StringBuffer(); |
| 99 bool markFound = false; | 129 bool markFound = false; |
| 100 int argIndex = 0; | 130 int argIndex = 0; |
| 101 for (int i = 0; i < fmt.length; i++) { | 131 for (int i = 0; i < fmt.length; i++) { |
| 102 int c = fmt.charCodeAt(i); | 132 int c = fmt.codeUnitAt(i); |
| 103 if (c == 0x25) { | 133 if (c == 0x25) { |
| 104 if (markFound) { | 134 if (markFound) { |
| 105 sb.addCharCode(c); | 135 sb.addCharCode(c); |
| 106 markFound = false; | 136 markFound = false; |
| 107 } else { | 137 } else { |
| 108 markFound = true; | 138 markFound = true; |
| 109 } | 139 } |
| 110 continue; | 140 continue; |
| 111 } | 141 } |
| 112 if (markFound) { | 142 if (markFound) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 201 |
| 172 class Math { | 202 class Math { |
| 173 static num max(num a, num b) => math.max(a, b); | 203 static num max(num a, num b) => math.max(a, b); |
| 174 static num min(num a, num b) => math.min(a, b); | 204 static num min(num a, num b) => math.min(a, b); |
| 175 } | 205 } |
| 176 | 206 |
| 177 class RuntimeException implements Exception { | 207 class RuntimeException implements Exception { |
| 178 String toString() => "RuntimeException"; | 208 String toString() => "RuntimeException"; |
| 179 } | 209 } |
| 180 | 210 |
| 211 class JavaException implements Exception { |
| 212 final String message; |
| 213 final Exception e; |
| 214 JavaException([this.message = "", this.e = null]); |
| 215 JavaException.withCause(this.e) : message = null; |
| 216 String toString() => "JavaException: $message $e"; |
| 217 } |
| 218 |
| 181 class IllegalArgumentException implements Exception { | 219 class IllegalArgumentException implements Exception { |
| 182 final String message; | 220 final String message; |
| 183 const IllegalArgumentException([this.message = ""]); | 221 const IllegalArgumentException([this.message = "", Exception e = null]); |
| 184 String toString() => "IllegalStateException: $message"; | 222 String toString() => "IllegalStateException: $message"; |
| 185 } | 223 } |
| 186 | 224 |
| 187 class IllegalStateException implements Exception { | 225 class IllegalStateException implements Exception { |
| 188 final String message; | 226 final String message; |
| 189 const IllegalStateException([this.message = ""]); | 227 const IllegalStateException([this.message = ""]); |
| 190 String toString() => "IllegalStateException: $message"; | 228 String toString() => "IllegalStateException: $message"; |
| 191 } | 229 } |
| 192 | 230 |
| 193 class UnsupportedOperationException implements Exception { | 231 class UnsupportedOperationException implements Exception { |
| 194 String toString() => "UnsupportedOperationException"; | 232 String toString() => "UnsupportedOperationException"; |
| 195 } | 233 } |
| 196 | 234 |
| 197 class NumberFormatException implements Exception { | 235 class NumberFormatException implements Exception { |
| 198 String toString() => "NumberFormatException"; | 236 String toString() => "NumberFormatException"; |
| 199 } | 237 } |
| 200 | 238 |
| 239 class URISyntaxException implements Exception { |
| 240 String toString() => "URISyntaxException"; |
| 241 } |
| 242 |
| 243 class IOException implements Exception { |
| 244 String toString() => "IOException"; |
| 245 } |
| 246 |
| 201 class ListWrapper<E> extends Collection<E> implements List<E> { | 247 class ListWrapper<E> extends Collection<E> implements List<E> { |
| 202 List<E> elements = new List<E>(); | 248 List<E> elements = new List<E>(); |
| 203 | 249 |
| 204 Iterator<E> get iterator { | 250 Iterator<E> get iterator { |
| 205 return elements.iterator; | 251 return elements.iterator; |
| 206 } | 252 } |
| 207 | 253 |
| 208 E operator [](int index) { | 254 E operator [](int index) { |
| 209 return elements[index]; | 255 return elements[index]; |
| 210 } | 256 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 315 |
| 270 void removeRange(int start, int length) { | 316 void removeRange(int start, int length) { |
| 271 elements.removeRange(start, length); | 317 elements.removeRange(start, length); |
| 272 } | 318 } |
| 273 | 319 |
| 274 void insertRange(int start, int length, [E fill]) { | 320 void insertRange(int start, int length, [E fill]) { |
| 275 elements.insertRange(start, length, fill); | 321 elements.insertRange(start, length, fill); |
| 276 } | 322 } |
| 277 } | 323 } |
| 278 | 324 |
| 325 class JavaIterator<E> { |
| 326 Collection<E> _collection; |
| 327 List<E> _elements = new List<E>(); |
| 328 int _coPos = 0; |
| 329 int _elPos = 0; |
| 330 E _current = null; |
| 331 JavaIterator(this._collection) { |
| 332 Iterator iterator = _collection.iterator; |
| 333 while (iterator.moveNext()) { |
| 334 _elements.add(iterator.current); |
| 335 } |
| 336 } |
| 337 |
| 338 bool get hasNext { |
| 339 return _elPos < _elements.length; |
| 340 } |
| 341 |
| 342 E next() { |
| 343 _current = _elements[_elPos]; |
| 344 _coPos++; |
| 345 _elPos++; |
| 346 return _current; |
| 347 } |
| 348 |
| 349 void remove() { |
| 350 if (_collection is List) { |
| 351 _coPos--; |
| 352 (_collection as List).remove(_coPos); |
| 353 } else if (_collection is Set) { |
| 354 _collection.remove(_current); |
| 355 } else { |
| 356 throw new StateError("Unsupported collection ${_collection.runtimeType}"); |
| 357 } |
| 358 } |
| 359 } |
| 360 |
| 279 class MapEntry<K, V> { | 361 class MapEntry<K, V> { |
| 280 K _key; | 362 K _key; |
| 281 V _value; | 363 V _value; |
| 282 MapEntry(this._key, this._value); | 364 MapEntry(this._key, this._value); |
| 283 K getKey() => _key; | 365 K getKey() => _key; |
| 284 V getValue() => _value; | 366 V getValue() => _value; |
| 285 } | 367 } |
| 286 | 368 |
| 287 Set<MapEntry> getMapEntrySet(Map m) { | 369 Set<MapEntry> getMapEntrySet(Map m) { |
| 288 Set<MapEntry> result = new Set(); | 370 Set<MapEntry> result = new Set(); |
| 289 m.forEach((k, v) { | 371 m.forEach((k, v) { |
| 290 result.add(new MapEntry(k, v)); | 372 result.add(new MapEntry(k, v)); |
| 291 }); | 373 }); |
| 292 return result; | 374 return result; |
| 293 } | 375 } |
| 294 | 376 |
| 295 bool javaSetAdd(Set s, o) { | 377 bool javaSetAdd(Set s, o) { |
| 296 if (!s.contains(o)) { | 378 if (!s.contains(o)) { |
| 297 s.add(o); | 379 s.add(o); |
| 298 return true; | 380 return true; |
| 299 } | 381 } |
| 300 return false; | 382 return false; |
| 301 } | 383 } |
| 384 |
| 385 void javaMapPutAll(Map target, Map source) { |
| 386 source.forEach((k, v) { |
| 387 target[k] = v; |
| 388 }); |
| 389 } |
| 390 |
| 391 File newRelativeFile(File base, String child) { |
| 392 var childPath = new Path(base.fullPathSync()).join(new Path(child)); |
| 393 return new File.fromPath(childPath); |
| 394 } |
| 395 |
| 396 File newFileFromUri(Uri uri) { |
| 397 return new File(uri.path); |
| 398 } |
| 399 |
| 400 File getAbsoluteFile(File file) { |
| 401 var path = file.fullPathSync(); |
| 402 return new File(path); |
| 403 } |
| 404 |
| 405 Uri newUriFromFile(File file) { |
| 406 return new Uri.fromComponents(path: file.fullPathSync()); |
| 407 } |
| OLD | NEW |