| 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 import "dart:uri"; |
| 6 | 5 |
| 7 class System { | 6 class JavaSystem { |
| 8 static final String pathSeparator = Platform.pathSeparator; | |
| 9 static final int pathSeparatorChar = Platform.pathSeparator.codeUnitAt(0); | |
| 10 | |
| 11 static int currentTimeMillis() { | 7 static int currentTimeMillis() { |
| 12 return (new DateTime.now()).millisecondsSinceEpoch; | 8 return (new DateTime.now()).millisecondsSinceEpoch; |
| 13 } | 9 } |
| 14 static String getProperty(String name) { | 10 |
| 15 if (name == 'os.name') { | 11 static void arraycopy(List src, int srcPos, List dest, int destPos, int length
) { |
| 16 return Platform.operatingSystem; | 12 for (int i = 0; i < length; i++) { |
| 13 dest[destPos + i] = src[srcPos + i]; |
| 17 } | 14 } |
| 18 if (name == 'line.separator') { | |
| 19 if (Platform.operatingSystem == 'windows') { | |
| 20 return '\r\n'; | |
| 21 } | |
| 22 return '\n'; | |
| 23 } | |
| 24 return null; | |
| 25 } | 15 } |
| 26 static String getenv(String name) => Platform.environment[name]; | |
| 27 | |
| 28 } | 16 } |
| 29 | 17 |
| 30 /** | 18 /** |
| 31 * Limited implementation of "o is instanceOfType", see | 19 * Limited implementation of "o is instanceOfType", see |
| 32 * http://code.google.com/p/dart/issues/detail?id=8184 | 20 * http://code.google.com/p/dart/issues/detail?id=8184 |
| 33 */ | 21 */ |
| 34 bool isInstanceOf(o, Type t) { | 22 bool isInstanceOf(o, Type t) { |
| 35 if (o == null) { | 23 if (o == null) { |
| 36 return false; | 24 return false; |
| 37 } | 25 } |
| 38 if (o.runtimeType == t) { | 26 if (o.runtimeType == t) { |
| 39 return true; | 27 return true; |
| 40 } | 28 } |
| 41 String oTypeName = o.runtimeType.toString(); | 29 String oTypeName = o.runtimeType.toString(); |
| 42 String tTypeName = t.toString(); | 30 String tTypeName = t.toString(); |
| 43 if (oTypeName == tTypeName) { | 31 if (oTypeName == tTypeName) { |
| 44 return true; | 32 return true; |
| 45 } | 33 } |
| 46 if (oTypeName == "${tTypeName}Impl") { | 34 if (oTypeName == "${tTypeName}Impl") { |
| 47 return true; | 35 return true; |
| 48 } | 36 } |
| 49 if (oTypeName.startsWith("_HashMap") && tTypeName == "Map") { | 37 if (oTypeName.startsWith("HashMap") && tTypeName == "Map") { |
| 50 return true; | 38 return true; |
| 51 } | 39 } |
| 52 if (oTypeName.startsWith("List") && tTypeName == "List") { | 40 if (oTypeName.startsWith("List") && tTypeName == "List") { |
| 53 return true; | 41 return true; |
| 54 } | 42 } |
| 55 return false; | 43 return false; |
| 56 } | 44 } |
| 57 | 45 |
| 58 class JavaArrays { | 46 class JavaArrays { |
| 59 static bool equals(List a, List b) { | 47 static bool equals(List a, List b) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 | 71 |
| 84 class Character { | 72 class Character { |
| 85 static const int MAX_VALUE = 0xffff; | 73 static const int MAX_VALUE = 0xffff; |
| 86 static const int MAX_CODE_POINT = 0x10ffff; | 74 static const int MAX_CODE_POINT = 0x10ffff; |
| 87 static bool isLetter(int c) { | 75 static bool isLetter(int c) { |
| 88 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; | 76 return c >= 0x41 && c <= 0x5A || c >= 0x61 && c <= 0x7A; |
| 89 } | 77 } |
| 90 static bool isLetterOrDigit(int c) { | 78 static bool isLetterOrDigit(int c) { |
| 91 return isLetter(c) || c >= 0x30 && c <= 0x39; | 79 return isLetter(c) || c >= 0x30 && c <= 0x39; |
| 92 } | 80 } |
| 81 static bool isWhitespace(int c) { |
| 82 return c == 0x09 || c == 0x20 || c == 0x0A || c == 0x0D; |
| 83 } |
| 93 static int digit(int codePoint, int radix) { | 84 static int digit(int codePoint, int radix) { |
| 94 if (radix != 16) { | 85 if (radix != 16) { |
| 95 throw new ArgumentError("only radix == 16 is supported"); | 86 throw new ArgumentError("only radix == 16 is supported"); |
| 96 } | 87 } |
| 97 if (0x30 <= codePoint && codePoint <= 0x39) { | 88 if (0x30 <= codePoint && codePoint <= 0x39) { |
| 98 return codePoint - 0x30; | 89 return codePoint - 0x30; |
| 99 } | 90 } |
| 100 if (0x41 <= codePoint && codePoint <= 0x46) { | 91 if (0x41 <= codePoint && codePoint <= 0x46) { |
| 101 return 0xA + (codePoint - 0x41); | 92 return 0xA + (codePoint - 0x41); |
| 102 } | 93 } |
| 94 if (0x61 <= codePoint && codePoint <= 0x66) { |
| 95 return 0xA + (codePoint - 0x61); |
| 96 } |
| 97 return -1; |
| 103 } | 98 } |
| 104 static String toChars(int codePoint) { | 99 static String toChars(int codePoint) { |
| 105 throw new UnsupportedOperationException(); | 100 throw new UnsupportedOperationException(); |
| 106 } | 101 } |
| 107 } | 102 } |
| 108 | 103 |
| 109 class CharBuffer { | 104 class CharBuffer { |
| 110 final String _content; | 105 final String _content; |
| 111 CharBuffer(this._content); | 106 CharBuffer(this._content); |
| 112 static CharBuffer wrap(String content) => new CharBuffer(content); | 107 static CharBuffer wrap(String content) => new CharBuffer(content); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 * Very limited printf implementation, supports only %s and %d. | 120 * Very limited printf implementation, supports only %s and %d. |
| 126 */ | 121 */ |
| 127 String _printf(String fmt, List args) { | 122 String _printf(String fmt, List args) { |
| 128 StringBuffer sb = new StringBuffer(); | 123 StringBuffer sb = new StringBuffer(); |
| 129 bool markFound = false; | 124 bool markFound = false; |
| 130 int argIndex = 0; | 125 int argIndex = 0; |
| 131 for (int i = 0; i < fmt.length; i++) { | 126 for (int i = 0; i < fmt.length; i++) { |
| 132 int c = fmt.codeUnitAt(i); | 127 int c = fmt.codeUnitAt(i); |
| 133 if (c == 0x25) { | 128 if (c == 0x25) { |
| 134 if (markFound) { | 129 if (markFound) { |
| 135 sb.addCharCode(c); | 130 sb.writeCharCode(c); |
| 136 markFound = false; | 131 markFound = false; |
| 137 } else { | 132 } else { |
| 138 markFound = true; | 133 markFound = true; |
| 139 } | 134 } |
| 140 continue; | 135 continue; |
| 141 } | 136 } |
| 142 if (markFound) { | 137 if (markFound) { |
| 143 markFound = false; | 138 markFound = false; |
| 144 // %d | 139 // %d |
| 145 if (c == 0x64) { | 140 if (c == 0x64) { |
| 146 sb.add(args[argIndex++]); | 141 sb.writeCharCode(args[argIndex++]); |
| 147 continue; | 142 continue; |
| 148 } | 143 } |
| 149 // %s | 144 // %s |
| 150 if (c == 0x73) { | 145 if (c == 0x73) { |
| 151 sb.add(args[argIndex++]); | 146 sb.writeCharCode(args[argIndex++]); |
| 152 continue; | 147 continue; |
| 153 } | 148 } |
| 154 // unknown | 149 // unknown |
| 155 throw new IllegalArgumentException('[$fmt][$i] = 0x${c.toRadixString(16)}'
); | 150 throw new IllegalArgumentException('[$fmt][$i] = 0x${c.toRadixString(16)}'
); |
| 156 } else { | 151 } else { |
| 157 sb.addCharCode(c); | 152 sb.writeCharCode(c); |
| 158 } | 153 } |
| 159 } | 154 } |
| 160 return sb.toString(); | 155 return sb.toString(); |
| 161 } | 156 } |
| 162 | 157 |
| 163 abstract class PrintWriter { | 158 abstract class PrintWriter { |
| 164 void print(x); | 159 void print(x); |
| 165 | 160 |
| 166 void println() { | 161 void println() { |
| 167 this.print('\n'); | 162 this.print('\n'); |
| 168 } | 163 } |
| 169 | 164 |
| 170 void printlnObject(String s) { | 165 void printlnObject(String s) { |
| 171 this.print(s); | 166 this.print(s); |
| 172 this.println(); | 167 this.println(); |
| 173 } | 168 } |
| 174 | 169 |
| 175 void printf(String fmt, List args) { | 170 void printf(String fmt, List args) { |
| 176 this.print(_printf(fmt, args)); | 171 this.print(_printf(fmt, args)); |
| 177 } | 172 } |
| 178 } | 173 } |
| 179 | 174 |
| 180 class PrintStringWriter extends PrintWriter { | 175 class PrintStringWriter extends PrintWriter { |
| 181 final StringBuffer _sb = new StringBuffer(); | 176 final StringBuffer _sb = new StringBuffer(); |
| 182 | 177 |
| 183 void print(x) { | 178 void print(x) { |
| 184 _sb.add(x); | 179 _sb.write(x); |
| 185 } | 180 } |
| 186 | 181 |
| 187 String toString() => _sb.toString(); | 182 String toString() => _sb.toString(); |
| 188 } | 183 } |
| 189 | 184 |
| 190 class StringUtils { | 185 class StringUtils { |
| 191 static List<String> split(String s, String pattern) => s.split(pattern); | 186 static List<String> split(String s, String pattern) => s.split(pattern); |
| 192 static String replace(String s, String from, String to) => s.replaceAll(from,
to); | 187 static String replace(String s, String from, String to) => s.replaceAll(from,
to); |
| 193 static String repeat(String s, int n) { | 188 static String repeat(String s, int n) { |
| 194 StringBuffer sb = new StringBuffer(); | 189 StringBuffer sb = new StringBuffer(); |
| 195 for (int i = 0; i < n; i++) { | 190 for (int i = 0; i < n; i++) { |
| 196 sb.add(s); | 191 sb.write(s); |
| 197 } | 192 } |
| 198 return sb.toString(); | 193 return sb.toString(); |
| 199 } | 194 } |
| 200 } | 195 } |
| 201 | 196 |
| 202 class Math { | 197 class Math { |
| 203 static num max(num a, num b) => math.max(a, b); | 198 static num max(num a, num b) => math.max(a, b); |
| 204 static num min(num a, num b) => math.min(a, b); | 199 static num min(num a, num b) => math.min(a, b); |
| 205 } | 200 } |
| 206 | 201 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 256 |
| 262 void set length(int newLength) { | 257 void set length(int newLength) { |
| 263 elements.length = newLength; | 258 elements.length = newLength; |
| 264 } | 259 } |
| 265 | 260 |
| 266 void add(E value) { | 261 void add(E value) { |
| 267 elements.add(value); | 262 elements.add(value); |
| 268 } | 263 } |
| 269 | 264 |
| 270 void addLast(E value) { | 265 void addLast(E value) { |
| 271 elements.addLast(value); | 266 elements.add(value); |
| 272 } | 267 } |
| 273 | 268 |
| 274 void addAll(Iterable<E> iterable) { | 269 void addAll(Iterable<E> iterable) { |
| 275 elements.addAll(iterable); | 270 elements.addAll(iterable); |
| 276 } | 271 } |
| 277 | 272 |
| 278 void sort([int compare(E a, E b)]) { | 273 void sort([int compare(E a, E b)]) { |
| 279 elements.sort(compare); | 274 elements.sort(compare); |
| 280 } | 275 } |
| 281 | 276 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 elements.setRange(start, length, from, startFrom); | 308 elements.setRange(start, length, from, startFrom); |
| 314 } | 309 } |
| 315 | 310 |
| 316 void removeRange(int start, int length) { | 311 void removeRange(int start, int length) { |
| 317 elements.removeRange(start, length); | 312 elements.removeRange(start, length); |
| 318 } | 313 } |
| 319 | 314 |
| 320 void insertRange(int start, int length, [E fill]) { | 315 void insertRange(int start, int length, [E fill]) { |
| 321 elements.insertRange(start, length, fill); | 316 elements.insertRange(start, length, fill); |
| 322 } | 317 } |
| 318 |
| 319 Map<int, E> asMap() { |
| 320 return elements.asMap(); |
| 321 } |
| 323 } | 322 } |
| 324 | 323 |
| 325 class JavaIterator<E> { | 324 class JavaIterator<E> { |
| 326 Collection<E> _collection; | 325 Collection<E> _collection; |
| 327 List<E> _elements = new List<E>(); | 326 List<E> _elements = new List<E>(); |
| 328 int _coPos = 0; | 327 int _coPos = 0; |
| 329 int _elPos = 0; | 328 int _elPos = 0; |
| 330 E _current = null; | 329 E _current = null; |
| 331 JavaIterator(this._collection) { | 330 JavaIterator(this._collection) { |
| 332 Iterator iterator = _collection.iterator; | 331 Iterator iterator = _collection.iterator; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 380 } |
| 382 return false; | 381 return false; |
| 383 } | 382 } |
| 384 | 383 |
| 385 void javaMapPutAll(Map target, Map source) { | 384 void javaMapPutAll(Map target, Map source) { |
| 386 source.forEach((k, v) { | 385 source.forEach((k, v) { |
| 387 target[k] = v; | 386 target[k] = v; |
| 388 }); | 387 }); |
| 389 } | 388 } |
| 390 | 389 |
| 391 File newRelativeFile(File base, String child) { | 390 bool javaStringEqualsIgnoreCase(String a, String b) { |
| 392 var childPath = new Path(base.fullPathSync()).join(new Path(child)); | 391 return a.toLowerCase() == b.toLowerCase(); |
| 393 return new File.fromPath(childPath); | |
| 394 } | 392 } |
| 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 |